UNPKG

toastmandu

Version:

Simple toast notification system

9 lines (6 loc) 3.38 kB
"use strict";var v=Object.create;var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var o in e)l(t,o,{get:e[o],enumerable:!0})},g=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of u(e))!f.call(t,a)&&a!==o&&l(t,a,{get:()=>e[a],enumerable:!(i=h(e,a))||i.enumerable});return t};var k=(t,e,o)=>(o=t!=null?v(x(t)):{},g(e||!t||!t.__esModule?l(o,"default",{value:t,enumerable:!0}):o,t)),C=t=>g(l({},"__esModule",{value:!0}),t);var N={};y(N,{ToastContainer:()=>p,toast:()=>b});module.exports=C(N);var w=k(require("react"),1);var c=new Set,n=[],d={subscribe(t){return c.add(t),t(n),()=>c.delete(t)},push(t){let e={...t,id:Date.now()};n=[...n,e],c.forEach(o=>o(n)),console.log("listeners before ",c),setTimeout(()=>{console.log("listeners ",c),n=n.filter(o=>o.id!==e.id),c.forEach(o=>o(n))},5e3)}};var s=require("lucide-react");var r=require("react/jsx-runtime"),p=()=>{let[t,e]=(0,w.useState)([]);console.log("all toasts",t),w.default.useEffect(()=>{let i=d.subscribe(e);console.log("unsubscribe",i)},[]);let o={success:{icon:s.CheckCircle,bgColor:"bg-emerald-500",iconBgColor:"bg-emerald-600",checkColor:"text-white"},error:{icon:s.XCircle,bgColor:"bg-red-500",iconBgColor:"bg-red-600",checkColor:"text-white"},warning:{icon:s.AlertCircle,bgColor:"bg-amber-500",iconBgColor:"bg-amber-600",checkColor:"text-white"},info:{icon:s.Info,bgColor:"bg-blue-500",iconBgColor:"bg-blue-600",checkColor:"text-white"}};return(0,r.jsx)("div",{className:"fixed top-4 right-4 space-y-3 z-50 max-w-sm w-full",children:t?.map(i=>{let a=o[i.type],m=a.icon;return(0,r.jsx)("div",{className:` ${a.bgColor} rounded-2xl shadow-lg transform transition-all duration-500 ease-out animate-slide-in hover:scale-105 overflow-hidden `,children:(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsx)("div",{className:"flex-shrink-0 px-4 py-2",children:(0,r.jsxs)("div",{className:"relative",children:[(0,r.jsx)("div",{className:`absolute -top-2 -left-2 w-8 h-8 ${a.iconBgColor} rounded-full opacity-60`}),(0,r.jsx)("div",{className:`absolute -bottom-1 -right-1 w-4 h-4 ${a.iconBgColor} rounded-full opacity-40`}),(0,r.jsx)("div",{className:`absolute top-1 -right-3 w-2 h-2 ${a.iconBgColor} rounded-full opacity-80`}),(0,r.jsx)("div",{className:`relative w-12 h-12 ${a.iconBgColor} rounded-full flex items-center justify-center`,children:(0,r.jsx)(m,{className:`${a.checkColor} w-6 h-6`})})]})}),(0,r.jsx)("div",{className:"flex-1 py-2 pr-2",children:(0,r.jsxs)("div",{className:"flex items-start justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-white font-semibold text-base leading-tight ",children:i.title}),(0,r.jsx)("p",{className:"text-white/90 text-sm leading-relaxed ",children:i.message})]}),(0,r.jsx)("button",{className:"ml-2 bg-transparent border-none outline-none text-white ",children:(0,r.jsx)(s.X,{className:"w-4 h-4"})})]})})]})},i.id)})})};var b={success:t=>{d.push({type:"success",message:t||"Operation was successful!"})},error:t=>{d.push({type:"error",message:t||"An error occurred!"})},info:t=>{d.push({type:"info",message:t||"Here is some information."})}};0&&(module.exports={ToastContainer,toast});