mayank-ui
Version:
Advanced React Toast UI with animations and auto-dismiss
3 lines (2 loc) • 2.13 kB
JavaScript
;var t,r=require("react"),e=require("react-dom");function n(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function o(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,a,i,u=[],c=!0,l=!1;try{if(a=(e=e.call(t)).next,0===r);else for(;!(c=(n=a.call(e)).done)&&(u.push(n.value),u.length!==r);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=e.return&&(i=e.return(),Object(i)!==i))return}finally{if(l)throw o}}return u}}(t,r)||i(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 a(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(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 i(t,r){if(t){if("string"==typeof t)return n(t,r);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(t,r):void 0}}exports.ToastManager=function(){var n=o(r.useState([]),2),i=n[0],u=n[1];return r.useEffect((function(){t=function(t){u((function(r){return[].concat(a(r),[t])})),setTimeout((function(){u((function(r){return r.filter((function(r){return r.id!==t.id}))}))}),t.duration)}}),[]),e.createPortal(r.createElement("div",{className:"toast-container"},i.map((function(t){return r.createElement("div",{key:t.id,className:"toast toast-".concat(t.type)},t.message)}))),document.body)},exports.toast=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.type,o=void 0===n?"info":n,a=e.duration,i=void 0===a?3e3:a;t&&t({id:Date.now(),message:r,type:o,duration:i})};
//# sourceMappingURL=index.js.map