UNPKG

react-async-alert-confirm

Version:

A reusable React component library for alert dialog and confirm dialog

32 lines (29 loc) 18.8 kB
(function(){"use strict";try{if(typeof document<"u"){var a=document.createElement("style");a.appendChild(document.createTextNode("._modal-overlay_pac0m_1{position:fixed;width:100vw;height:100vh;background-color:#00000080;display:flex;align-items:center;justify-content:center;inset:0;z-index:20;opacity:0}._modal-container_pac0m_14{padding:12px 64px;background-color:#fff;box-shadow:2px 2px 30px 10px #ffffff1a;border-radius:8px;display:flex;flex-direction:column;align-items:center;justify-content:center;max-width:600px;box-sizing:border-box}@media (max-width: 768px){._modal-container_pac0m_14{width:calc(100% - 32px);max-width:calc(100% - 32px);padding:24px}}._modal-title_pac0m_36{display:flex;font-size:16px;color:#000;font-weight:700;align-items:center;justify-content:center}._modal-content_pac0m_45{font-size:16px;margin-top:20px;color:#000;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center}._modal-actions_pac0m_56{width:100%;display:flex;justify-content:space-around;margin-top:24px;gap:16px}@media (max-width: 768px){._modal-actions_pac0m_56{gap:8px}}._modal-button_pac0m_69{padding:8px 24px;cursor:pointer;display:flex;align-items:center;justify-content:center;width:136px;margin-top:20px;border-radius:8px;font-size:14px;color:#fff;background-color:#000}._modal-button-cancel_pac0m_82{background-color:#0000004d}@keyframes _board_show_pac0m_1{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}@keyframes _overlay_show_pac0m_1{0%{opacity:0}to{opacity:1}}@keyframes _board_hide_pac0m_1{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.5)}}@keyframes _overlay_hide_pac0m_1{0%{opacity:1}to{opacity:0}}._overlay-show_pac0m_134{animation:_overlay_show_pac0m_1 .3s forwards}._overlay-hide_pac0m_137{animation:_overlay_hide_pac0m_1 .3s forwards}._container-show_pac0m_140{animation:_board_show_pac0m_1 .3s forwards}._container-hide_pac0m_143{animation:_board_hide_pac0m_1 .3s forwards}")),document.head.appendChild(a)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})(); (function(x,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("react"),require("react-dom/client")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client"],S):(x=typeof globalThis<"u"?globalThis:x||self,S(x.ReactAsyncAlertConfrim={},x.React,x.ReactDOMClient))})(this,function(x,S,re){"use strict";var L={exports:{}},N={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var te;function ke(){if(te)return N;te=1;var E=S,R=Symbol.for("react.element"),C=Symbol.for("react.fragment"),y=Object.prototype.hasOwnProperty,b=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,T={key:!0,ref:!0,__self:!0,__source:!0};function m(d,u,O){var p,w={},P=null,V=null;O!==void 0&&(P=""+O),u.key!==void 0&&(P=""+u.key),u.ref!==void 0&&(V=u.ref);for(p in u)y.call(u,p)&&!T.hasOwnProperty(p)&&(w[p]=u[p]);if(d&&d.defaultProps)for(p in u=d.defaultProps,u)w[p]===void 0&&(w[p]=u[p]);return{$$typeof:R,type:d,key:P,ref:V,props:w,_owner:b.current}}return N.Fragment=C,N.jsx=m,N.jsxs=m,N}var Y={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ne;function De(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var E=S,R=Symbol.for("react.element"),C=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),T=Symbol.for("react.profiler"),m=Symbol.for("react.provider"),d=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),O=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),V=Symbol.for("react.offscreen"),oe=Symbol.iterator,Ye="@@iterator";function We(e){if(e===null||typeof e!="object")return null;var r=oe&&e[oe]||e[Ye];return typeof r=="function"?r:null}var F=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function _(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Me("error",e,t)}}function Me(e,r,t){{var n=F.ReactDebugCurrentFrame,i=n.getStackAddendum();i!==""&&(r+="%s",t=t.concat([i]));var c=t.map(function(o){return String(o)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var Le=!1,Ve=!1,Ue=!1,Be=!1,Je=!1,ie;ie=Symbol.for("react.module.reference");function Ke(e){return!!(typeof e=="string"||typeof e=="function"||e===y||e===T||Je||e===b||e===O||e===p||Be||e===V||Le||Ve||Ue||typeof e=="object"&&e!==null&&(e.$$typeof===P||e.$$typeof===w||e.$$typeof===m||e.$$typeof===d||e.$$typeof===u||e.$$typeof===ie||e.getModuleId!==void 0))}function qe(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function ce(e){return e.displayName||"Context"}function k(e){if(e==null)return null;if(typeof e.tag=="number"&&_("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case y:return"Fragment";case C:return"Portal";case T:return"Profiler";case b:return"StrictMode";case O:return"Suspense";case p:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case d:var r=e;return ce(r)+".Consumer";case m:var t=e;return ce(t._context)+".Provider";case u:return qe(e,e.render,"ForwardRef");case w:var n=e.displayName||null;return n!==null?n:k(e.type)||"Memo";case P:{var i=e,c=i._payload,o=i._init;try{return k(o(c))}catch{return null}}}return null}var D=Object.assign,W=0,se,le,ue,fe,de,ve,me;function pe(){}pe.__reactDisabledLog=!0;function Ge(){{if(W===0){se=console.log,le=console.info,ue=console.warn,fe=console.error,de=console.group,ve=console.groupCollapsed,me=console.groupEnd;var e={configurable:!0,enumerable:!0,value:pe,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}W++}}function ze(){{if(W--,W===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:se}),info:D({},e,{value:le}),warn:D({},e,{value:ue}),error:D({},e,{value:fe}),group:D({},e,{value:de}),groupCollapsed:D({},e,{value:ve}),groupEnd:D({},e,{value:me})})}W<0&&_("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var q=F.ReactCurrentDispatcher,G;function U(e,r,t){{if(G===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);G=n&&n[1]||""}return` `+G+e}}var z=!1,B;{var Xe=typeof WeakMap=="function"?WeakMap:Map;B=new Xe}function _e(e,r){if(!e||z)return"";{var t=B.get(e);if(t!==void 0)return t}var n;z=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=q.current,q.current=null,Ge();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(g){n=g}Reflect.construct(e,[],o)}else{try{o.call()}catch(g){n=g}e.call(o.prototype)}}else{try{throw Error()}catch(g){n=g}e()}}catch(g){if(g&&n&&typeof g.stack=="string"){for(var a=g.stack.split(` `),h=n.stack.split(` `),l=a.length-1,f=h.length-1;l>=1&&f>=0&&a[l]!==h[f];)f--;for(;l>=1&&f>=0;l--,f--)if(a[l]!==h[f]){if(l!==1||f!==1)do if(l--,f--,f<0||a[l]!==h[f]){var j=` `+a[l].replace(" at new "," at ");return e.displayName&&j.includes("<anonymous>")&&(j=j.replace("<anonymous>",e.displayName)),typeof e=="function"&&B.set(e,j),j}while(l>=1&&f>=0);break}}}finally{z=!1,q.current=c,ze(),Error.prepareStackTrace=i}var $=e?e.displayName||e.name:"",A=$?U($):"";return typeof e=="function"&&B.set(e,A),A}function He(e,r,t){return _e(e,!1)}function Ze(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function J(e,r,t){if(e==null)return"";if(typeof e=="function")return _e(e,Ze(e));if(typeof e=="string")return U(e);switch(e){case O:return U("Suspense");case p:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case u:return He(e.render);case w:return J(e.type,r,t);case P:{var n=e,i=n._payload,c=n._init;try{return J(c(i),r,t)}catch{}}}return""}var M=Object.prototype.hasOwnProperty,he={},ye=F.ReactDebugCurrentFrame;function K(e){if(e){var r=e._owner,t=J(e.type,e._source,r?r.type:null);ye.setExtraStackFrame(t)}else ye.setExtraStackFrame(null)}function Qe(e,r,t,n,i){{var c=Function.call.bind(M);for(var o in e)if(c(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var h=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw h.name="Invariant Violation",h}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){a=l}a&&!(a instanceof Error)&&(K(i),_("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),K(null)),a instanceof Error&&!(a.message in he)&&(he[a.message]=!0,K(i),_("Failed %s type: %s",t,a.message),K(null))}}}var er=Array.isArray;function X(e){return er(e)}function rr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function tr(e){try{return be(e),!1}catch{return!0}}function be(e){return""+e}function ge(e){if(tr(e))return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",rr(e)),be(e)}var Ee=F.ReactCurrentOwner,nr={key:!0,ref:!0,__self:!0,__source:!0},Re,Te;function ar(e){if(M.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function or(e){if(M.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function ir(e,r){typeof e.ref=="string"&&Ee.current}function cr(e,r){{var t=function(){Re||(Re=!0,_("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function sr(e,r){{var t=function(){Te||(Te=!0,_("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var lr=function(e,r,t,n,i,c,o){var a={$$typeof:R,type:e,key:r,ref:t,props:o,_owner:c};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function ur(e,r,t,n,i){{var c,o={},a=null,h=null;t!==void 0&&(ge(t),a=""+t),or(r)&&(ge(r.key),a=""+r.key),ar(r)&&(h=r.ref,ir(r,i));for(c in r)M.call(r,c)&&!nr.hasOwnProperty(c)&&(o[c]=r[c]);if(e&&e.defaultProps){var l=e.defaultProps;for(c in l)o[c]===void 0&&(o[c]=l[c])}if(a||h){var f=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&cr(o,f),h&&sr(o,f)}return lr(e,a,h,i,n,Ee.current,o)}}var H=F.ReactCurrentOwner,je=F.ReactDebugCurrentFrame;function I(e){if(e){var r=e._owner,t=J(e.type,e._source,r?r.type:null);je.setExtraStackFrame(t)}else je.setExtraStackFrame(null)}var Z;Z=!1;function Q(e){return typeof e=="object"&&e!==null&&e.$$typeof===R}function Ce(){{if(H.current){var e=k(H.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function fr(e){return""}var Oe={};function dr(e){{var r=Ce();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function we(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=dr(r);if(Oe[t])return;Oe[t]=!0;var n="";e&&e._owner&&e._owner!==H.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),I(e),_('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),I(null)}}function xe(e,r){{if(typeof e!="object")return;if(X(e))for(var t=0;t<e.length;t++){var n=e[t];Q(n)&&we(n,r)}else if(Q(e))e._store&&(e._store.validated=!0);else if(e){var i=We(e);if(typeof i=="function"&&i!==e.entries)for(var c=i.call(e),o;!(o=c.next()).done;)Q(o.value)&&we(o.value,r)}}}function vr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===u||r.$$typeof===w))t=r.propTypes;else return;if(t){var n=k(r);Qe(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!Z){Z=!0;var i=k(r);_("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&_("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function mr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){I(e),_("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),I(null);break}}e.ref!==null&&(I(e),_("Invalid attribute `ref` supplied to `React.Fragment`."),I(null))}}var Se={};function Pe(e,r,t,n,i,c){{var o=Ke(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var h=fr();h?a+=h:a+=Ce();var l;e===null?l="null":X(e)?l="array":e!==void 0&&e.$$typeof===R?(l="<"+(k(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):l=typeof e,_("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",l,a)}var f=ur(e,r,t,i,c);if(f==null)return f;if(o){var j=r.children;if(j!==void 0)if(n)if(X(j)){for(var $=0;$<j.length;$++)xe(j[$],e);Object.freeze&&Object.freeze(j)}else _("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else xe(j,e)}if(M.call(r,"key")){var A=k(e),g=Object.keys(r).filter(function(gr){return gr!=="key"}),ee=g.length>0?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}";if(!Se[A+ee]){var br=g.length>0?"{"+g.join(": ..., ")+": ...}":"{}";_(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,ee,A,br,A),Se[A+ee]=!0}}return e===y?mr(f):vr(f),f}}function pr(e,r,t){return Pe(e,r,t,!0)}function _r(e,r,t){return Pe(e,r,t,!1)}var hr=_r,yr=pr;Y.Fragment=y,Y.jsx=hr,Y.jsxs=yr}()),Y}var ae;function Ae(){return ae||(ae=1,process.env.NODE_ENV==="production"?L.exports=ke():L.exports=De()),L.exports}var v=Ae();const s={"modal-overlay":"_modal-overlay_pac0m_1","modal-container":"_modal-container_pac0m_14","modal-title":"_modal-title_pac0m_36","modal-content":"_modal-content_pac0m_45","modal-actions":"_modal-actions_pac0m_56","modal-button":"_modal-button_pac0m_69","modal-button-cancel":"_modal-button-cancel_pac0m_82","overlay-show":"_overlay-show_pac0m_134","overlay-hide":"_overlay-hide_pac0m_137","container-show":"_container-show_pac0m_140","container-hide":"_container-hide_pac0m_143"},Fe=({title:E="",content:R="",yes:C=()=>{},confirm_text:y="Okay"})=>{const[b,T]=S.useState(!1),m=()=>{T(!0)};return v.jsx("div",{className:`${s["modal-overlay"]} ${b?s["overlay-hide"]:s["overlay-show"]} react-aac-overlay`,children:v.jsxs("div",{onAnimationEnd:d=>{d.stopPropagation(),b&&C()},className:`${s["modal-container"]} ${b?s["container-hide"]:s["container-show"]} react-aac-container`,children:[!!E&&v.jsx("div",{className:`${s["modal-title"]} react-aac-title`,children:E}),v.jsx("div",{className:`${s["modal-content"]} react-aac-content`,children:R}),v.jsx("div",{className:`${s["modal-actions"]} react-aac-actions`,children:v.jsx("div",{className:`${s["modal-button"]} react-aac-btn`,onClick:m,children:y})})]})})},Ie=async({title:E="",content:R="I am an alert content",confirm_text:C="Okay",node_name:y="confirm-and-alert"})=>new Promise(b=>{const T=document.getElementById(y),m=re.createRoot(T),d=()=>{m.unmount(),b(!0)};m.render(v.jsx(Fe,{title:E,content:R,confirm_text:C,yes:d}))}),$e=({title:E="I am a confirm title",content:R="I am a confirm content",yes:C=()=>{},no:y=()=>{},confirm_text:b="Confirm",cancel_text:T="Cancel"})=>{const[m,d]=S.useState(!1),[u,O]=S.useState(""),p=()=>{d(!0),O("yes")},w=()=>{d(!0),O("no")};return v.jsx("div",{className:`${s["modal-overlay"]} ${m?s["overlay-hide"]:s["overlay-show"]} react-aac-overlay`,children:v.jsxs("div",{onAnimationEnd:P=>{P.stopPropagation(),u==="no"&&y(),u==="yes"&&C()},className:`${s["modal-container"]} ${m?s["container-hide"]:s["container-show"]} react-aac-container`,children:[!!E&&v.jsx("div",{className:`${s["modal-title"]} react-aac-title`,children:E}),v.jsx("div",{className:`${s["modal-content"]} react-aac-content`,children:R}),v.jsxs("div",{className:`${s["modal-actions"]} react-aac-actions`,children:[v.jsx("div",{className:`${s["modal-button"]} ${s["modal-button-cancel"]} react-aac-cancel-button`,onClick:w,children:T}),v.jsx("div",{className:`${s["modal-button"]} react-aac-confirm-button`,onClick:p,children:b})]})]})})},Ne=async({title:E="I am a confirm title",content:R="I am a confirm content",cancel_text:C="Cancel",confirm_text:y="Confirm",node_name:b="confirm-and-alert"})=>new Promise(T=>{const m=document.getElementById(b),d=re.createRoot(m),u=()=>{d.unmount(),T(!1)},O=()=>{d.unmount(),T(!0)};d.render(v.jsx($e,{title:E,content:R,cancel_text:C,confirm_text:y,no:u,yes:O}))});x.app_alert=Ie,x.app_confirm=Ne,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});