UNPKG

@edinelsonslima/toast-notification

Version:

- 🔗 [Apresentação do toast notification](https://edinelsonslima.github.io/lp-toast-notification/) - 🔗 [NPM](https://www.npmjs.com/package/@edinelsonslima/toast-notification)

1 lines • 17 kB
var hr=Object.defineProperty,br=(e,t,r)=>t in e?hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Ie=(e,t,r)=>(br(e,"symbol"!=typeof t?t+"":t,r),r);import $e,{isValidElement as Me,useState as We,useCallback as Le,useEffect as Ue}from"react";class yr{constructor(){Ie(this,"listeners",new Map([]))}on(e,t){var r;this.listeners.has(e)||this.listeners.set(e,[]),null==(r=this.listeners.get(e))||r.push(t)}emit(e,t){var r;this.listeners.has(e)&&(null==(r=this.listeners.get(e))||r.forEach((e=>e(t))))}removeListener(e,t){const r=this.listeners.get(e);if(!r)return;const n=r.filter((e=>e!==t));this.listeners.set(e,n)}}function G(e){return function(t){if(Me(t))return I({content:t,type:e});const{content:r,duration:n}=t;return I({content:r,duration:n,type:e})}}function Er(e){if(e)return Me(e)||"object"!=typeof e||Array.isArray(e)?e:JSON.stringify(e)}const ie=new yr;function I({duration:e,content:t,type:r}){t=Er(t),ie.emit("add-toast",{content:t,duration:e,type:r})}I.error=G("error"),I.success=G("success"),I.warn=G("warn"),I.info=G("info"),I.ghost=G("ghost");var De,se={exports:{}},Y={};function Rr(){if(De)return Y;De=1;var e=$e,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function i(e,r,i){var s,c={},u=null,l=null;for(s in void 0!==i&&(u=""+i),void 0!==r.key&&(u=""+r.key),void 0!==r.ref&&(l=r.ref),r)n.call(r,s)&&!a.hasOwnProperty(s)&&(c[s]=r[s]);if(e&&e.defaultProps)for(s in r=e.defaultProps)void 0===c[s]&&(c[s]=r[s]);return{$$typeof:t,type:e,key:u,ref:l,props:c,_owner:o.current}}return Y.Fragment=r,Y.jsx=i,Y.jsxs=i,Y}var Fe,V={};function jr(){return Fe||(Fe=1,"production"!==process.env.NODE_ENV&&function(){var e=$e,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),s=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),l=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),y=Symbol.iterator,d="@@iterator";var _=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function g(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=_.ReactDebugCurrentFrame,o=n.getStackAddendum();""!==o&&(t+="%s",r=r.concat([o]));var a=r.map((function(e){return String(e)}));a.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,a)}("error",e,r)}var v,h=!1,b=!1,j=!1,w=!1,k=!1;function O(e){return e.displayName||"Context"}function S(e){if(null==e)return null;if("number"==typeof e.tag&&g("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case n:return"Fragment";case r:return"Portal";case a:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case l:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case s:return O(e)+".Consumer";case i:return O(e._context)+".Provider";case c:return function(e,t,r){var n=e.displayName;if(n)return n;var o=t.displayName||t.name||"";return""!==o?r+"("+o+")":r}(e,e.render,"ForwardRef");case f:var t=e.displayName||null;return null!==t?t:S(e.type)||"Memo";case p:var m=e,y=m._payload,d=m._init;try{return S(d(y))}catch{return null}}return null}v=Symbol.for("react.module.reference");var R,E,$,I,P,T,x,C=Object.assign,N=0;function D(){}D.__reactDisabledLog=!0;var F,A=_.ReactCurrentDispatcher;function L(e,t,r){if(void 0===F)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);F=n&&n[1]||""}return"\n"+F+e}var U,M=!1,W="function"==typeof WeakMap?WeakMap:Map;function Y(e,t){if(!e||M)return"";var r,n=U.get(e);if(void 0!==n)return n;M=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=A.current,A.current=null,function(){if(0===N){R=console.log,E=console.info,$=console.warn,I=console.error,P=console.group,T=console.groupCollapsed,x=console.groupEnd;var e={configurable:!0,enumerable:!0,value:D,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}N++}();try{if(t){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(e){r=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){r=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){r=e}e()}}catch(t){if(t&&r&&"string"==typeof t.stack){for(var s=t.stack.split("\n"),c=r.stack.split("\n"),u=s.length-1,l=c.length-1;u>=1&&l>=0&&s[u]!==c[l];)l--;for(;u>=1&&l>=0;u--,l--)if(s[u]!==c[l]){if(1!==u||1!==l)do{if(u--,--l<0||s[u]!==c[l]){var f="\n"+s[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&U.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{M=!1,A.current=o,function(){if(0==--N){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:C({},e,{value:R}),info:C({},e,{value:E}),warn:C({},e,{value:$}),error:C({},e,{value:I}),group:C({},e,{value:P}),groupCollapsed:C({},e,{value:T}),groupEnd:C({},e,{value:x})})}N<0&&g("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",m=p?L(p):"";return"function"==typeof e&&U.set(e,m),m}function z(e,t,r){if(null==e)return"";if("function"==typeof e)return Y(e,function(e){var t=e.prototype;return!(!t||!t.isReactComponent)}(e));if("string"==typeof e)return L(e);switch(e){case u:return L("Suspense");case l:return L("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case c:return function(e,t,r){return Y(e,!1)}(e.render);case f:return z(e.type,t,r);case p:var n=e,o=n._payload,a=n._init;try{return z(a(o),t,r)}catch{}}return""}U=new W;var G=Object.prototype.hasOwnProperty,H={},X=_.ReactDebugCurrentFrame;function B(e){if(e){var t=e._owner,r=z(e.type,e._source,t?t.type:null);X.setExtraStackFrame(r)}else X.setExtraStackFrame(null)}var q=Array.isArray;function J(e){return q(e)}function K(e){return""+e}function Q(e){if(function(e){try{return K(e),!1}catch{return!0}}(e))return g("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),K(e)}var Z,ee,te,re=_.ReactCurrentOwner,ne={key:!0,ref:!0,__self:!0,__source:!0};te={};var oe=function(e,r,n,o,a,i,s){var c={$$typeof:t,type:e,key:r,ref:n,props:s,_owner:i,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c};function ae(e,t,r,n,o){var a,i={},s=null,c=null;for(a in void 0!==r&&(Q(r),s=""+r),function(e){if(G.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(Q(t.key),s=""+t.key),function(e){if(G.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e,t){if("string"==typeof e.ref&&re.current&&t&&re.current.stateNode!==t){var r=S(re.current.type);te[r]||(g('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',S(re.current.type),e.ref),te[r]=!0)}}(t,o)),t)G.call(t,a)&&!ne.hasOwnProperty(a)&&(i[a]=t[a]);if(e&&e.defaultProps){var u=e.defaultProps;for(a in u)void 0===i[a]&&(i[a]=u[a])}if(s||c){var l="function"==typeof e?e.displayName||e.name||"Unknown":e;s&&function(e,t){var r=function(){Z||(Z=!0,g("%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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(i,l),c&&function(e,t){var r=function(){ee||(ee=!0,g("%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)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(i,l)}return oe(e,s,c,o,n,re.current,i)}var ie,se=_.ReactCurrentOwner,ce=_.ReactDebugCurrentFrame;function ue(e){if(e){var t=e._owner,r=z(e.type,e._source,t?t.type:null);ce.setExtraStackFrame(r)}else ce.setExtraStackFrame(null)}function le(e){return"object"==typeof e&&null!==e&&e.$$typeof===t}function fe(){if(se.current){var e=S(se.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ie=!1;var pe={};function me(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=fe();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!pe[r]){pe[r]=!0;var n="";e&&e._owner&&e._owner!==se.current&&(n=" It was passed a child from "+S(e._owner.type)+"."),ue(e),g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,n),ue(null)}}}function ye(e,t){if("object"==typeof e)if(J(e))for(var r=0;r<e.length;r++){var n=e[r];le(n)&&me(n,t)}else if(le(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var t=y&&e[y]||e[d];return"function"==typeof t?t:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)le(a.value)&&me(a.value,t)}}function de(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==c&&r.$$typeof!==f)return;t=r.propTypes}if(t){var n=S(r);!function(e,t,r,n,o){var a=Function.call.bind(G);for(var i in e)if(a(e,i)){var s=void 0;try{if("function"!=typeof e[i]){var c=Error((n||"React class")+": "+r+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}s=e[i](t,i,n,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){s=e}s&&!(s instanceof Error)&&(B(o),g("%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",r,i,typeof s),B(null)),s instanceof Error&&!(s.message in H)&&(H[s.message]=!0,B(o),g("Failed %s type: %s",r,s.message),B(null))}}(t,e.props,"prop",n,e)}else if(void 0!==r.PropTypes&&!ie){ie=!0,g("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",S(r)||"Unknown")}"function"==typeof r.getDefaultProps&&!r.getDefaultProps.isReactClassApproved&&g("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function _e(e,r,y,d,_,O){var R=function(e){return!!("string"==typeof e||"function"==typeof e||e===n||e===a||k||e===o||e===u||e===l||w||e===m||h||b||j||"object"==typeof e&&null!==e&&(e.$$typeof===p||e.$$typeof===f||e.$$typeof===i||e.$$typeof===s||e.$$typeof===c||e.$$typeof===v||void 0!==e.getModuleId))}(e);if(!R){var E="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(E+=" 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 $,I=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(_);E+=I||fe(),null===e?$="null":J(e)?$="array":void 0!==e&&e.$$typeof===t?($="<"+(S(e.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):$=typeof e,g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",$,E)}var P=ae(e,r,y,_,O);if(null==P)return P;if(R){var T=r.children;if(void 0!==T)if(d)if(J(T)){for(var x=0;x<T.length;x++)ye(T[x],e);Object.freeze&&Object.freeze(T)}else g("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 ye(T,e)}return e===n?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){ue(e),g("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),ue(null);break}}null!==e.ref&&(ue(e),g("Invalid attribute `ref` supplied to `React.Fragment`."),ue(null))}(P):de(P),P}var ge=function(e,t,r){return _e(e,t,r,!1)},ve=function(e,t,r){return _e(e,t,r,!0)};V.Fragment=n,V.jsx=ge,V.jsxs=ve}()),V}"production"===process.env.NODE_ENV?se.exports=Rr():se.exports=jr();var ue=se.exports;function H(e){if(e&&"object"==typeof e)return e}function X(e){return e&&"string"==typeof e?e:""}const Cr="_screenRightIn_1ojrm_1",Tr="_screenCenterIn_1ojrm_1",Sr="_screenLeftIn_1ojrm_1",Or="_success_1ojrm_114",wr="_info_1ojrm_118",Pr="_warn_1ojrm_123",xr="_error_1ojrm_127",kr="_ghost_1ojrm_132",Ar="_screenOut_1ojrm_1",A={"toast-container":"_toast-container_1ojrm_1","animation-message-right-top":"_animation-message-right-top_1ojrm_9","animation-message-right-center":"_animation-message-right-center_1ojrm_10","animation-message-right-bottom":"_animation-message-right-bottom_1ojrm_11",screenRightIn:Cr,"right-top":"_right-top_1ojrm_15","right-center":"_right-center_1ojrm_16","right-bottom":"_right-bottom_1ojrm_17","animation-message-center-top":"_animation-message-center-top_1ojrm_37","animation-message-center-bottom":"_animation-message-center-bottom_1ojrm_38","animation-message-center-center":"_animation-message-center-center_1ojrm_39",screenCenterIn:Tr,"center-top":"_center-top_1ojrm_43","center-center":"_center-center_1ojrm_44","center-bottom":"_center-bottom_1ojrm_45","animation-message-left-top":"_animation-message-left-top_1ojrm_64","animation-message-left-center":"_animation-message-left-center_1ojrm_65","animation-message-left-bottom":"_animation-message-left-bottom_1ojrm_66",screenLeftIn:Sr,"left-top":"_left-top_1ojrm_70","left-center":"_left-center_1ojrm_71","left-bottom":"_left-bottom_1ojrm_72","toast-message":"_toast-message_1ojrm_90",success:Or,info:wr,warn:Pr,error:xr,ghost:kr,"animation-unmount":"_animation-unmount_1ojrm_136",screenOut:Ar};function Ir({message:{duration:e=7e3,id:t,content:r,type:n},onRemoveMessage:o,classNames:a}){var i,s;const c=null==(i=null==a?void 0:a.toastMessages)?void 0:i["*"],u=null==(s=null==a?void 0:a.toastMessages)?void 0:s[n],[l,f]=We(void 0);function p(){return l?A[l]?A[l]:l:""}const m=Le((()=>{f((null==a?void 0:a.animationUnmount)||"animation-unmount")}),[null==a?void 0:a.animationUnmount]);return Ue((()=>{const t=setTimeout((()=>m()),e);return()=>clearTimeout(t)}),[e,m]),ue.jsx("span",{tabIndex:0,onAnimationEnd:function(e){var r;const n=p();null!=(r=e.currentTarget.classList)&&r.contains(n)&&o(t)},onClick:m,style:{...H(c),...H(u)},className:function(){const e=X(c),t=X(u),r=p(),o=A[`animation-message-${null==a?void 0:a.toastPosition}`];return`${A["toast-message"]} ${A[n]} ${o} ${r} ${t} ${e}`.trim()}(),children:r})}function $r({classNames:e,defaultDuration:t,position:r="right-top"}){var n,o;const a=null==(n=null==e?void 0:e.toastContainer)?void 0:n["*"],i=null==(o=null==e?void 0:e.toastContainer)?void 0:o[r],[s,c]=We([]);const u=Le((e=>{c((t=>t.filter((t=>t.id!==e))))}),[]);return Ue((()=>{function e(e){const{content:r,type:n,duration:o=t}=e;c((e=>[...e,{id:crypto.randomUUID(),content:r,duration:o,type:n}]))}return ie.on("add-toast",e),()=>{ie.removeListener("add-toast",e)}}),[t]),ue.jsx("div",{style:{...H(a),...H(i)},className:function(){const e=X(a),t=X(i);return`${A["toast-container"]} ${A[r]} ${t} ${e}`.trim()}(),children:s.map((t=>ue.jsx(Ir,{message:t,onRemoveMessage:u,classNames:{toastPosition:r,toastMessages:null==e?void 0:e.toastMessages,animationUnmount:null==e?void 0:e.animationUnmount}},t.id)))})}export{$r as ToastContainer,I as toast};