UNPKG

mayank-ui

Version:

Advanced React Toast UI with animations and auto-dismiss

3 lines (2 loc) 2.15 kB
import t,{useState as r,useEffect as n}from"react";import{createPortal as e}from"react-dom";function o(t,r){(null==r||r>t.length)&&(r=t.length);for(var n=0,e=Array(r);n<r;n++)e[n]=t[n];return e}function a(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var e,o,a,i,u=[],l=!0,c=!1;try{if(a=(n=n.call(t)).next,0===r);else for(;!(l=(e=a.call(n)).done)&&(u.push(e.value),u.length!==r);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw o}}return u}}(t,r)||u(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||u(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(t,r){if(t){if("string"==typeof t)return o(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,r):void 0}}var l,c=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.type,e=void 0===n?"info":n,o=r.duration,a=void 0===o?3e3:o;l&&l({id:Date.now(),message:t,type:e,duration:a})},f=function(){var o=a(r([]),2),u=o[0],c=o[1];return n((function(){l=function(t){c((function(r){return[].concat(i(r),[t])})),setTimeout((function(){c((function(r){return r.filter((function(r){return r.id!==t.id}))}))}),t.duration)}}),[]),e(t.createElement("div",{className:"toast-container"},u.map((function(r){return t.createElement("div",{key:r.id,className:"toast toast-".concat(r.type)},r.message)}))),document.body)};export{f as ToastManager,c as toast}; //# sourceMappingURL=index.es.js.map