@tenedev/toast 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/toast.js CHANGED
@@ -16,5 +16,5 @@
16
16
  *
17
17
  * This source code is licensed under the ISC license.
18
18
  * See the LICENSE file in the root directory of this source tree.
19
- */exports.Toaster=function(n){var i=n.position,o=void 0===i?"bottom-right":i,r=n.closeButton,l=void 0!==r&&r,u=n.gap,c=void 0===u?4:u,h=n.duration,d=void 0===h?4e3:h,p=n.richColors,m=void 0!==p&&p,f=e.useState([]),v=f[0],g=f[1],y=e.useRef(new Map),x=e.useCallback((function(t){g((function(e){return e.filter((function(e){return e.id!==t}))})),y.current.has(t)&&(clearTimeout(y.current.get(t)),y.current.delete(t))}),[]),w=e.useCallback((function(t,e){var n=Date.now();g((function(i){return s(s([],i,!0),[{id:n,message:t,description:null==e?void 0:e.description,type:null==e?void 0:e.type}],!1)}));var i=setTimeout((function(){x(n)}),d);y.current.set(n,i)}),[x]);e.useEffect((function(){return a.setAddToast(w),function(){y.current.forEach((function(t){return clearTimeout(t)})),y.current.clear(),g([])}}),[w]);var T={top:{initial:{y:"-50%",opacity:0},exit:{y:"-50%",opacity:0},animate:{y:0,opacity:1}},bottom:{initial:{y:"50%",opacity:0},exit:{y:"50%",opacity:0},animate:{y:0,opacity:1}}},S=o.includes("top")?T.top:T.bottom,b=function(t,e){if(!t)return"";return{success:"text-green-500",error:"text-red-500",info:"text-blue-500",warning:"text-yellow-500"}[e]||""},A=function(e){switch(e){case"success":return t.jsx(ma,{className:"mr-2 w-5"});case"error":return t.jsx(pa,{className:"mr-2 w-5"});case"info":return t.jsx(fa,{className:"mr-2 w-5"});case"warning":return t.jsx(va,{className:"mr-2 w-5"});default:return null}};return t.jsx("div",{style:{gap:"".concat(c,"px"),zIndex:1e3},className:"fixed mx-auto flex w-full min-w-[5%] flex-col sm:max-w-[50%] md:max-w-[30%] ".concat({"top-left":"top-2 left-2","top-mid":"top-2 left-1/2 -translate-x-1/2","top-right":"top-2 right-2","bottom-left":"bottom-2 left-4 flex-col-reverse","bottom-mid":"bottom-2 left-1/2 -translate-x-1/2 flex-col-reverse","bottom-right":"bottom-2 right-2 flex-col-reverse"}[o]),children:t.jsx(P,{children:v.map((function(e){return t.jsxs(la.div,{initial:S.initial,exit:S.exit,animate:S.animate,transition:{type:"spring",duration:.5,stiffness:200,damping:20},className:"relative flex min-h-14 flex-col content-center justify-center rounded-lg border border-zinc-700 p-2 font-medium ".concat(e.type?b(m,e.type):"bg-[#F5F5F5]"),children:[l&&t.jsx("span",{className:"absolute top-1 right-0 cursor-pointer text-black",onClick:function(){return x(e.id)},children:t.jsx(ga,{className:"w-5"})}),t.jsxs("div",{className:"flex items-center",children:[e.type&&A(e.type),e.message]})]},e.id)}))})})},exports.toast=a;
19
+ */exports.Toaster=function(n){var i=n.position,o=void 0===i?"bottom-right":i,r=n.closeButton,l=void 0!==r&&r,u=n.gap,c=void 0===u?5:u,h=n.duration,d=void 0===h?4e3:h,p=n.richColors,m=void 0!==p&&p,f=e.useState([]),v=f[0],g=f[1],y=e.useRef(new Map),x=e.useCallback((function(t){g((function(e){return e.filter((function(e){return e.id!==t}))})),y.current.has(t)&&(clearTimeout(y.current.get(t)),y.current.delete(t))}),[]),w=e.useCallback((function(t,e){var n=Date.now();g((function(i){return s(s([],i,!0),[{id:n,message:t,description:null==e?void 0:e.description,type:null==e?void 0:e.type}],!1)}));var i=setTimeout((function(){x(n)}),d);y.current.set(n,i)}),[x]);e.useEffect((function(){return a.setAddToast(w),function(){y.current.forEach((function(t){return clearTimeout(t)})),y.current.clear(),g([])}}),[w]);var T={top:{initial:{y:"-50%",opacity:0},exit:{y:"-50%",opacity:0},animate:{y:0,opacity:1}},bottom:{initial:{y:"50%",opacity:0},exit:{y:"50%",opacity:0},animate:{y:0,opacity:1}}},S=o.includes("top")?T.top:T.bottom,b=function(t,e){if(!t)return"";return{success:"text-green-500",error:"text-red-500",info:"text-blue-500",warning:"text-yellow-500"}[e]||""},A=function(e){switch(e){case"success":return t.jsx(ma,{className:"mr-2 w-5"});case"error":return t.jsx(pa,{className:"mr-2 w-5"});case"info":return t.jsx(fa,{className:"mr-2 w-5"});case"warning":return t.jsx(va,{className:"mr-2 w-5"});default:return null}};return t.jsx("div",{style:{gap:"".concat(c,"px"),zIndex:1e3},className:"fixed mx-auto flex w-full min-w-[5%] flex-col sm:max-w-[50%] md:max-w-[30%] ".concat({"top-left":"top-2 left-2","top-mid":"top-2 left-1/2 -translate-x-1/2","top-right":"top-2 right-2","bottom-left":"bottom-2 left-4 flex-col-reverse","bottom-mid":"bottom-2 left-1/2 -translate-x-1/2 flex-col-reverse","bottom-right":"bottom-2 right-2 flex-col-reverse"}[o]),children:t.jsx(P,{children:v.slice().reverse().map((function(e){return t.jsxs(la.div,{initial:S.initial,exit:S.exit,animate:S.animate,transition:{type:"spring",duration:.5,stiffness:200,damping:20},className:"relative flex min-h-14 flex-col content-center justify-center rounded-lg border border-zinc-700 p-2 font-medium ".concat(e.type?b(m,e.type):"bg-[#F5F5F5]"),children:[l&&t.jsx("span",{className:"absolute top-1 right-0 cursor-pointer text-black",onClick:function(){return x(e.id)},children:t.jsx(ga,{className:"w-5"})}),t.jsxs("div",{className:"flex items-center",children:[e.type&&A(e.type),e.message]})]},e.id)}))})})},exports.toast=a;
20
20
  //# sourceMappingURL=toast.js.map