@nicojones/toast 2.0.0 → 2.1.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/README.md +7 -4
- package/dist/main.cjs +2 -2
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.cts +20 -20
- package/dist/main.d.ts +20 -20
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -165,17 +165,20 @@ toast.success({
|
|
|
165
165
|
Show a toast with loading state that automatically updates after a promise resolves or fails:
|
|
166
166
|
|
|
167
167
|
```tsx
|
|
168
|
-
|
|
168
|
+
const somePromise = (): Promise<Foo> => { ... }
|
|
169
|
+
|
|
170
|
+
toast.loading<Foo>({
|
|
169
171
|
// Initial message:
|
|
170
172
|
text: "Loading",
|
|
171
173
|
options: {
|
|
172
|
-
promise:
|
|
174
|
+
promise: somePromise(),
|
|
173
175
|
success: "Ready",
|
|
174
176
|
error: "Error",
|
|
175
177
|
// Close toast automatically (the duration depends by delayDuration property):
|
|
176
178
|
autoDismiss: true,
|
|
177
179
|
// Optional:
|
|
178
180
|
onSuccess: (data) => {
|
|
181
|
+
// `data is of type Foo`
|
|
179
182
|
console.log("Success", data);
|
|
180
183
|
},
|
|
181
184
|
// Optional:
|
|
@@ -531,8 +534,8 @@ The `toast.loading` function accepts the same options as above, plus:
|
|
|
531
534
|
| `success` | Success message | `string` | ✅ |
|
|
532
535
|
| `error` | Error message | `string` | ✅ |
|
|
533
536
|
| `autoDismiss` | Close toast automatically after promise | `boolean` | ✅ |
|
|
534
|
-
| `onSuccess` | Callback when promise resolves | `(data: T) => void`
|
|
535
|
-
| `onError` | Callback when promise rejects | `(error: Error, id
|
|
537
|
+
| `onSuccess` | Callback when promise resolves | `(data: T, id: ToastId) => void` | - |
|
|
538
|
+
| `onError` | Callback when promise rejects | `(error: Error, id: ToastId) => void` | - |
|
|
536
539
|
|
|
537
540
|
### `toast.close()`
|
|
538
541
|
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
"use strict";var
|
|
3
|
-
`);var y=require("react");var g=require("react");var m=require("react/jsx-runtime"),
|
|
2
|
+
"use strict";var I=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var q=(t,o)=>{for(var e in o)I(t,e,{get:o[e],enumerable:!0})},J=(t,o,e,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of Q(o))!X.call(t,s)&&s!==e&&I(t,s,{get:()=>o[s],enumerable:!(a=H(o,s))||a.enumerable});return t};var K=t=>J(I({},"__esModule",{value:!0}),t);var nt={};q(nt,{Toaster:()=>Y,toast:()=>$});module.exports=K(nt);function N(t,{insertAt:o}={}){if(!t||typeof document>"u")return;let e=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",o==="top"&&e.firstChild?e.insertBefore(a,e.firstChild):e.appendChild(a),a.styleSheet?a.styleSheet.cssText=t:a.appendChild(document.createTextNode(t))}N(`:root{--pheralb-toast-animation-enter: .4s;--pheralb-toast-animation-exit: .4s}:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_light-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_dark-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}@media (prefers-color-scheme: dark){:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}}.t_toasts{display:flex;flex-direction:column;gap:10px;padding:14px;position:fixed;z-index:999;overflow:hidden;transition:max-height .5s ease-in-out;width:100%}.t_default_font{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.t_top-left{top:0;left:0}.t_top-right{top:0;right:0}.t_top-center{top:0;left:50%;transform:translate(-50%)}.t_bottom-left{bottom:0;left:0}.t_bottom-right{bottom:0;right:0}.t_bottom-center{bottom:0;left:50%;transform:translate(-50%)}@media (min-width: 768px){.t_toasts{max-width:355px}}.t_global{display:flex;justify-content:space-between;padding:0;margin:0;list-style:none;outline:none;background-color:var(--background-color);width:auto;box-shadow:0 1px 3px 0 var(--box-shadow),0 1px 2px -1px var(--box-shadow);border:1px solid var(--border-color);border-radius:.375rem;font-size:.875rem;line-height:1.25rem;overflow:hidden}.t_global button{border:none;outline:none}.t_global button:focus{outline:1px solid var(--focus-color);outline-offset:0px;background-color:var(--hover-color)}.t_container{display:flex;flex-direction:row;align-items:center;width:100%;max-width:20rem;height:100wh;gap:.6rem;padding:12px;word-wrap:break-word;overflow-wrap:break-word}.t_icon{fill:var(--text-color);margin-top:.1rem;flex-shrink:0}.t_content{display:flex;flex-direction:column;justify-content:center;max-width:100%}.t_content p{font-weight:600;color:var(--text-color);margin:0}.t_content p:nth-of-type(2){font-weight:400;font-size:.75rem;color:var(--description-color)}.t_actions{display:flex;flex-direction:column;border-left:1px solid var(--border-color);height:100wh}.t_actions>button{flex:1 1 0%;width:100%;padding:6px 20px;font-size:13px;background-color:transparent;cursor:pointer;border:none}.t_actions>button:nth-child(1){color:var(--text-color);font-weight:500}.t_actions>button:nth-child(2){color:var(--text-color);border-top:1px solid var(--border-color)}.t_actions>button:hover{background-color:var(--hover-color)}.t_loading{animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.t_slide-enter-top{animation:slide-top var(--pheralb-toast-animation-enter) ease}@keyframes slide-top{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.t_slide-enter-bottom{animation:slide-bottom var(--pheralb-toast-animation-enter) ease}@keyframes slide-bottom{0%{opacity:0;transform:translateY(100%)}to{opacity:1;transform:translateY(0)}}.t-slide-exit-top,.t-slide-exit-bottom{will-change:transform,opacity}.t-slide-exit-top{animation:slide-top-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-top-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t-slide-exit-bottom{animation:slide-bottom-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-bottom-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(100%)}}.t_swipe-exit-center{animation:swipe-center-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-center-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t_swipe-exit-left{animation:swipe-left-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-left-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100%)}}.t_swipe-exit-right{animation:swipe-right-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-right-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(100%)}}
|
|
3
|
+
`);var y=require("react");var g=require("react");var m=require("react/jsx-runtime"),z=t=>(0,m.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:(0,m.jsx)("path",{d:"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z"})}),E=t=>(0,m.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:(0,m.jsx)("path",{d:"M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z"})}),R=t=>(0,m.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:(0,m.jsx)("path",{d:"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z"})}),S=t=>(0,m.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:(0,m.jsx)("path",{d:"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z"})}),L=t=>(0,m.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:(0,m.jsx)("path",{d:"M136 32v32a8 8 0 01-16 0V32a8 8 0 0116 0zm37.25 58.75a8 8 0 005.66-2.35l22.63-22.62a8 8 0 00-11.32-11.32L167.6 77.09a8 8 0 005.65 13.66zM224 120h-32a8 8 0 000 16h32a8 8 0 000-16zm-45.09 47.6a8 8 0 00-11.31 11.31l22.62 22.63a8 8 0 0011.32-11.32zM128 184a8 8 0 00-8 8v32a8 8 0 0016 0v-32a8 8 0 00-8-8zm-50.91-16.4l-22.63 22.62a8 8 0 0011.32 11.32l22.62-22.63a8 8 0 00-11.31-11.31zM72 128a8 8 0 00-8-8H32a8 8 0 000 16h32a8 8 0 008-8zm-6.22-73.54a8 8 0 00-11.32 11.32L77.09 88.4A8 8 0 0088.4 77.09z"})});var r=require("react"),B=(t,o)=>{let e=(0,r.useRef)(0),a=(0,r.useRef)(t),s=(0,r.useRef)(0),f=(0,r.useRef)(o),l=(0,r.useRef)(!0),h=(0,r.useCallback)(()=>{e.current&&window.clearTimeout(e.current)},[]),v=(0,r.useCallback)(()=>{!l.current||!s.current||(h(),f.current-=Date.now()-s.current,l.current=!1)},[h]),x=(0,r.useCallback)(()=>{l.current||(s.current=Date.now(),e.current=window.setTimeout(a.current,f.current),l.current=!0)},[]),u=(0,r.useCallback)(()=>{h(),f.current=o,s.current=Date.now(),e.current=window.setTimeout(a.current,o),l.current=!0},[h,o]);return(0,r.useEffect)(()=>{a.current=t},[t]),(0,r.useEffect)(()=>(u(),h),[o,u,h]),{pause:v,resume:x,reset:u,isActive:l.current}};var d=(...t)=>t.filter(Boolean).join(" "),O=()=>Math.random().toString(16).slice(2,10),W=(()=>{let t;return()=>(t===void 0&&(typeof window<"u"&&window.matchMedia!==void 0?t=window.matchMedia("(prefers-reduced-motion: reduce)").matches:t=!1),t)})(),D=()=>typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"t_dark-theme":"t_light-theme";var C={success:"#22c55e",error:"#ef4444",warning:"#eab308",info:"#3b82f6",loading:"currentColor"},Z={"top-left":"t_slide-enter-top","top-right":"t_slide-enter-top","top-center":"t_slide-enter-top","bottom-left":"t_slide-enter-bottom","bottom-right":"t_slide-enter-bottom","bottom-center":"t_slide-enter-bottom"},tt={"top-left":"t-slide-exit-top","top-right":"t-slide-exit-top","top-center":"t-slide-exit-top","bottom-left":"t-slide-exit-bottom","bottom-right":"t-slide-exit-bottom","bottom-center":"t-slide-exit-bottom"},ot={"top-left":"t_swipe-exit-left","top-right":"t_swipe-exit-right","top-center":"t_swipe-exit-center","bottom-left":"t_swipe-exit-left","bottom-right":"t_swipe-exit-right","bottom-center":"t_swipe-exit-center"},F=(t,o,e)=>t?o==="swipe"?ot[e]:tt[e]:Z[e];var n=require("react/jsx-runtime"),et=4e3,at=t=>{let[o,e]=(0,g.useState)(t.variant||"info"),[a,s]=(0,g.useState)(C[o]),[f,l]=(0,g.useState)(t.text),[h,v]=(0,g.useState)(!1),x=t.delayDuration||et,{pause:u,resume:c}=B(()=>{b()},x),i=d("t_icon",t.variant==="loading"&&o==="loading"?"t_loading":""),p={success:(0,n.jsx)(z,{width:18,height:18,style:{fill:a},className:i}),error:(0,n.jsx)(R,{width:18,height:18,style:{fill:a},className:i}),warning:(0,n.jsx)(E,{width:18,height:18,style:{fill:a},className:i}),info:(0,n.jsx)(S,{width:18,height:18,style:{fill:a},className:i}),loading:(0,n.jsx)(L,{width:18,height:18,style:{fill:a},className:i})},_=t.toastOptions?.icons?t.toastOptions?.icons[o]:p[o],b=(0,g.useCallback)(()=>{v(!0),W()?t.onClose&&t.onClose():setTimeout(()=>{t.onClose&&t.onClose()},300)},[t]),P=()=>{c()},w=()=>{u()};return(0,g.useEffect)(()=>{t.variant==="loading"&&t.options&&(u(),(typeof t.options.promise=="function"?t.options.promise():Promise.resolve(t.options.promise)).then(k=>{c(),e("success"),t.options.autoDismiss&&setTimeout(()=>{b()},x),l(t.options.success),s(C.success),t.options?.onSuccess&&t.options.onSuccess(k,t.id)}).catch(k=>{e("error"),l(t.options.error),s(C.error),t.options.autoDismiss&&setTimeout(()=>{b()},x),t.options?.onError&&t.options.onError(k,t.id)}))},[x,b,u,t.id,t.options,t.variant,c]),(0,n.jsxs)("div",{...t.attrs,role:"alert","aria-labelledby":`toast-title-${t.id}`,"aria-describedby":`toast-description-${t.id}`,title:t.text,className:d(W()||t.isUpdate?"":F(h,t.toastOptions?.animationOnClose||"slide",t.toastPosition),!t.toastOptions?.headless&&t.theme==="system"?D():"",!t.toastOptions?.headless&&t.theme==="dark"?"t_dark-theme":"",!t.toastOptions?.headless&&t.theme==="light"?"t_light-theme":"",t.toastOptions?.headless?"":"t_global",t.toastOptions?.classNames?.toast,t.attrs?.className),style:{zIndex:t.active?1e3:999,...t.attrs?.style},onMouseEnter:w,onMouseLeave:P,onFocus:w,onBlur:P,children:[(0,n.jsxs)("div",{className:d(t.toastOptions?.headless?"":"t_container",t.toastOptions?.classNames?.container),children:[t.variant&&!t.icon?(0,n.jsx)("div",{className:d(t.toastOptions?.headless?"":"t_icon",t.toastOptions?.classNames?.icon),children:_}):t.icon&&(0,n.jsx)("div",{className:d(t.toastOptions?.headless?"":"t_icon",t.toastOptions?.classNames?.icon),children:t.icon}),(0,n.jsxs)("div",{className:d(t.toastOptions?.headless?"":"t_content",t.toastOptions?.classNames?.content),children:[(0,n.jsx)("p",{id:`toast-title-${t.id}`,children:f}),t.description&&(0,n.jsx)("p",{id:`toast-description-${t.id}`,children:t.description})]})]}),(0,n.jsxs)("div",{className:d(t.toastOptions?.headless?"":"t_actions",t.toastOptions?.classNames?.actions?.container),children:[t.action&&(0,n.jsx)("button",{onClick:t.action.onClick,title:typeof t.action.content=="string"?t.action.content:"Action Button",className:d(t.toastOptions?.classNames?.actions?.actionBtn),children:t.action.content??t.toastOptions?.defaultActionContent??"Action"}),(0,n.jsx)("button",{onClick:b,title:"Close toast",className:d(t.toastOptions?.classNames?.actions?.closeBtn),children:t.toastOptions?.defaultCloseContent??"Close"})]})]})},U=at;var V=require("react/jsx-runtime"),A,M,Y=({maxToasts:t=4,position:o="bottom-right",theme:e="system",toastOptions:a,...s})=>{let[f,l]=(0,y.useState)([]),[h,v]=(0,y.useState)(!1);(0,y.useEffect)(()=>{v(!0)},[]);let x=c=>{let i={_key_:O(),id:O(),...c};l(p=>{let _=o==="top-left"||o==="top-right"||o==="top-center",b=!1,P=p.map(w=>w.id===i.id?(b=!0,{...w,...i,isUpdate:!0}):w);return b?[...P]:p.length>=t?_?[i,...p.slice(0,-1)]:[...p.slice(1),i]:_?[i,...p]:[...p,i]})},u=c=>{l(i=>i.filter(p=>p.id!==c))};return A=x,M=u,h&&f.length>0&&(0,V.jsx)("section",{...s,"aria-label":"Toast Notifications",role:"alert","aria-live":"polite",className:d("t_toasts",o==="top-left"?"t_top-left":"",o==="top-right"?"t_top-right":"",o==="top-center"?"t_top-center":"",o==="bottom-left"?"t_bottom-left":"",o==="bottom-right"?"t_bottom-right":"",o==="bottom-center"?"t_bottom-center":"",a?.font?a?.font:"t_default_font"),children:f.map(c=>(0,V.jsx)(U,{theme:e,toastPosition:o,onClose:()=>u(c.id),toastOptions:a,active:f.indexOf(c)===f.length-1,...c},c._key_))})},T=t=>{A?A(t):console.error("\u{1F514} <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.")},j=t=>{M?M(t):console.error("\u{1F514} <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.")};var $={default:t=>(T({...t}),t),success:t=>(T({...t,variant:"success"}),t),error:t=>(T({...t,variant:"error"}),t),warning:t=>(T({...t,variant:"warning"}),t),info:t=>(T({...t,variant:"info"}),t),loading:t=>(T({...t,variant:"loading"}),t),close:t=>j(t)};0&&(module.exports={Toaster,toast});
|
|
4
4
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/main.tsx","#style-inject:#style-inject","../src/styles/globals.css","../src/components/toaster.tsx","../src/components/toast.tsx","../src/icons/index.tsx","../src/hooks/useTimeout.tsx","../src/utils/index.ts","../src/components/default-options.ts","../src/components/toast-functions.ts"],"sourcesContent":["/* eslint-disable react-refresh/only-export-components */\nimport \"./styles/globals.css\";\n\nexport { toast } from \"./components/toast-functions\";\nexport { Toaster } from \"./components/toaster\";\nexport type {\n Position as ToastPosition,\n ToastProps as ToastProperties,\n Variant as ToastVariant,\n Theme as ToastTheme,\n ToastOptions,\n ToasterProperties,\n ToastPropsWithLoading,\n ToastPropsWithVariant,\n ToastAnimations,\n} from \"./types/toast.types\";\n","\n export default function styleInject(css, { insertAt } = {}) {\n if (!css || typeof document === 'undefined') return\n \n const head = document.head || document.getElementsByTagName('head')[0]\n const style = document.createElement('style')\n style.type = 'text/css'\n \n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild)\n } else {\n head.appendChild(style)\n }\n } else {\n head.appendChild(style)\n }\n \n if (style.styleSheet) {\n style.styleSheet.cssText = css\n } else {\n style.appendChild(document.createTextNode(css))\n }\n }\n ","import styleInject from '#style-inject';styleInject(\":root{--pheralb-toast-animation-enter: .4s;--pheralb-toast-animation-exit: .4s}:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_light-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_dark-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}@media (prefers-color-scheme: dark){:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}}.t_toasts{display:flex;flex-direction:column;gap:10px;padding:14px;position:fixed;z-index:999;overflow:hidden;transition:max-height .5s ease-in-out;width:100%}.t_default_font{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.t_top-left{top:0;left:0}.t_top-right{top:0;right:0}.t_top-center{top:0;left:50%;transform:translate(-50%)}.t_bottom-left{bottom:0;left:0}.t_bottom-right{bottom:0;right:0}.t_bottom-center{bottom:0;left:50%;transform:translate(-50%)}@media (min-width: 768px){.t_toasts{max-width:355px}}.t_global{display:flex;justify-content:space-between;padding:0;margin:0;list-style:none;outline:none;background-color:var(--background-color);width:auto;box-shadow:0 1px 3px 0 var(--box-shadow),0 1px 2px -1px var(--box-shadow);border:1px solid var(--border-color);border-radius:.375rem;font-size:.875rem;line-height:1.25rem;overflow:hidden}.t_global button{border:none;outline:none}.t_global button:focus{outline:1px solid var(--focus-color);outline-offset:0px;background-color:var(--hover-color)}.t_container{display:flex;flex-direction:row;align-items:center;width:100%;max-width:20rem;height:100wh;gap:.6rem;padding:12px;word-wrap:break-word;overflow-wrap:break-word}.t_icon{fill:var(--text-color);margin-top:.1rem;flex-shrink:0}.t_content{display:flex;flex-direction:column;justify-content:center;max-width:100%}.t_content p{font-weight:600;color:var(--text-color);margin:0}.t_content p:nth-of-type(2){font-weight:400;font-size:.75rem;color:var(--description-color)}.t_actions{display:flex;flex-direction:column;border-left:1px solid var(--border-color);height:100wh}.t_actions>button{flex:1 1 0%;width:100%;padding:6px 20px;font-size:13px;background-color:transparent;cursor:pointer;border:none}.t_actions>button:nth-child(1){color:var(--text-color);font-weight:500}.t_actions>button:nth-child(2){color:var(--text-color);border-top:1px solid var(--border-color)}.t_actions>button:hover{background-color:var(--hover-color)}.t_loading{animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.t_slide-enter-top{animation:slide-top var(--pheralb-toast-animation-enter) ease}@keyframes slide-top{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.t_slide-enter-bottom{animation:slide-bottom var(--pheralb-toast-animation-enter) ease}@keyframes slide-bottom{0%{opacity:0;transform:translateY(100%)}to{opacity:1;transform:translateY(0)}}.t-slide-exit-top,.t-slide-exit-bottom{will-change:transform,opacity}.t-slide-exit-top{animation:slide-top-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-top-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t-slide-exit-bottom{animation:slide-bottom-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-bottom-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(100%)}}.t_swipe-exit-center{animation:swipe-center-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-center-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t_swipe-exit-left{animation:swipe-left-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-left-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100%)}}.t_swipe-exit-right{animation:swipe-right-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-right-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(100%)}}\\n\")","import { useEffect, useState } from \"react\";\n\nimport type {\n ToastId,\n ToastPropsWithVariant,\n ToasterProperties,\n} from \"../types/toast.types\";\n\nimport ToastComponent from \"./toast\";\nimport { cn, generateRandomId } from \"../utils\";\n\n// Ensure openToastGlobal is initialized correctly\nlet openToastGlobal: (data: ToastPropsWithVariant) => void;\n// Ensure closeToastGlobal is initialized correctly\nlet closeToastGlobal: (id: ToastId) => void;\n\nexport const Toaster = ({\n maxToasts = 4,\n position = \"bottom-right\",\n theme = \"system\",\n toastOptions,\n ...htmlProps\n}: ToasterProperties) => {\n const [toasts, setToasts] = useState<ToastPropsWithVariant[]>([]);\n const [isMounted, setIsMounted] = useState<boolean>(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // Define the openToast function\n const openToast = (data: ToastPropsWithVariant) => {\n const newToast = {\n id: generateRandomId(),\n ...data,\n };\n setToasts((prevToasts) => {\n const isTopPosition =\n position === \"top-left\" ||\n position === \"top-right\" ||\n position === \"top-center\";\n\n // If the `id` exists, update the notification\n let isToastUpdate = false;\n const updatedToasts = prevToasts.map(pt => {\n if (pt.id === newToast.id) {\n isToastUpdate = true;\n return {...pt, ...newToast}\n }\n return pt\n })\n\n if (isToastUpdate) {\n // `newToast` is embedded, array preserves length\n return [...updatedToasts]\n }\n\n if (prevToasts.length >= maxToasts) {\n return isTopPosition\n ? [newToast, ...prevToasts.slice(0, -1)]\n : [...prevToasts.slice(1), newToast];\n }\n\n return isTopPosition\n ? [newToast, ...prevToasts]\n : [...prevToasts, newToast];\n });\n };\n\n // Define the closeToast function\n const closeToast = (id: ToastId) => {\n setToasts((prevToasts) => prevToasts.filter((toast) => toast.id !== id));\n };\n\n // Assign openToast to the global variable\n openToastGlobal = openToast;\n // Assign closeToast to the global variable\n closeToastGlobal = closeToast;\n\n // Render the component\n return (\n isMounted &&\n toasts.length > 0 && (\n <section\n {...htmlProps}\n aria-label=\"Toast Notifications\"\n role=\"alert\"\n aria-live=\"polite\"\n className={cn(\n \"t_toasts\",\n position === \"top-left\" ? \"t_top-left\" : \"\",\n position === \"top-right\" ? \"t_top-right\" : \"\",\n position === \"top-center\" ? \"t_top-center\" : \"\",\n position === \"bottom-left\" ? \"t_bottom-left\" : \"\",\n position === \"bottom-right\" ? \"t_bottom-right\" : \"\",\n position === \"bottom-center\" ? \"t_bottom-center\" : \"\",\n toastOptions?.font ? toastOptions?.font : \"t_default_font\",\n )}\n >\n {toasts.map((toast) => (\n <ToastComponent\n key={toast.id}\n theme={theme}\n toastPosition={position}\n onClose={() => closeToast(toast.id!)}\n toastOptions={toastOptions}\n active={toasts.indexOf(toast) === toasts.length - 1}\n {...toast}\n />\n ))}\n </section>\n )\n );\n};\n\n// Export the openToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const openToast = (data: ToastPropsWithVariant): void => {\n if (openToastGlobal) {\n openToastGlobal(data);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n\n// Export the closeToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const closeToast = (id: ToastId): void => {\n if (closeToastGlobal) {\n closeToastGlobal(id);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n","import type {\n Position,\n ToastIcons,\n ToastOptions,\n ToastPropsWithLoading,\n Variant,\n} from \"../types/toast.types\";\n\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { Error, Info, Loading, Success, Warning } from \"../icons\";\nimport { useTimeout } from \"../hooks/useTimeout\";\nimport { cn, getSystemTheme, prefersReducedMotion } from \"../utils\";\n\nimport { iconsColors, getAnimationClass } from \"./default-options\";\n\ninterface ToastComponentProps extends ToastPropsWithLoading {\n toastPosition: Position;\n toastOptions?: ToastOptions;\n active?: boolean;\n onClose: () => void;\n}\n\nconst Toast = (props: ToastComponentProps) => {\n const [status, setStatus] = useState<Variant>(props.variant || \"info\");\n const [iconColor, setIconColor] = useState<string>(iconsColors[status]);\n const [toastText, setToastText] = useState<string>(props.text);\n const [isExiting, setIsExiting] = useState<boolean>(false);\n\n const delayDuration = props.delayDuration || 4000;\n\n const { pause, resume } = useTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n\n const iconClass = cn(\n \"t_icon\",\n props.variant === \"loading\" && status === \"loading\" ? \"t_loading\" : \"\",\n );\n\n const icons: ToastIcons = {\n success: (\n <Success\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n error: (\n <Error\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n warning: (\n <Warning\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n info: (\n <Info\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n loading: (\n <Loading\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n };\n\n const IconComponent = props.toastOptions?.icons\n ? props.toastOptions?.icons[status]\n : icons[status];\n\n const handleCloseToast = useCallback(() => {\n setIsExiting(true);\n const animationDisabled = prefersReducedMotion();\n if (!animationDisabled) {\n setTimeout(() => {\n if (props.onClose) {\n props.onClose();\n }\n }, 300);\n } else if (props.onClose) {\n props.onClose();\n }\n }, [props]);\n\n const handleMouseLeave = () => {\n resume();\n };\n\n const handleMouseEnter = () => {\n pause();\n };\n\n useEffect(() => {\n if (props.variant === \"loading\" && props.options) {\n pause();\n\n const executePromise =\n typeof props.options.promise === \"function\"\n ? props.options.promise()\n : Promise.resolve(props.options.promise);\n\n executePromise\n .then((data) => {\n resume();\n setStatus(\"success\");\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n setToastText(props.options!.success);\n setIconColor(iconsColors.success);\n if (props.options?.onSuccess) {\n props.options.onSuccess(data);\n }\n })\n .catch((error) => {\n setStatus(\"error\");\n setToastText(props.options!.error);\n setIconColor(iconsColors.error);\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n if (props.options?.onError) {\n props.options.onError(error, props.id);\n }\n });\n }\n }, [\n delayDuration,\n handleCloseToast,\n pause,\n props.options,\n props.variant,\n resume,\n ]);\n\n return (\n <div\n {...props.attrs}\n role=\"alert\"\n aria-labelledby={`toast-title-${props.id}`}\n aria-describedby={`toast-description-${props.id}`}\n title={props.text}\n className={cn(\n !prefersReducedMotion()\n ? getAnimationClass(\n isExiting,\n props.toastOptions?.animationOnClose || \"slide\",\n props.toastPosition,\n )\n : \"\",\n !props.toastOptions?.headless && props.theme === \"system\"\n ? getSystemTheme()\n : \"\",\n !props.toastOptions?.headless && props.theme === \"dark\"\n ? \"t_dark-theme\"\n : \"\",\n !props.toastOptions?.headless && props.theme === \"light\"\n ? \"t_light-theme\"\n : \"\",\n !props.toastOptions?.headless ? \"t_global\" : \"\",\n props.toastOptions?.classNames?.toast,\n props.attrs?.className,\n )}\n style={{\n zIndex: props.active ? 1000 : 999,\n ...props.attrs?.style,\n }}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleMouseEnter}\n onBlur={handleMouseLeave}\n >\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_container\" : \"\",\n props.toastOptions?.classNames?.container,\n )}\n >\n {props.variant && !props.icon ? (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {IconComponent}\n </div>\n ) : (\n props.icon && (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {props.icon}\n </div>\n )\n )}\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_content\" : \"\",\n props.toastOptions?.classNames?.content,\n )}\n >\n <p id={`toast-title-${props.id}`}>{toastText}</p>\n {props.description && (\n <p id={`toast-description-${props.id}`}>{props.description}</p>\n )}\n </div>\n </div>\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_actions\" : \"\",\n props.toastOptions?.classNames?.actions?.container,\n )}\n >\n {props.action && (\n <button\n onClick={props.action.onClick}\n title={\n typeof props.action.content === \"string\"\n ? props.action.content\n : \"Action Button\"\n }\n className={cn(props.toastOptions?.classNames?.actions?.actionBtn)}\n >\n {props.action.content ??\n props.toastOptions?.defaultActionContent ??\n \"Action\"}\n </button>\n )}\n <button\n onClick={handleCloseToast}\n title=\"Close toast\"\n className={cn(props.toastOptions?.classNames?.actions?.closeBtn)}\n >\n {props.toastOptions?.defaultCloseContent ?? \"Close\"}\n </button>\n </div>\n </div>\n );\n};\n\nexport default Toast;\n","import type { ComponentProps, FC } from \"react\";\n\nexport const Success: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z\"></path>\n </svg>\n);\n\nexport const Warning: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Error: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Info: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z\"></path>\n </svg>\n);\n\nexport const Loading: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M136 32v32a8 8 0 01-16 0V32a8 8 0 0116 0zm37.25 58.75a8 8 0 005.66-2.35l22.63-22.62a8 8 0 00-11.32-11.32L167.6 77.09a8 8 0 005.65 13.66zM224 120h-32a8 8 0 000 16h32a8 8 0 000-16zm-45.09 47.6a8 8 0 00-11.31 11.31l22.62 22.63a8 8 0 0011.32-11.32zM128 184a8 8 0 00-8 8v32a8 8 0 0016 0v-32a8 8 0 00-8-8zm-50.91-16.4l-22.63 22.62a8 8 0 0011.32 11.32l22.62-22.63a8 8 0 00-11.31-11.31zM72 128a8 8 0 00-8-8H32a8 8 0 000 16h32a8 8 0 008-8zm-6.22-73.54a8 8 0 00-11.32 11.32L77.09 88.4A8 8 0 0088.4 77.09z\"></path>\n </svg>\n);\n","import { useCallback, useEffect, useRef } from \"react\";\n\ninterface UseTimeoutReturn {\n pause: () => void;\n resume: () => void;\n reset: () => void;\n isActive: boolean;\n}\n\nexport const useTimeout = (\n callback: () => void,\n delay: number,\n): UseTimeoutReturn => {\n const timeoutRef = useRef<number>(0);\n const callbackRef = useRef(callback);\n const startTimeRef = useRef<number>(0);\n const remainingRef = useRef(delay);\n const isActiveRef = useRef(true);\n\n const cleanup = useCallback(() => {\n if (timeoutRef.current) {\n window.clearTimeout(timeoutRef.current);\n }\n }, []);\n\n const pause = useCallback(() => {\n if (!isActiveRef.current || !startTimeRef.current) return;\n\n cleanup();\n remainingRef.current -= Date.now() - startTimeRef.current;\n isActiveRef.current = false;\n }, [cleanup]);\n\n const resume = useCallback(() => {\n if (isActiveRef.current) return;\n\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(\n callbackRef.current,\n remainingRef.current,\n );\n isActiveRef.current = true;\n }, []);\n\n const reset = useCallback(() => {\n cleanup();\n remainingRef.current = delay;\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(callbackRef.current, delay);\n isActiveRef.current = true;\n }, [cleanup, delay]);\n\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n reset();\n return cleanup;\n }, [delay, reset, cleanup]);\n\n return {\n pause,\n resume,\n reset,\n isActive: isActiveRef.current,\n };\n};\n","export const cn = (...classes: (string | undefined)[]) => {\n return classes.filter(Boolean).join(\" \");\n};\n\nexport const generateRandomId = () => Math.floor(Math.random() * 1000000);\n\nexport const prefersReducedMotion = (() => {\n let shouldReduceMotion: boolean | undefined = undefined;\n return () => {\n if (shouldReduceMotion === undefined) {\n if (typeof window !== \"undefined\" && window.matchMedia !== undefined) {\n const mediaQuery = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n );\n shouldReduceMotion = mediaQuery.matches;\n } else {\n shouldReduceMotion = false;\n }\n }\n return shouldReduceMotion;\n };\n})();\n\n// Get system theme:\nexport const getSystemTheme = () => {\n if (typeof window !== \"undefined\") {\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n ? \"t_dark-theme\"\n : \"t_light-theme\";\n }\n return \"t_light-theme\";\n};\n","import type { Position, ToastAnimations, Variant } from \"../types/toast.types\";\n\n/* Default icon colors */\n\nexport const iconsColors: Record<Variant, string> = {\n success: \"#22c55e\",\n error: \"#ef4444\",\n warning: \"#eab308\",\n info: \"#3b82f6\",\n loading: \"currentColor\",\n};\n\n/* Default animations */\n\nconst ANIMATION_ENTER_MAP: Record<Position, string> = {\n \"top-left\": \"t_slide-enter-top\",\n \"top-right\": \"t_slide-enter-top\",\n \"top-center\": \"t_slide-enter-top\",\n \"bottom-left\": \"t_slide-enter-bottom\",\n \"bottom-right\": \"t_slide-enter-bottom\",\n \"bottom-center\": \"t_slide-enter-bottom\",\n};\n\nconst ANIMATION_EXIT_MAP: Record<Position, string> = {\n \"top-left\": \"t-slide-exit-top\",\n \"top-right\": \"t-slide-exit-top\",\n \"top-center\": \"t-slide-exit-top\",\n \"bottom-left\": \"t-slide-exit-bottom\",\n \"bottom-right\": \"t-slide-exit-bottom\",\n \"bottom-center\": \"t-slide-exit-bottom\",\n};\n\n/* Swipe exit animations */\n\nconst ANIMATION_SWIPE_EXIT_MAP: Record<Position, string> = {\n \"top-left\": \"t_swipe-exit-left\",\n \"top-right\": \"t_swipe-exit-right\",\n \"top-center\": \"t_swipe-exit-center\",\n \"bottom-left\": \"t_swipe-exit-left\",\n \"bottom-right\": \"t_swipe-exit-right\",\n \"bottom-center\": \"t_swipe-exit-center\",\n};\n\nexport const getAnimationClass = (\n isExiting: boolean,\n animationType: ToastAnimations,\n position: Position,\n) => {\n if (!isExiting) {\n return ANIMATION_ENTER_MAP[position];\n }\n\n if (animationType === \"swipe\") {\n return ANIMATION_SWIPE_EXIT_MAP[position];\n }\n\n return ANIMATION_EXIT_MAP[position];\n};\n","import type {\n ToastId,\n ToastPropsWithLoading,\n ToastPropsWithVariant\n} from '../types/toast.types';\nimport { openToast, closeToast } from './toaster';\n\ninterface ToastFunctions {\n default: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n success: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n error: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n warning: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n info: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n loading: (data: ToastPropsWithLoading) => ToastPropsWithLoading;\n close: (id: ToastId) => void;\n}\n\nexport const toast: ToastFunctions = {\n default: (data: ToastPropsWithVariant) => {\n openToast({ ...data });\n return data;\n },\n success: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'success' });\n return data;\n },\n error: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'error' });\n return data;\n },\n warning: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'warning' });\n return data;\n },\n info: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'info' });\n return data;\n },\n loading: (data: ToastPropsWithLoading) => {\n openToast({ ...data, variant: 'loading' });\n return data;\n },\n close: (id: ToastId) => closeToast(id)\n};\n"],"mappings":";yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,EAAA,UAAAC,IAAA,eAAAC,EAAAJ,ICCyB,SAARK,EAA6BC,EAAK,CAAE,SAAAC,CAAS,EAAI,CAAC,EAAG,CAC1D,GAAI,CAACD,GAAO,OAAO,SAAa,IAAa,OAE7C,IAAME,EAAO,SAAS,MAAQ,SAAS,qBAAqB,MAAM,EAAE,CAAC,EAC/DC,EAAQ,SAAS,cAAc,OAAO,EAC5CA,EAAM,KAAO,WAETF,IAAa,OACXC,EAAK,WACPA,EAAK,aAAaC,EAAOD,EAAK,UAAU,EAK1CA,EAAK,YAAYC,CAAK,EAGpBA,EAAM,WACRA,EAAM,WAAW,QAAUH,EAE3BG,EAAM,YAAY,SAAS,eAAeH,CAAG,CAAC,CAElD,CCvB8BI,EAAY;AAAA,CAAu6I,ECA39I,IAAAC,EAAoC,iBCQpC,IAAAC,EAAiD,iBCJ7C,IAAAC,EAAA,6BAFSC,EAAsCC,MACjD,OAAC,OAAI,MAAM,6BAA6B,QAAQ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CA,IAAa,eAAiB,iBAAmB,GACjDA,IAAa,gBAAkB,kBAAoB,GACnDE,GAAc,KAAOA,GAAc,KAAO,gBAC5C,EAEC,SAAAE,EAAO,IAAKe,MACX,OAACE,EAAA,CAEC,MAAOpB,EACP,cAAeD,EACf,QAAS,IAAMiB,EAAWE,EAAM,EAAG,EACnC,aAAcjB,EACd,OAAQE,EAAO,QAAQe,CAAK,IAAMf,EAAO,OAAS,EACjD,GAAGe,GANCA,EAAM,EAOb,CACD,EACH,CAGN,EAIaX,EAAaC,GAAsC,CAC1Db,EACFA,EAAgBa,CAAI,EAEpB,QAAQ,MACN,uGACF,CAEJ,EAIaQ,EAAcC,GAAsB,CAC3CrB,EACFA,EAAiBqB,CAAE,EAEnB,QAAQ,MACN,uGACF,CAEJ,EMxHO,IAAMI,EAAwB,CACnC,QAAUC,IACRC,EAAU,CAAE,GAAGD,CAAK,CAAC,EACdA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,MAAQA,IACNC,EAAU,CAAE,GAAGD,EAAM,QAAS,OAAQ,CAAC,EAChCA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,KAAOA,IACLC,EAAU,CAAE,GAAGD,EAAM,QAAS,MAAO,CAAC,EAC/BA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,MAAQE,GAAgBC,EAAWD,CAAE,CACvC","names":["main_exports","__export","Toaster","toast","__toCommonJS","styleInject","css","insertAt","head","style","styleInject","import_react","import_react","import_jsx_runtime","Success","props","Warning","Error","Info","Loading","import_react","useTimeout","callback","delay","timeoutRef","callbackRef","startTimeRef","remainingRef","isActiveRef","cleanup","pause","resume","reset","cn","classes","generateRandomId","prefersReducedMotion","shouldReduceMotion","getSystemTheme","iconsColors","ANIMATION_ENTER_MAP","ANIMATION_EXIT_MAP","ANIMATION_SWIPE_EXIT_MAP","getAnimationClass","isExiting","animationType","position","import_jsx_runtime","Toast","props","status","setStatus","iconColor","setIconColor","iconsColors","toastText","setToastText","isExiting","setIsExiting","delayDuration","pause","resume","useTimeout","handleCloseToast","iconClass","cn","icons","Success","Error","Warning","Info","Loading","IconComponent","prefersReducedMotion","handleMouseLeave","handleMouseEnter","data","error","getAnimationClass","getSystemTheme","toast_default","import_jsx_runtime","openToastGlobal","closeToastGlobal","Toaster","maxToasts","position","theme","toastOptions","htmlProps","toasts","setToasts","isMounted","setIsMounted","openToast","data","newToast","generateRandomId","prevToasts","isTopPosition","isToastUpdate","updatedToasts","pt","closeToast","id","toast","cn","toast_default","toast","data","openToast","id","closeToast"]}
|
|
1
|
+
{"version":3,"sources":["../src/main.tsx","#style-inject:#style-inject","../src/styles/globals.css","../src/components/toaster.tsx","../src/components/toast.tsx","../src/icons/index.tsx","../src/hooks/useTimeout.tsx","../src/utils/index.ts","../src/components/default-options.ts","../src/components/toast-functions.ts"],"sourcesContent":["/* eslint-disable react-refresh/only-export-components */\nimport \"./styles/globals.css\";\n\nexport { toast } from \"./components/toast-functions\";\nexport { Toaster } from \"./components/toaster\";\nexport type {\n ToastPosition as ToastPosition,\n ToastProps as ToastProperties,\n Variant as ToastVariant,\n Theme as ToastTheme,\n ToastOptions,\n ToasterProperties,\n ToastPropsWithLoading,\n ToastPropsWithVariant,\n ToastAnimations,\n} from \"./types/toast.types\";\n","\n export default function styleInject(css, { insertAt } = {}) {\n if (!css || typeof document === 'undefined') return\n \n const head = document.head || document.getElementsByTagName('head')[0]\n const style = document.createElement('style')\n style.type = 'text/css'\n \n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild)\n } else {\n head.appendChild(style)\n }\n } else {\n head.appendChild(style)\n }\n \n if (style.styleSheet) {\n style.styleSheet.cssText = css\n } else {\n style.appendChild(document.createTextNode(css))\n }\n }\n ","import styleInject from '#style-inject';styleInject(\":root{--pheralb-toast-animation-enter: .4s;--pheralb-toast-animation-exit: .4s}:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_light-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_dark-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}@media (prefers-color-scheme: dark){:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}}.t_toasts{display:flex;flex-direction:column;gap:10px;padding:14px;position:fixed;z-index:999;overflow:hidden;transition:max-height .5s ease-in-out;width:100%}.t_default_font{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.t_top-left{top:0;left:0}.t_top-right{top:0;right:0}.t_top-center{top:0;left:50%;transform:translate(-50%)}.t_bottom-left{bottom:0;left:0}.t_bottom-right{bottom:0;right:0}.t_bottom-center{bottom:0;left:50%;transform:translate(-50%)}@media (min-width: 768px){.t_toasts{max-width:355px}}.t_global{display:flex;justify-content:space-between;padding:0;margin:0;list-style:none;outline:none;background-color:var(--background-color);width:auto;box-shadow:0 1px 3px 0 var(--box-shadow),0 1px 2px -1px var(--box-shadow);border:1px solid var(--border-color);border-radius:.375rem;font-size:.875rem;line-height:1.25rem;overflow:hidden}.t_global button{border:none;outline:none}.t_global button:focus{outline:1px solid var(--focus-color);outline-offset:0px;background-color:var(--hover-color)}.t_container{display:flex;flex-direction:row;align-items:center;width:100%;max-width:20rem;height:100wh;gap:.6rem;padding:12px;word-wrap:break-word;overflow-wrap:break-word}.t_icon{fill:var(--text-color);margin-top:.1rem;flex-shrink:0}.t_content{display:flex;flex-direction:column;justify-content:center;max-width:100%}.t_content p{font-weight:600;color:var(--text-color);margin:0}.t_content p:nth-of-type(2){font-weight:400;font-size:.75rem;color:var(--description-color)}.t_actions{display:flex;flex-direction:column;border-left:1px solid var(--border-color);height:100wh}.t_actions>button{flex:1 1 0%;width:100%;padding:6px 20px;font-size:13px;background-color:transparent;cursor:pointer;border:none}.t_actions>button:nth-child(1){color:var(--text-color);font-weight:500}.t_actions>button:nth-child(2){color:var(--text-color);border-top:1px solid var(--border-color)}.t_actions>button:hover{background-color:var(--hover-color)}.t_loading{animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.t_slide-enter-top{animation:slide-top var(--pheralb-toast-animation-enter) ease}@keyframes slide-top{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.t_slide-enter-bottom{animation:slide-bottom var(--pheralb-toast-animation-enter) ease}@keyframes slide-bottom{0%{opacity:0;transform:translateY(100%)}to{opacity:1;transform:translateY(0)}}.t-slide-exit-top,.t-slide-exit-bottom{will-change:transform,opacity}.t-slide-exit-top{animation:slide-top-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-top-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t-slide-exit-bottom{animation:slide-bottom-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-bottom-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(100%)}}.t_swipe-exit-center{animation:swipe-center-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-center-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t_swipe-exit-left{animation:swipe-left-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-left-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100%)}}.t_swipe-exit-right{animation:swipe-right-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-right-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(100%)}}\\n\")","import { useEffect, useState } from \"react\";\n\nimport type {\n ToastId,\n ToastPropsInternal,\n ToastPropsWithVariant,\n ToasterProperties,\n} from \"../types/toast.types\";\n\nimport ToastComponent from \"./toast\";\nimport { cn, generateRandomId } from \"../utils\";\n\n// Ensure openToastGlobal is initialized correctly\nlet openToastGlobal: (data: ToastPropsWithVariant) => void;\n// Ensure closeToastGlobal is initialized correctly\nlet closeToastGlobal: (id: ToastId) => void;\n\nexport const Toaster = ({\n maxToasts = 4,\n position = \"bottom-right\",\n theme = \"system\",\n toastOptions,\n ...htmlProps\n}: ToasterProperties) => {\n const [toasts, setToasts] = useState<ToastPropsInternal[]>([]);\n const [isMounted, setIsMounted] = useState<boolean>(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // Define the openToast function\n const openToast = (data: ToastPropsWithVariant) => {\n const newToast: ToastPropsInternal = {\n _key_: generateRandomId(),\n id: generateRandomId(),\n ...data,\n };\n setToasts((prevToasts) => {\n const isTopPosition =\n position === \"top-left\" ||\n position === \"top-right\" ||\n position === \"top-center\";\n\n // If the `id` exists, update the notification\n let isToastUpdate = false;\n const updatedToasts = prevToasts.map(pt => {\n if (pt.id === newToast.id) {\n isToastUpdate = true;\n return { ...pt, ...newToast, isUpdate: true } satisfies ToastPropsInternal;\n }\n return pt\n })\n\n if (isToastUpdate) {\n // `newToast` is embedded, array preserves length\n return [...updatedToasts]\n }\n\n if (prevToasts.length >= maxToasts) {\n return isTopPosition\n ? [newToast, ...prevToasts.slice(0, -1)]\n : [...prevToasts.slice(1), newToast];\n }\n\n return isTopPosition\n ? [newToast, ...prevToasts]\n : [...prevToasts, newToast];\n });\n };\n\n // Define the closeToast function\n const closeToast = (id: ToastId) => {\n setToasts((prevToasts) => prevToasts.filter((toast) => toast.id !== id));\n };\n\n // Assign openToast to the global variable\n openToastGlobal = openToast;\n // Assign closeToast to the global variable\n closeToastGlobal = closeToast;\n\n // Render the component\n return (\n isMounted &&\n toasts.length > 0 && (\n <section\n {...htmlProps}\n aria-label=\"Toast Notifications\"\n role=\"alert\"\n aria-live=\"polite\"\n className={cn(\n \"t_toasts\",\n position === \"top-left\" ? \"t_top-left\" : \"\",\n position === \"top-right\" ? \"t_top-right\" : \"\",\n position === \"top-center\" ? \"t_top-center\" : \"\",\n position === \"bottom-left\" ? \"t_bottom-left\" : \"\",\n position === \"bottom-right\" ? \"t_bottom-right\" : \"\",\n position === \"bottom-center\" ? \"t_bottom-center\" : \"\",\n toastOptions?.font ? toastOptions?.font : \"t_default_font\",\n )}\n >\n {toasts.map((toast) => (\n <ToastComponent\n key={toast._key_}\n theme={theme}\n toastPosition={position}\n onClose={() => closeToast(toast.id!)}\n toastOptions={toastOptions}\n active={toasts.indexOf(toast) === toasts.length - 1}\n {...toast}\n />\n ))}\n </section>\n )\n );\n};\n\n// Export the openToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const openToast = (data: ToastPropsWithVariant): void => {\n if (openToastGlobal) {\n openToastGlobal(data);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n\n// Export the closeToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const closeToast = (id: ToastId): void => {\n if (closeToastGlobal) {\n closeToastGlobal(id);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n","import type {\n ToastPosition,\n ToastIcons,\n ToastOptions,\n ToastPropsWithLoading,\n Variant,\n ToastPropsInternal,\n} from \"../types/toast.types\";\n\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { Error, Info, Loading, Success, Warning } from \"../icons\";\nimport { useTimeout } from \"../hooks/useTimeout\";\nimport { cn, getSystemTheme, prefersReducedMotion } from \"../utils\";\n\nimport { iconsColors, getAnimationClass } from \"./default-options\";\n\ntype ToastComponentProps = ToastPropsInternal &\n Pick<ToastPropsWithLoading, 'options'> &\n{\n toastPosition: ToastPosition;\n toastOptions?: ToastOptions;\n active?: boolean;\n onClose: () => void;\n};\n\nconst DEFAULT_DURATION = 4000;\n\nconst Toast = (props: ToastComponentProps) => {\n const [status, setStatus] = useState<Variant>(props.variant || \"info\");\n const [iconColor, setIconColor] = useState<string>(iconsColors[status]);\n const [toastText, setToastText] = useState<string>(props.text);\n const [isExiting, setIsExiting] = useState<boolean>(false);\n\n const delayDuration = props.delayDuration || DEFAULT_DURATION;\n\n const { pause, resume } = useTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n\n const iconClass = cn(\n \"t_icon\",\n props.variant === \"loading\" && status === \"loading\" ? \"t_loading\" : \"\",\n );\n\n const icons: ToastIcons = {\n success: (\n <Success\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n error: (\n <Error\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n warning: (\n <Warning\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n info: (\n <Info\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n loading: (\n <Loading\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n };\n\n const IconComponent = props.toastOptions?.icons\n ? props.toastOptions?.icons[status]\n : icons[status];\n\n const handleCloseToast = useCallback(() => {\n setIsExiting(true);\n const animationDisabled = prefersReducedMotion();\n if (!animationDisabled) {\n setTimeout(() => {\n if (props.onClose) {\n props.onClose();\n }\n }, 300);\n } else if (props.onClose) {\n props.onClose();\n }\n }, [props]);\n\n const handleMouseLeave = () => {\n resume();\n };\n\n const handleMouseEnter = () => {\n pause();\n };\n\n useEffect(() => {\n if (props.variant === \"loading\" && props.options) {\n pause();\n\n const executePromise =\n typeof props.options.promise === \"function\"\n ? props.options.promise()\n : Promise.resolve(props.options.promise);\n\n executePromise\n .then((data) => {\n resume();\n setStatus(\"success\");\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n setToastText(props.options!.success);\n setIconColor(iconsColors.success);\n if (props.options?.onSuccess) {\n props.options.onSuccess(data, props.id!);\n }\n })\n .catch((error) => {\n setStatus(\"error\");\n setToastText(props.options!.error);\n setIconColor(iconsColors.error);\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n if (props.options?.onError) {\n props.options.onError(error, props.id!);\n }\n });\n }\n }, [delayDuration, handleCloseToast, pause, props.id, props.options, props.variant, resume]);\n\n return (\n <div\n {...props.attrs}\n role=\"alert\"\n aria-labelledby={`toast-title-${props.id}`}\n aria-describedby={`toast-description-${props.id}`}\n title={props.text}\n className={cn(\n prefersReducedMotion() || props.isUpdate\n ? \"\"\n : getAnimationClass(\n isExiting,\n props.toastOptions?.animationOnClose || \"slide\",\n props.toastPosition,\n ),\n !props.toastOptions?.headless && props.theme === \"system\"\n ? getSystemTheme()\n : \"\",\n !props.toastOptions?.headless && props.theme === \"dark\"\n ? \"t_dark-theme\"\n : \"\",\n !props.toastOptions?.headless && props.theme === \"light\"\n ? \"t_light-theme\"\n : \"\",\n !props.toastOptions?.headless ? \"t_global\" : \"\",\n props.toastOptions?.classNames?.toast,\n props.attrs?.className,\n )}\n style={{\n zIndex: props.active ? 1000 : 999,\n ...props.attrs?.style,\n }}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleMouseEnter}\n onBlur={handleMouseLeave}\n >\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_container\" : \"\",\n props.toastOptions?.classNames?.container,\n )}\n >\n {props.variant && !props.icon ? (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {IconComponent}\n </div>\n ) : (\n props.icon && (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {props.icon}\n </div>\n )\n )}\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_content\" : \"\",\n props.toastOptions?.classNames?.content,\n )}\n >\n <p id={`toast-title-${props.id}`}>{toastText}</p>\n {props.description && (\n <p id={`toast-description-${props.id}`}>{props.description}</p>\n )}\n </div>\n </div>\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_actions\" : \"\",\n props.toastOptions?.classNames?.actions?.container,\n )}\n >\n {props.action && (\n <button\n onClick={props.action.onClick}\n title={\n typeof props.action.content === \"string\"\n ? props.action.content\n : \"Action Button\"\n }\n className={cn(props.toastOptions?.classNames?.actions?.actionBtn)}\n >\n {props.action.content ??\n props.toastOptions?.defaultActionContent ??\n \"Action\"}\n </button>\n )}\n <button\n onClick={handleCloseToast}\n title=\"Close toast\"\n className={cn(props.toastOptions?.classNames?.actions?.closeBtn)}\n >\n {props.toastOptions?.defaultCloseContent ?? \"Close\"}\n </button>\n </div>\n </div>\n );\n};\n\nexport default Toast;\n","import type { ComponentProps, FC } from \"react\";\n\nexport const Success: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z\"></path>\n </svg>\n);\n\nexport const Warning: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Error: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Info: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z\"></path>\n </svg>\n);\n\nexport const Loading: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M136 32v32a8 8 0 01-16 0V32a8 8 0 0116 0zm37.25 58.75a8 8 0 005.66-2.35l22.63-22.62a8 8 0 00-11.32-11.32L167.6 77.09a8 8 0 005.65 13.66zM224 120h-32a8 8 0 000 16h32a8 8 0 000-16zm-45.09 47.6a8 8 0 00-11.31 11.31l22.62 22.63a8 8 0 0011.32-11.32zM128 184a8 8 0 00-8 8v32a8 8 0 0016 0v-32a8 8 0 00-8-8zm-50.91-16.4l-22.63 22.62a8 8 0 0011.32 11.32l22.62-22.63a8 8 0 00-11.31-11.31zM72 128a8 8 0 00-8-8H32a8 8 0 000 16h32a8 8 0 008-8zm-6.22-73.54a8 8 0 00-11.32 11.32L77.09 88.4A8 8 0 0088.4 77.09z\"></path>\n </svg>\n);\n","import { useCallback, useEffect, useRef } from \"react\";\n\ninterface UseTimeoutReturn {\n pause: () => void;\n resume: () => void;\n reset: () => void;\n isActive: boolean;\n}\n\nexport const useTimeout = (\n callback: () => void,\n delay: number,\n): UseTimeoutReturn => {\n const timeoutRef = useRef<number>(0);\n const callbackRef = useRef(callback);\n const startTimeRef = useRef<number>(0);\n const remainingRef = useRef(delay);\n const isActiveRef = useRef(true);\n\n const cleanup = useCallback(() => {\n if (timeoutRef.current) {\n window.clearTimeout(timeoutRef.current);\n }\n }, []);\n\n const pause = useCallback(() => {\n if (!isActiveRef.current || !startTimeRef.current) return;\n\n cleanup();\n remainingRef.current -= Date.now() - startTimeRef.current;\n isActiveRef.current = false;\n }, [cleanup]);\n\n const resume = useCallback(() => {\n if (isActiveRef.current) return;\n\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(\n callbackRef.current,\n remainingRef.current,\n );\n isActiveRef.current = true;\n }, []);\n\n const reset = useCallback(() => {\n cleanup();\n remainingRef.current = delay;\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(callbackRef.current, delay);\n isActiveRef.current = true;\n }, [cleanup, delay]);\n\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n reset();\n return cleanup;\n }, [delay, reset, cleanup]);\n\n return {\n pause,\n resume,\n reset,\n isActive: isActiveRef.current,\n };\n};\n","export const cn = (...classes: (string | undefined)[]) => {\n return classes.filter(Boolean).join(\" \");\n};\n\nexport const generateRandomId = () =>\n Math.random().toString(16).slice(2, 10);\n\nexport const prefersReducedMotion = (() => {\n let shouldReduceMotion: boolean | undefined = undefined;\n return () => {\n if (shouldReduceMotion === undefined) {\n if (typeof window !== \"undefined\" && window.matchMedia !== undefined) {\n const mediaQuery = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n );\n shouldReduceMotion = mediaQuery.matches;\n } else {\n shouldReduceMotion = false;\n }\n }\n return shouldReduceMotion;\n };\n})();\n\n// Get system theme:\nexport const getSystemTheme = () => {\n if (typeof window !== \"undefined\") {\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n ? \"t_dark-theme\"\n : \"t_light-theme\";\n }\n return \"t_light-theme\";\n};\n","import type { ToastPosition, ToastAnimations, Variant } from \"../types/toast.types\";\n\n/* Default icon colors */\n\nexport const iconsColors: Record<Variant, string> = {\n success: \"#22c55e\",\n error: \"#ef4444\",\n warning: \"#eab308\",\n info: \"#3b82f6\",\n loading: \"currentColor\",\n};\n\n/* Default animations */\n\nconst ANIMATION_ENTER_MAP: Record<ToastPosition, string> = {\n \"top-left\": \"t_slide-enter-top\",\n \"top-right\": \"t_slide-enter-top\",\n \"top-center\": \"t_slide-enter-top\",\n \"bottom-left\": \"t_slide-enter-bottom\",\n \"bottom-right\": \"t_slide-enter-bottom\",\n \"bottom-center\": \"t_slide-enter-bottom\",\n};\n\nconst ANIMATION_EXIT_MAP: Record<ToastPosition, string> = {\n \"top-left\": \"t-slide-exit-top\",\n \"top-right\": \"t-slide-exit-top\",\n \"top-center\": \"t-slide-exit-top\",\n \"bottom-left\": \"t-slide-exit-bottom\",\n \"bottom-right\": \"t-slide-exit-bottom\",\n \"bottom-center\": \"t-slide-exit-bottom\",\n};\n\n/* Swipe exit animations */\n\nconst ANIMATION_SWIPE_EXIT_MAP: Record<ToastPosition, string> = {\n \"top-left\": \"t_swipe-exit-left\",\n \"top-right\": \"t_swipe-exit-right\",\n \"top-center\": \"t_swipe-exit-center\",\n \"bottom-left\": \"t_swipe-exit-left\",\n \"bottom-right\": \"t_swipe-exit-right\",\n \"bottom-center\": \"t_swipe-exit-center\",\n};\n\nexport const getAnimationClass = (\n isExiting: boolean,\n animationType: ToastAnimations,\n position: ToastPosition,\n) => {\n if (!isExiting) {\n return ANIMATION_ENTER_MAP[position];\n }\n\n if (animationType === \"swipe\") {\n return ANIMATION_SWIPE_EXIT_MAP[position];\n }\n\n return ANIMATION_EXIT_MAP[position];\n};\n","import type {\n ToastId,\n ToastPropsWithLoading,\n ToastPropsWithVariant\n} from '../types/toast.types';\nimport { openToast, closeToast } from './toaster';\n\ninterface ToastFunctions {\n default: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n success: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n error: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n warning: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n info: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n loading: <T = unknown>(data: ToastPropsWithLoading<T>) => ToastPropsWithLoading<T>;\n close: (id: ToastId) => void;\n}\n\nexport const toast: ToastFunctions = {\n default: (data: ToastPropsWithVariant) => {\n openToast({ ...data });\n return data;\n },\n success: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'success' });\n return data;\n },\n error: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'error' });\n return data;\n },\n warning: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'warning' });\n return data;\n },\n info: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'info' });\n return data;\n },\n loading: <T = unknown>(data: ToastPropsWithLoading<T>) => {\n openToast({ ...data, variant: 'loading' });\n return data;\n },\n close: (id: ToastId) => closeToast(id)\n};\n"],"mappings":";yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,EAAA,UAAAC,IAAA,eAAAC,EAAAJ,ICCyB,SAARK,EAA6BC,EAAK,CAAE,SAAAC,CAAS,EAAI,CAAC,EAAG,CAC1D,GAAI,CAACD,GAAO,OAAO,SAAa,IAAa,OAE7C,IAAME,EAAO,SAAS,MAAQ,SAAS,qBAAqB,MAAM,EAAE,CAAC,EAC/DC,EAAQ,SAAS,cAAc,OAAO,EAC5CA,EAAM,KAAO,WAETF,IAAa,OACXC,EAAK,WACPA,EAAK,aAAaC,EAAOD,EAAK,UAAU,EAK1CA,EAAK,YAAYC,CAAK,EAGpBA,EAAM,WACRA,EAAM,WAAW,QAAUH,EAE3BG,EAAM,YAAY,SAAS,eAAeH,CAAG,CAAC,CAElD,CCvB8BI,EAAY;AAAA,CAAu6I,ECA39I,IAAAC,EAAoC,iBCSpC,IAA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GACAF,EAAO,OAAS,MACd,OAAC,WACE,GAAGD,EACJ,aAAW,sBACX,KAAK,QACL,YAAU,SACV,UAAWiB,EACT,WACApB,IAAa,WAAa,aAAe,GACzCA,IAAa,YAAc,cAAgB,GAC3CA,IAAa,aAAe,eAAiB,GAC7CA,IAAa,cAAgB,gBAAkB,GAC/CA,IAAa,eAAiB,iBAAmB,GACjDA,IAAa,gBAAkB,kBAAoB,GACnDE,GAAc,KAAOA,GAAc,KAAO,gBAC5C,EAEC,SAAAE,EAAO,IAAKe,MACX,OAACE,EAAA,CAEC,MAAOpB,EACP,cAAeD,EACf,QAAS,IAAMiB,EAAWE,EAAM,EAAG,EACnC,aAAcjB,EACd,OAAQE,EAAO,QAAQe,CAAK,IAAMf,EAAO,OAAS,EACjD,GAAGe,GANCA,EAAM,KAOb,CACD,EACH,CAGN,EAIaX,EAAaC,GAAsC,CAC1Db,EACFA,EAAgBa,CAAI,EAEpB,QAAQ,MACN,uGACF,CAEJ,EAIaQ,EAAcC,GAAsB,CAC3CrB,EACFA,EAAiBqB,CAAE,EAEnB,QAAQ,MACN,uGACF,CAEJ,EM1HO,IAAMI,EAAwB,CACnC,QAAUC,IACRC,EAAU,CAAE,GAAGD,CAAK,CAAC,EACdA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,MAAQA,IACNC,EAAU,CAAE,GAAGD,EAAM,QAAS,OAAQ,CAAC,EAChCA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,KAAOA,IACLC,EAAU,CAAE,GAAGD,EAAM,QAAS,MAAO,CAAC,EAC/BA,GAET,QAAuBA,IACrBC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,MAAQE,GAAgBC,EAAWD,CAAE,CACvC","names":["main_exports","__export","Toaster","toast","__toCommonJS","styleInject","css","insertAt","head","style","styleInject","import_react","import_react","import_jsx_runtime","Success","props","Warning","Error","Info","Loading","import_react","useTimeout","callback","delay","timeoutRef","callbackRef","startTimeRef","remainingRef","isActiveRef","cleanup","pause","resume","reset","cn","classes","generateRandomId","prefersReducedMotion","shouldReduceMotion","getSystemTheme","iconsColors","ANIMATION_ENTER_MAP","ANIMATION_EXIT_MAP","ANIMATION_SWIPE_EXIT_MAP","getAnimationClass","isExiting","animationType","position","import_jsx_runtime","DEFAULT_DURATION","Toast","props","status","setStatus","iconColor","setIconColor","iconsColors","toastText","setToastText","isExiting","setIsExiting","delayDuration","pause","resume","useTimeout","handleCloseToast","iconClass","cn","icons","Success","Error","Warning","Info","Loading","IconComponent","prefersReducedMotion","handleMouseLeave","handleMouseEnter","data","error","getAnimationClass","getSystemTheme","toast_default","import_jsx_runtime","openToastGlobal","closeToastGlobal","Toaster","maxToasts","position","theme","toastOptions","htmlProps","toasts","setToasts","isMounted","setIsMounted","openToast","data","newToast","generateRandomId","prevToasts","isTopPosition","isToastUpdate","updatedToasts","pt","closeToast","id","toast","cn","toast_default","toast","data","openToast","id","closeToast"]}
|
package/dist/main.d.cts
CHANGED
|
@@ -2,12 +2,12 @@ import { ReactNode, HTMLProps } from 'react';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
type Variant = "success" | "error" | "warning" | "info" | "loading";
|
|
5
|
-
type
|
|
5
|
+
type ToastPosition = "top-left" | "top-right" | "top-center" | "bottom-left" | "bottom-right" | "bottom-center";
|
|
6
6
|
type Theme = "light" | "dark" | "system";
|
|
7
|
-
|
|
7
|
+
type ToastAction = {
|
|
8
8
|
content?: string | ReactNode;
|
|
9
9
|
onClick: () => void | (() => Promise<void>);
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
type ToastIcons = Record<Variant, ReactNode>;
|
|
12
12
|
type ToastId = number | string;
|
|
13
13
|
type ToastProps = {
|
|
@@ -21,32 +21,32 @@ type ToastProps = {
|
|
|
21
21
|
icon?: ReactNode;
|
|
22
22
|
delayDuration?: number;
|
|
23
23
|
theme?: Theme;
|
|
24
|
-
action?:
|
|
24
|
+
action?: ToastAction;
|
|
25
25
|
/**
|
|
26
26
|
* Set any HTML Attributes to the notification
|
|
27
27
|
*/
|
|
28
28
|
attrs?: HTMLProps<HTMLDivElement>;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
type ToastLoadingType<T = unknown> = {
|
|
31
31
|
promise: (() => Promise<T>) | Promise<T>;
|
|
32
32
|
success: string;
|
|
33
33
|
error: string;
|
|
34
34
|
autoDismiss: boolean;
|
|
35
|
-
onSuccess?: (data: T) => void;
|
|
36
|
-
onError?: (error: Error, id
|
|
37
|
-
}
|
|
38
|
-
|
|
35
|
+
onSuccess?: (data: T, id: ToastId) => void;
|
|
36
|
+
onError?: (error: Error, id: ToastId) => void;
|
|
37
|
+
};
|
|
38
|
+
type ToastActionsCustomClassnames = {
|
|
39
39
|
container: string;
|
|
40
40
|
closeBtn: string;
|
|
41
41
|
actionBtn: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
42
|
+
};
|
|
43
|
+
type ToastClassnames = {
|
|
44
44
|
toast?: string;
|
|
45
45
|
container?: string;
|
|
46
46
|
icon?: string;
|
|
47
47
|
content?: string;
|
|
48
48
|
actions?: ToastActionsCustomClassnames;
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
50
|
type ToastAnimations = "slide" | "swipe";
|
|
51
51
|
type ToastOptions = {
|
|
52
52
|
animationOnClose?: ToastAnimations;
|
|
@@ -61,15 +61,15 @@ type ToasterHTMLElementProperties = Omit<HTMLProps<HTMLElement>, 'aria-role' | '
|
|
|
61
61
|
type ToasterProperties = ToasterHTMLElementProperties & {
|
|
62
62
|
theme?: Theme;
|
|
63
63
|
maxToasts?: number;
|
|
64
|
-
position?:
|
|
64
|
+
position?: ToastPosition;
|
|
65
65
|
toastOptions?: ToastOptions;
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
type ToastPropsWithVariant = ToastProps & {
|
|
68
68
|
variant?: Variant;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
options?:
|
|
72
|
-
}
|
|
69
|
+
};
|
|
70
|
+
type ToastPropsWithLoading<T = unknown> = ToastPropsWithVariant & {
|
|
71
|
+
options?: ToastLoadingType<T>;
|
|
72
|
+
};
|
|
73
73
|
|
|
74
74
|
interface ToastFunctions {
|
|
75
75
|
default: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
@@ -77,11 +77,11 @@ interface ToastFunctions {
|
|
|
77
77
|
error: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
78
78
|
warning: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
79
79
|
info: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
80
|
-
loading: (data: ToastPropsWithLoading) => ToastPropsWithLoading
|
|
80
|
+
loading: <T = unknown>(data: ToastPropsWithLoading<T>) => ToastPropsWithLoading<T>;
|
|
81
81
|
close: (id: ToastId) => void;
|
|
82
82
|
}
|
|
83
83
|
declare const toast: ToastFunctions;
|
|
84
84
|
|
|
85
85
|
declare const Toaster: ({ maxToasts, position, theme, toastOptions, ...htmlProps }: ToasterProperties) => false | react_jsx_runtime.JSX.Element;
|
|
86
86
|
|
|
87
|
-
export { type ToastAnimations, type ToastOptions, type
|
|
87
|
+
export { type ToastAnimations, type ToastOptions, type ToastPosition, type ToastProps as ToastProperties, type ToastPropsWithLoading, type ToastPropsWithVariant, type Theme as ToastTheme, type Variant as ToastVariant, Toaster, type ToasterProperties, toast };
|
package/dist/main.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { ReactNode, HTMLProps } from 'react';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
type Variant = "success" | "error" | "warning" | "info" | "loading";
|
|
5
|
-
type
|
|
5
|
+
type ToastPosition = "top-left" | "top-right" | "top-center" | "bottom-left" | "bottom-right" | "bottom-center";
|
|
6
6
|
type Theme = "light" | "dark" | "system";
|
|
7
|
-
|
|
7
|
+
type ToastAction = {
|
|
8
8
|
content?: string | ReactNode;
|
|
9
9
|
onClick: () => void | (() => Promise<void>);
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
type ToastIcons = Record<Variant, ReactNode>;
|
|
12
12
|
type ToastId = number | string;
|
|
13
13
|
type ToastProps = {
|
|
@@ -21,32 +21,32 @@ type ToastProps = {
|
|
|
21
21
|
icon?: ReactNode;
|
|
22
22
|
delayDuration?: number;
|
|
23
23
|
theme?: Theme;
|
|
24
|
-
action?:
|
|
24
|
+
action?: ToastAction;
|
|
25
25
|
/**
|
|
26
26
|
* Set any HTML Attributes to the notification
|
|
27
27
|
*/
|
|
28
28
|
attrs?: HTMLProps<HTMLDivElement>;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
type ToastLoadingType<T = unknown> = {
|
|
31
31
|
promise: (() => Promise<T>) | Promise<T>;
|
|
32
32
|
success: string;
|
|
33
33
|
error: string;
|
|
34
34
|
autoDismiss: boolean;
|
|
35
|
-
onSuccess?: (data: T) => void;
|
|
36
|
-
onError?: (error: Error, id
|
|
37
|
-
}
|
|
38
|
-
|
|
35
|
+
onSuccess?: (data: T, id: ToastId) => void;
|
|
36
|
+
onError?: (error: Error, id: ToastId) => void;
|
|
37
|
+
};
|
|
38
|
+
type ToastActionsCustomClassnames = {
|
|
39
39
|
container: string;
|
|
40
40
|
closeBtn: string;
|
|
41
41
|
actionBtn: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
42
|
+
};
|
|
43
|
+
type ToastClassnames = {
|
|
44
44
|
toast?: string;
|
|
45
45
|
container?: string;
|
|
46
46
|
icon?: string;
|
|
47
47
|
content?: string;
|
|
48
48
|
actions?: ToastActionsCustomClassnames;
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
50
|
type ToastAnimations = "slide" | "swipe";
|
|
51
51
|
type ToastOptions = {
|
|
52
52
|
animationOnClose?: ToastAnimations;
|
|
@@ -61,15 +61,15 @@ type ToasterHTMLElementProperties = Omit<HTMLProps<HTMLElement>, 'aria-role' | '
|
|
|
61
61
|
type ToasterProperties = ToasterHTMLElementProperties & {
|
|
62
62
|
theme?: Theme;
|
|
63
63
|
maxToasts?: number;
|
|
64
|
-
position?:
|
|
64
|
+
position?: ToastPosition;
|
|
65
65
|
toastOptions?: ToastOptions;
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
type ToastPropsWithVariant = ToastProps & {
|
|
68
68
|
variant?: Variant;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
options?:
|
|
72
|
-
}
|
|
69
|
+
};
|
|
70
|
+
type ToastPropsWithLoading<T = unknown> = ToastPropsWithVariant & {
|
|
71
|
+
options?: ToastLoadingType<T>;
|
|
72
|
+
};
|
|
73
73
|
|
|
74
74
|
interface ToastFunctions {
|
|
75
75
|
default: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
@@ -77,11 +77,11 @@ interface ToastFunctions {
|
|
|
77
77
|
error: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
78
78
|
warning: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
79
79
|
info: (data: ToastPropsWithVariant) => ToastPropsWithVariant;
|
|
80
|
-
loading: (data: ToastPropsWithLoading) => ToastPropsWithLoading
|
|
80
|
+
loading: <T = unknown>(data: ToastPropsWithLoading<T>) => ToastPropsWithLoading<T>;
|
|
81
81
|
close: (id: ToastId) => void;
|
|
82
82
|
}
|
|
83
83
|
declare const toast: ToastFunctions;
|
|
84
84
|
|
|
85
85
|
declare const Toaster: ({ maxToasts, position, theme, toastOptions, ...htmlProps }: ToasterProperties) => false | react_jsx_runtime.JSX.Element;
|
|
86
86
|
|
|
87
|
-
export { type ToastAnimations, type ToastOptions, type
|
|
87
|
+
export { type ToastAnimations, type ToastOptions, type ToastPosition, type ToastProps as ToastProperties, type ToastPropsWithLoading, type ToastPropsWithVariant, type Theme as ToastTheme, type Variant as ToastVariant, Toaster, type ToasterProperties, toast };
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use client"
|
|
2
|
-
function
|
|
3
|
-
`);import{useEffect as
|
|
2
|
+
function N(t,{insertAt:o}={}){if(!t||typeof document>"u")return;let a=document.head||document.getElementsByTagName("head")[0],e=document.createElement("style");e.type="text/css",o==="top"&&a.firstChild?a.insertBefore(e,a.firstChild):a.appendChild(e),e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}N(`:root{--pheralb-toast-animation-enter: .4s;--pheralb-toast-animation-exit: .4s}:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_light-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_dark-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}@media (prefers-color-scheme: dark){:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}}.t_toasts{display:flex;flex-direction:column;gap:10px;padding:14px;position:fixed;z-index:999;overflow:hidden;transition:max-height .5s ease-in-out;width:100%}.t_default_font{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.t_top-left{top:0;left:0}.t_top-right{top:0;right:0}.t_top-center{top:0;left:50%;transform:translate(-50%)}.t_bottom-left{bottom:0;left:0}.t_bottom-right{bottom:0;right:0}.t_bottom-center{bottom:0;left:50%;transform:translate(-50%)}@media (min-width: 768px){.t_toasts{max-width:355px}}.t_global{display:flex;justify-content:space-between;padding:0;margin:0;list-style:none;outline:none;background-color:var(--background-color);width:auto;box-shadow:0 1px 3px 0 var(--box-shadow),0 1px 2px -1px var(--box-shadow);border:1px solid var(--border-color);border-radius:.375rem;font-size:.875rem;line-height:1.25rem;overflow:hidden}.t_global button{border:none;outline:none}.t_global button:focus{outline:1px solid var(--focus-color);outline-offset:0px;background-color:var(--hover-color)}.t_container{display:flex;flex-direction:row;align-items:center;width:100%;max-width:20rem;height:100wh;gap:.6rem;padding:12px;word-wrap:break-word;overflow-wrap:break-word}.t_icon{fill:var(--text-color);margin-top:.1rem;flex-shrink:0}.t_content{display:flex;flex-direction:column;justify-content:center;max-width:100%}.t_content p{font-weight:600;color:var(--text-color);margin:0}.t_content p:nth-of-type(2){font-weight:400;font-size:.75rem;color:var(--description-color)}.t_actions{display:flex;flex-direction:column;border-left:1px solid var(--border-color);height:100wh}.t_actions>button{flex:1 1 0%;width:100%;padding:6px 20px;font-size:13px;background-color:transparent;cursor:pointer;border:none}.t_actions>button:nth-child(1){color:var(--text-color);font-weight:500}.t_actions>button:nth-child(2){color:var(--text-color);border-top:1px solid var(--border-color)}.t_actions>button:hover{background-color:var(--hover-color)}.t_loading{animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.t_slide-enter-top{animation:slide-top var(--pheralb-toast-animation-enter) ease}@keyframes slide-top{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.t_slide-enter-bottom{animation:slide-bottom var(--pheralb-toast-animation-enter) ease}@keyframes slide-bottom{0%{opacity:0;transform:translateY(100%)}to{opacity:1;transform:translateY(0)}}.t-slide-exit-top,.t-slide-exit-bottom{will-change:transform,opacity}.t-slide-exit-top{animation:slide-top-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-top-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t-slide-exit-bottom{animation:slide-bottom-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-bottom-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(100%)}}.t_swipe-exit-center{animation:swipe-center-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-center-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t_swipe-exit-left{animation:swipe-left-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-left-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100%)}}.t_swipe-exit-right{animation:swipe-right-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-right-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(100%)}}
|
|
3
|
+
`);import{useEffect as tt,useState as Y}from"react";import{useCallback as q,useEffect as J,useState as C}from"react";import{jsx as h}from"react/jsx-runtime";var V=t=>h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:h("path",{d:"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z"})}),z=t=>h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:h("path",{d:"M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z"})}),E=t=>h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:h("path",{d:"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z"})}),R=t=>h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:h("path",{d:"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z"})}),S=t=>h("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",...t,children:h("path",{d:"M136 32v32a8 8 0 01-16 0V32a8 8 0 0116 0zm37.25 58.75a8 8 0 005.66-2.35l22.63-22.62a8 8 0 00-11.32-11.32L167.6 77.09a8 8 0 005.65 13.66zM224 120h-32a8 8 0 000 16h32a8 8 0 000-16zm-45.09 47.6a8 8 0 00-11.31 11.31l22.62 22.63a8 8 0 0011.32-11.32zM128 184a8 8 0 00-8 8v32a8 8 0 0016 0v-32a8 8 0 00-8-8zm-50.91-16.4l-22.63 22.62a8 8 0 0011.32 11.32l22.62-22.63a8 8 0 00-11.31-11.31zM72 128a8 8 0 00-8-8H32a8 8 0 000 16h32a8 8 0 008-8zm-6.22-73.54a8 8 0 00-11.32 11.32L77.09 88.4A8 8 0 0088.4 77.09z"})});import{useCallback as _,useEffect as L,useRef as w}from"react";var B=(t,o)=>{let a=w(0),e=w(t),u=w(0),c=w(o),s=w(!0),d=_(()=>{a.current&&window.clearTimeout(a.current)},[]),T=_(()=>{!s.current||!u.current||(d(),c.current-=Date.now()-u.current,s.current=!1)},[d]),p=_(()=>{s.current||(u.current=Date.now(),a.current=window.setTimeout(e.current,c.current),s.current=!0)},[]),m=_(()=>{d(),c.current=o,u.current=Date.now(),a.current=window.setTimeout(e.current,o),s.current=!0},[d,o]);return L(()=>{e.current=t},[t]),L(()=>(m(),d),[o,m,d]),{pause:T,resume:p,reset:m,isActive:s.current}};var r=(...t)=>t.filter(Boolean).join(" "),O=()=>Math.random().toString(16).slice(2,10),W=(()=>{let t;return()=>(t===void 0&&(typeof window<"u"&&window.matchMedia!==void 0?t=window.matchMedia("(prefers-reduced-motion: reduce)").matches:t=!1),t)})(),D=()=>typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"t_dark-theme":"t_light-theme";var P={success:"#22c55e",error:"#ef4444",warning:"#eab308",info:"#3b82f6",loading:"currentColor"},H={"top-left":"t_slide-enter-top","top-right":"t_slide-enter-top","top-center":"t_slide-enter-top","bottom-left":"t_slide-enter-bottom","bottom-right":"t_slide-enter-bottom","bottom-center":"t_slide-enter-bottom"},Q={"top-left":"t-slide-exit-top","top-right":"t-slide-exit-top","top-center":"t-slide-exit-top","bottom-left":"t-slide-exit-bottom","bottom-right":"t-slide-exit-bottom","bottom-center":"t-slide-exit-bottom"},X={"top-left":"t_swipe-exit-left","top-right":"t_swipe-exit-right","top-center":"t_swipe-exit-center","bottom-left":"t_swipe-exit-left","bottom-right":"t_swipe-exit-right","bottom-center":"t_swipe-exit-center"},F=(t,o,a)=>t?o==="swipe"?X[a]:Q[a]:H[a];import{jsx as l,jsxs as k}from"react/jsx-runtime";var K=4e3,Z=t=>{let[o,a]=C(t.variant||"info"),[e,u]=C(P[o]),[c,s]=C(t.text),[d,T]=C(!1),p=t.delayDuration||K,{pause:m,resume:i}=B(()=>{g()},p),n=r("t_icon",t.variant==="loading"&&o==="loading"?"t_loading":""),f={success:l(V,{width:18,height:18,style:{fill:e},className:n}),error:l(E,{width:18,height:18,style:{fill:e},className:n}),warning:l(z,{width:18,height:18,style:{fill:e},className:n}),info:l(R,{width:18,height:18,style:{fill:e},className:n}),loading:l(S,{width:18,height:18,style:{fill:e},className:n})},v=t.toastOptions?.icons?t.toastOptions?.icons[o]:f[o],g=q(()=>{T(!0),W()?t.onClose&&t.onClose():setTimeout(()=>{t.onClose&&t.onClose()},300)},[t]),y=()=>{i()},b=()=>{m()};return J(()=>{t.variant==="loading"&&t.options&&(m(),(typeof t.options.promise=="function"?t.options.promise():Promise.resolve(t.options.promise)).then(I=>{i(),a("success"),t.options.autoDismiss&&setTimeout(()=>{g()},p),s(t.options.success),u(P.success),t.options?.onSuccess&&t.options.onSuccess(I,t.id)}).catch(I=>{a("error"),s(t.options.error),u(P.error),t.options.autoDismiss&&setTimeout(()=>{g()},p),t.options?.onError&&t.options.onError(I,t.id)}))},[p,g,m,t.id,t.options,t.variant,i]),k("div",{...t.attrs,role:"alert","aria-labelledby":`toast-title-${t.id}`,"aria-describedby":`toast-description-${t.id}`,title:t.text,className:r(W()||t.isUpdate?"":F(d,t.toastOptions?.animationOnClose||"slide",t.toastPosition),!t.toastOptions?.headless&&t.theme==="system"?D():"",!t.toastOptions?.headless&&t.theme==="dark"?"t_dark-theme":"",!t.toastOptions?.headless&&t.theme==="light"?"t_light-theme":"",t.toastOptions?.headless?"":"t_global",t.toastOptions?.classNames?.toast,t.attrs?.className),style:{zIndex:t.active?1e3:999,...t.attrs?.style},onMouseEnter:b,onMouseLeave:y,onFocus:b,onBlur:y,children:[k("div",{className:r(t.toastOptions?.headless?"":"t_container",t.toastOptions?.classNames?.container),children:[t.variant&&!t.icon?l("div",{className:r(t.toastOptions?.headless?"":"t_icon",t.toastOptions?.classNames?.icon),children:v}):t.icon&&l("div",{className:r(t.toastOptions?.headless?"":"t_icon",t.toastOptions?.classNames?.icon),children:t.icon}),k("div",{className:r(t.toastOptions?.headless?"":"t_content",t.toastOptions?.classNames?.content),children:[l("p",{id:`toast-title-${t.id}`,children:c}),t.description&&l("p",{id:`toast-description-${t.id}`,children:t.description})]})]}),k("div",{className:r(t.toastOptions?.headless?"":"t_actions",t.toastOptions?.classNames?.actions?.container),children:[t.action&&l("button",{onClick:t.action.onClick,title:typeof t.action.content=="string"?t.action.content:"Action Button",className:r(t.toastOptions?.classNames?.actions?.actionBtn),children:t.action.content??t.toastOptions?.defaultActionContent??"Action"}),l("button",{onClick:g,title:"Close toast",className:r(t.toastOptions?.classNames?.actions?.closeBtn),children:t.toastOptions?.defaultCloseContent??"Close"})]})]})},U=Z;import{jsx as j}from"react/jsx-runtime";var A,M,ot=({maxToasts:t=4,position:o="bottom-right",theme:a="system",toastOptions:e,...u})=>{let[c,s]=Y([]),[d,T]=Y(!1);tt(()=>{T(!0)},[]);let p=i=>{let n={_key_:O(),id:O(),...i};s(f=>{let v=o==="top-left"||o==="top-right"||o==="top-center",g=!1,y=f.map(b=>b.id===n.id?(g=!0,{...b,...n,isUpdate:!0}):b);return g?[...y]:f.length>=t?v?[n,...f.slice(0,-1)]:[...f.slice(1),n]:v?[n,...f]:[...f,n]})},m=i=>{s(n=>n.filter(f=>f.id!==i))};return A=p,M=m,d&&c.length>0&&j("section",{...u,"aria-label":"Toast Notifications",role:"alert","aria-live":"polite",className:r("t_toasts",o==="top-left"?"t_top-left":"",o==="top-right"?"t_top-right":"",o==="top-center"?"t_top-center":"",o==="bottom-left"?"t_bottom-left":"",o==="bottom-right"?"t_bottom-right":"",o==="bottom-center"?"t_bottom-center":"",e?.font?e?.font:"t_default_font"),children:c.map(i=>j(U,{theme:a,toastPosition:o,onClose:()=>m(i.id),toastOptions:e,active:c.indexOf(i)===c.length-1,...i},i._key_))})},x=t=>{A?A(t):console.error("\u{1F514} <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.")},$=t=>{M?M(t):console.error("\u{1F514} <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.")};var et={default:t=>(x({...t}),t),success:t=>(x({...t,variant:"success"}),t),error:t=>(x({...t,variant:"error"}),t),warning:t=>(x({...t,variant:"warning"}),t),info:t=>(x({...t,variant:"info"}),t),loading:t=>(x({...t,variant:"loading"}),t),close:t=>$(t)};export{ot as Toaster,et as toast};
|
|
4
4
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["#style-inject:#style-inject","../src/styles/globals.css","../src/components/toaster.tsx","../src/components/toast.tsx","../src/icons/index.tsx","../src/hooks/useTimeout.tsx","../src/utils/index.ts","../src/components/default-options.ts","../src/components/toast-functions.ts"],"sourcesContent":["\n export default function styleInject(css, { insertAt } = {}) {\n if (!css || typeof document === 'undefined') return\n \n const head = document.head || document.getElementsByTagName('head')[0]\n const style = document.createElement('style')\n style.type = 'text/css'\n \n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild)\n } else {\n head.appendChild(style)\n }\n } else {\n head.appendChild(style)\n }\n \n if (style.styleSheet) {\n style.styleSheet.cssText = css\n } else {\n style.appendChild(document.createTextNode(css))\n }\n }\n ","import styleInject from '#style-inject';styleInject(\":root{--pheralb-toast-animation-enter: .4s;--pheralb-toast-animation-exit: .4s}:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_light-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_dark-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}@media (prefers-color-scheme: dark){:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}}.t_toasts{display:flex;flex-direction:column;gap:10px;padding:14px;position:fixed;z-index:999;overflow:hidden;transition:max-height .5s ease-in-out;width:100%}.t_default_font{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.t_top-left{top:0;left:0}.t_top-right{top:0;right:0}.t_top-center{top:0;left:50%;transform:translate(-50%)}.t_bottom-left{bottom:0;left:0}.t_bottom-right{bottom:0;right:0}.t_bottom-center{bottom:0;left:50%;transform:translate(-50%)}@media (min-width: 768px){.t_toasts{max-width:355px}}.t_global{display:flex;justify-content:space-between;padding:0;margin:0;list-style:none;outline:none;background-color:var(--background-color);width:auto;box-shadow:0 1px 3px 0 var(--box-shadow),0 1px 2px -1px var(--box-shadow);border:1px solid var(--border-color);border-radius:.375rem;font-size:.875rem;line-height:1.25rem;overflow:hidden}.t_global button{border:none;outline:none}.t_global button:focus{outline:1px solid var(--focus-color);outline-offset:0px;background-color:var(--hover-color)}.t_container{display:flex;flex-direction:row;align-items:center;width:100%;max-width:20rem;height:100wh;gap:.6rem;padding:12px;word-wrap:break-word;overflow-wrap:break-word}.t_icon{fill:var(--text-color);margin-top:.1rem;flex-shrink:0}.t_content{display:flex;flex-direction:column;justify-content:center;max-width:100%}.t_content p{font-weight:600;color:var(--text-color);margin:0}.t_content p:nth-of-type(2){font-weight:400;font-size:.75rem;color:var(--description-color)}.t_actions{display:flex;flex-direction:column;border-left:1px solid var(--border-color);height:100wh}.t_actions>button{flex:1 1 0%;width:100%;padding:6px 20px;font-size:13px;background-color:transparent;cursor:pointer;border:none}.t_actions>button:nth-child(1){color:var(--text-color);font-weight:500}.t_actions>button:nth-child(2){color:var(--text-color);border-top:1px solid var(--border-color)}.t_actions>button:hover{background-color:var(--hover-color)}.t_loading{animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.t_slide-enter-top{animation:slide-top var(--pheralb-toast-animation-enter) ease}@keyframes slide-top{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.t_slide-enter-bottom{animation:slide-bottom var(--pheralb-toast-animation-enter) ease}@keyframes slide-bottom{0%{opacity:0;transform:translateY(100%)}to{opacity:1;transform:translateY(0)}}.t-slide-exit-top,.t-slide-exit-bottom{will-change:transform,opacity}.t-slide-exit-top{animation:slide-top-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-top-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t-slide-exit-bottom{animation:slide-bottom-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-bottom-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(100%)}}.t_swipe-exit-center{animation:swipe-center-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-center-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t_swipe-exit-left{animation:swipe-left-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-left-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100%)}}.t_swipe-exit-right{animation:swipe-right-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-right-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(100%)}}\\n\")","import { useEffect, useState } from \"react\";\n\nimport type {\n ToastId,\n ToastPropsWithVariant,\n ToasterProperties,\n} from \"../types/toast.types\";\n\nimport ToastComponent from \"./toast\";\nimport { cn, generateRandomId } from \"../utils\";\n\n// Ensure openToastGlobal is initialized correctly\nlet openToastGlobal: (data: ToastPropsWithVariant) => void;\n// Ensure closeToastGlobal is initialized correctly\nlet closeToastGlobal: (id: ToastId) => void;\n\nexport const Toaster = ({\n maxToasts = 4,\n position = \"bottom-right\",\n theme = \"system\",\n toastOptions,\n ...htmlProps\n}: ToasterProperties) => {\n const [toasts, setToasts] = useState<ToastPropsWithVariant[]>([]);\n const [isMounted, setIsMounted] = useState<boolean>(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // Define the openToast function\n const openToast = (data: ToastPropsWithVariant) => {\n const newToast = {\n id: generateRandomId(),\n ...data,\n };\n setToasts((prevToasts) => {\n const isTopPosition =\n position === \"top-left\" ||\n position === \"top-right\" ||\n position === \"top-center\";\n\n // If the `id` exists, update the notification\n let isToastUpdate = false;\n const updatedToasts = prevToasts.map(pt => {\n if (pt.id === newToast.id) {\n isToastUpdate = true;\n return {...pt, ...newToast}\n }\n return pt\n })\n\n if (isToastUpdate) {\n // `newToast` is embedded, array preserves length\n return [...updatedToasts]\n }\n\n if (prevToasts.length >= maxToasts) {\n return isTopPosition\n ? [newToast, ...prevToasts.slice(0, -1)]\n : [...prevToasts.slice(1), newToast];\n }\n\n return isTopPosition\n ? [newToast, ...prevToasts]\n : [...prevToasts, newToast];\n });\n };\n\n // Define the closeToast function\n const closeToast = (id: ToastId) => {\n setToasts((prevToasts) => prevToasts.filter((toast) => toast.id !== id));\n };\n\n // Assign openToast to the global variable\n openToastGlobal = openToast;\n // Assign closeToast to the global variable\n closeToastGlobal = closeToast;\n\n // Render the component\n return (\n isMounted &&\n toasts.length > 0 && (\n <section\n {...htmlProps}\n aria-label=\"Toast Notifications\"\n role=\"alert\"\n aria-live=\"polite\"\n className={cn(\n \"t_toasts\",\n position === \"top-left\" ? \"t_top-left\" : \"\",\n position === \"top-right\" ? \"t_top-right\" : \"\",\n position === \"top-center\" ? \"t_top-center\" : \"\",\n position === \"bottom-left\" ? \"t_bottom-left\" : \"\",\n position === \"bottom-right\" ? \"t_bottom-right\" : \"\",\n position === \"bottom-center\" ? \"t_bottom-center\" : \"\",\n toastOptions?.font ? toastOptions?.font : \"t_default_font\",\n )}\n >\n {toasts.map((toast) => (\n <ToastComponent\n key={toast.id}\n theme={theme}\n toastPosition={position}\n onClose={() => closeToast(toast.id!)}\n toastOptions={toastOptions}\n active={toasts.indexOf(toast) === toasts.length - 1}\n {...toast}\n />\n ))}\n </section>\n )\n );\n};\n\n// Export the openToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const openToast = (data: ToastPropsWithVariant): void => {\n if (openToastGlobal) {\n openToastGlobal(data);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n\n// Export the closeToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const closeToast = (id: ToastId): void => {\n if (closeToastGlobal) {\n closeToastGlobal(id);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n","import type {\n Position,\n ToastIcons,\n ToastOptions,\n ToastPropsWithLoading,\n Variant,\n} from \"../types/toast.types\";\n\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { Error, Info, Loading, Success, Warning } from \"../icons\";\nimport { useTimeout } from \"../hooks/useTimeout\";\nimport { cn, getSystemTheme, prefersReducedMotion } from \"../utils\";\n\nimport { iconsColors, getAnimationClass } from \"./default-options\";\n\ninterface ToastComponentProps extends ToastPropsWithLoading {\n toastPosition: Position;\n toastOptions?: ToastOptions;\n active?: boolean;\n onClose: () => void;\n}\n\nconst Toast = (props: ToastComponentProps) => {\n const [status, setStatus] = useState<Variant>(props.variant || \"info\");\n const [iconColor, setIconColor] = useState<string>(iconsColors[status]);\n const [toastText, setToastText] = useState<string>(props.text);\n const [isExiting, setIsExiting] = useState<boolean>(false);\n\n const delayDuration = props.delayDuration || 4000;\n\n const { pause, resume } = useTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n\n const iconClass = cn(\n \"t_icon\",\n props.variant === \"loading\" && status === \"loading\" ? \"t_loading\" : \"\",\n );\n\n const icons: ToastIcons = {\n success: (\n <Success\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n error: (\n <Error\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n warning: (\n <Warning\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n info: (\n <Info\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n loading: (\n <Loading\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n };\n\n const IconComponent = props.toastOptions?.icons\n ? props.toastOptions?.icons[status]\n : icons[status];\n\n const handleCloseToast = useCallback(() => {\n setIsExiting(true);\n const animationDisabled = prefersReducedMotion();\n if (!animationDisabled) {\n setTimeout(() => {\n if (props.onClose) {\n props.onClose();\n }\n }, 300);\n } else if (props.onClose) {\n props.onClose();\n }\n }, [props]);\n\n const handleMouseLeave = () => {\n resume();\n };\n\n const handleMouseEnter = () => {\n pause();\n };\n\n useEffect(() => {\n if (props.variant === \"loading\" && props.options) {\n pause();\n\n const executePromise =\n typeof props.options.promise === \"function\"\n ? props.options.promise()\n : Promise.resolve(props.options.promise);\n\n executePromise\n .then((data) => {\n resume();\n setStatus(\"success\");\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n setToastText(props.options!.success);\n setIconColor(iconsColors.success);\n if (props.options?.onSuccess) {\n props.options.onSuccess(data);\n }\n })\n .catch((error) => {\n setStatus(\"error\");\n setToastText(props.options!.error);\n setIconColor(iconsColors.error);\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n if (props.options?.onError) {\n props.options.onError(error, props.id);\n }\n });\n }\n }, [\n delayDuration,\n handleCloseToast,\n pause,\n props.options,\n props.variant,\n resume,\n ]);\n\n return (\n <div\n {...props.attrs}\n role=\"alert\"\n aria-labelledby={`toast-title-${props.id}`}\n aria-describedby={`toast-description-${props.id}`}\n title={props.text}\n className={cn(\n !prefersReducedMotion()\n ? getAnimationClass(\n isExiting,\n props.toastOptions?.animationOnClose || \"slide\",\n props.toastPosition,\n )\n : \"\",\n !props.toastOptions?.headless && props.theme === \"system\"\n ? getSystemTheme()\n : \"\",\n !props.toastOptions?.headless && props.theme === \"dark\"\n ? \"t_dark-theme\"\n : \"\",\n !props.toastOptions?.headless && props.theme === \"light\"\n ? \"t_light-theme\"\n : \"\",\n !props.toastOptions?.headless ? \"t_global\" : \"\",\n props.toastOptions?.classNames?.toast,\n props.attrs?.className,\n )}\n style={{\n zIndex: props.active ? 1000 : 999,\n ...props.attrs?.style,\n }}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleMouseEnter}\n onBlur={handleMouseLeave}\n >\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_container\" : \"\",\n props.toastOptions?.classNames?.container,\n )}\n >\n {props.variant && !props.icon ? (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {IconComponent}\n </div>\n ) : (\n props.icon && (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {props.icon}\n </div>\n )\n )}\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_content\" : \"\",\n props.toastOptions?.classNames?.content,\n )}\n >\n <p id={`toast-title-${props.id}`}>{toastText}</p>\n {props.description && (\n <p id={`toast-description-${props.id}`}>{props.description}</p>\n )}\n </div>\n </div>\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_actions\" : \"\",\n props.toastOptions?.classNames?.actions?.container,\n )}\n >\n {props.action && (\n <button\n onClick={props.action.onClick}\n title={\n typeof props.action.content === \"string\"\n ? props.action.content\n : \"Action Button\"\n }\n className={cn(props.toastOptions?.classNames?.actions?.actionBtn)}\n >\n {props.action.content ??\n props.toastOptions?.defaultActionContent ??\n \"Action\"}\n </button>\n )}\n <button\n onClick={handleCloseToast}\n title=\"Close toast\"\n className={cn(props.toastOptions?.classNames?.actions?.closeBtn)}\n >\n {props.toastOptions?.defaultCloseContent ?? \"Close\"}\n </button>\n </div>\n </div>\n );\n};\n\nexport default Toast;\n","import type { ComponentProps, FC } from \"react\";\n\nexport const Success: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z\"></path>\n </svg>\n);\n\nexport const Warning: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Error: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Info: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z\"></path>\n </svg>\n);\n\nexport const Loading: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M136 32v32a8 8 0 01-16 0V32a8 8 0 0116 0zm37.25 58.75a8 8 0 005.66-2.35l22.63-22.62a8 8 0 00-11.32-11.32L167.6 77.09a8 8 0 005.65 13.66zM224 120h-32a8 8 0 000 16h32a8 8 0 000-16zm-45.09 47.6a8 8 0 00-11.31 11.31l22.62 22.63a8 8 0 0011.32-11.32zM128 184a8 8 0 00-8 8v32a8 8 0 0016 0v-32a8 8 0 00-8-8zm-50.91-16.4l-22.63 22.62a8 8 0 0011.32 11.32l22.62-22.63a8 8 0 00-11.31-11.31zM72 128a8 8 0 00-8-8H32a8 8 0 000 16h32a8 8 0 008-8zm-6.22-73.54a8 8 0 00-11.32 11.32L77.09 88.4A8 8 0 0088.4 77.09z\"></path>\n </svg>\n);\n","import { useCallback, useEffect, useRef } from \"react\";\n\ninterface UseTimeoutReturn {\n pause: () => void;\n resume: () => void;\n reset: () => void;\n isActive: boolean;\n}\n\nexport const useTimeout = (\n callback: () => void,\n delay: number,\n): UseTimeoutReturn => {\n const timeoutRef = useRef<number>(0);\n const callbackRef = useRef(callback);\n const startTimeRef = useRef<number>(0);\n const remainingRef = useRef(delay);\n const isActiveRef = useRef(true);\n\n const cleanup = useCallback(() => {\n if (timeoutRef.current) {\n window.clearTimeout(timeoutRef.current);\n }\n }, []);\n\n const pause = useCallback(() => {\n if (!isActiveRef.current || !startTimeRef.current) return;\n\n cleanup();\n remainingRef.current -= Date.now() - startTimeRef.current;\n isActiveRef.current = false;\n }, [cleanup]);\n\n const resume = useCallback(() => {\n if (isActiveRef.current) return;\n\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(\n callbackRef.current,\n remainingRef.current,\n );\n isActiveRef.current = true;\n }, []);\n\n const reset = useCallback(() => {\n cleanup();\n remainingRef.current = delay;\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(callbackRef.current, delay);\n isActiveRef.current = true;\n }, [cleanup, delay]);\n\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n reset();\n return cleanup;\n }, [delay, reset, cleanup]);\n\n return {\n pause,\n resume,\n reset,\n isActive: isActiveRef.current,\n };\n};\n","export const cn = (...classes: (string | undefined)[]) => {\n return classes.filter(Boolean).join(\" \");\n};\n\nexport const generateRandomId = () => Math.floor(Math.random() * 1000000);\n\nexport const prefersReducedMotion = (() => {\n let shouldReduceMotion: boolean | undefined = undefined;\n return () => {\n if (shouldReduceMotion === undefined) {\n if (typeof window !== \"undefined\" && window.matchMedia !== undefined) {\n const mediaQuery = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n );\n shouldReduceMotion = mediaQuery.matches;\n } else {\n shouldReduceMotion = false;\n }\n }\n return shouldReduceMotion;\n };\n})();\n\n// Get system theme:\nexport const getSystemTheme = () => {\n if (typeof window !== \"undefined\") {\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n ? \"t_dark-theme\"\n : \"t_light-theme\";\n }\n return \"t_light-theme\";\n};\n","import type { Position, ToastAnimations, Variant } from \"../types/toast.types\";\n\n/* Default icon colors */\n\nexport const iconsColors: Record<Variant, string> = {\n success: \"#22c55e\",\n error: \"#ef4444\",\n warning: \"#eab308\",\n info: \"#3b82f6\",\n loading: \"currentColor\",\n};\n\n/* Default animations */\n\nconst ANIMATION_ENTER_MAP: Record<Position, string> = {\n \"top-left\": \"t_slide-enter-top\",\n \"top-right\": \"t_slide-enter-top\",\n \"top-center\": \"t_slide-enter-top\",\n \"bottom-left\": \"t_slide-enter-bottom\",\n \"bottom-right\": \"t_slide-enter-bottom\",\n \"bottom-center\": \"t_slide-enter-bottom\",\n};\n\nconst ANIMATION_EXIT_MAP: Record<Position, string> = {\n \"top-left\": \"t-slide-exit-top\",\n \"top-right\": \"t-slide-exit-top\",\n \"top-center\": \"t-slide-exit-top\",\n \"bottom-left\": \"t-slide-exit-bottom\",\n \"bottom-right\": \"t-slide-exit-bottom\",\n \"bottom-center\": \"t-slide-exit-bottom\",\n};\n\n/* Swipe exit animations */\n\nconst ANIMATION_SWIPE_EXIT_MAP: Record<Position, string> = {\n \"top-left\": \"t_swipe-exit-left\",\n \"top-right\": \"t_swipe-exit-right\",\n \"top-center\": \"t_swipe-exit-center\",\n \"bottom-left\": \"t_swipe-exit-left\",\n \"bottom-right\": \"t_swipe-exit-right\",\n \"bottom-center\": \"t_swipe-exit-center\",\n};\n\nexport const getAnimationClass = (\n isExiting: boolean,\n animationType: ToastAnimations,\n position: Position,\n) => {\n if (!isExiting) {\n return ANIMATION_ENTER_MAP[position];\n }\n\n if (animationType === \"swipe\") {\n return ANIMATION_SWIPE_EXIT_MAP[position];\n }\n\n return ANIMATION_EXIT_MAP[position];\n};\n","import type {\n ToastId,\n ToastPropsWithLoading,\n ToastPropsWithVariant\n} from '../types/toast.types';\nimport { openToast, closeToast } from './toaster';\n\ninterface ToastFunctions {\n default: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n success: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n error: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n warning: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n info: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n loading: (data: ToastPropsWithLoading) => ToastPropsWithLoading;\n close: (id: ToastId) => void;\n}\n\nexport const toast: ToastFunctions = {\n default: (data: ToastPropsWithVariant) => {\n openToast({ ...data });\n return data;\n },\n success: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'success' });\n return data;\n },\n error: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'error' });\n return data;\n },\n warning: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'warning' });\n return data;\n },\n info: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'info' });\n return data;\n },\n loading: (data: ToastPropsWithLoading) => {\n openToast({ ...data, variant: 'loading' });\n return data;\n },\n close: (id: ToastId) => closeToast(id)\n};\n"],"mappings":";AACyB,SAARA,EAA6BC,EAAK,CAAE,SAAAC,CAAS,EAAI,CAAC,EAAG,CAC1D,GAAI,CAACD,GAAO,OAAO,SAAa,IAAa,OAE7C,IAAME,EAAO,SAAS,MAAQ,SAAS,qBAAqB,MAAM,EAAE,CAAC,EAC/DC,EAAQ,SAAS,cAAc,OAAO,EAC5CA,EAAM,KAAO,WAETF,IAAa,OACXC,EAAK,WACPA,EAAK,aAAaC,EAAOD,EAAK,UAAU,EAK1CA,EAAK,YAAYC,CAAK,EAGpBA,EAAM,WACRA,EAAM,WAAW,QAAUH,EAE3BG,EAAM,YAAY,SAAS,eAAeH,CAAG,CAAC,CAElD,CCvB8BI,EAAY;AAAA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IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,MAAQE,GAAgBC,EAAWD,CAAE,CACvC","names":["styleInject","css","insertAt","head","style","styleInject","useEffect","useState","useCallback","useEffect","useState","jsx","Success","props","Warning","Error","Info","Loading","useCallback","useEffect","useRef","useTimeout","callback","delay","timeoutRef","callbackRef","startTimeRef","remainingRef","isActiveRef","cleanup","pause","resume","reset","cn","classes","generateRandomId","prefersReducedMotion","shouldReduceMotion","getSystemTheme","iconsColors","ANIMATION_ENTER_MAP","ANIMATION_EXIT_MAP","ANIMATION_SWIPE_EXIT_MAP","getAnimationClass","isExiting","animationType","position","jsx","jsxs","Toast","props","status","setStatus","useState","iconColor","setIconColor","iconsColors","toastText","setToastText","isExiting","setIsExiting","delayDuration","pause","resume","useTimeout","handleCloseToast","iconClass","cn","icons","Success","Error","Warning","Info","Loading","IconComponent","useCallback","prefersReducedMotion","handleMouseLeave","handleMouseEnter","useEffect","data","error","getAnimationClass","getSystemTheme","toast_default","jsx","openToastGlobal","closeToastGlobal","Toaster","maxToasts","position","theme","toastOptions","htmlProps","toasts","setToasts","useState","isMounted","setIsMounted","useEffect","openToast","data","newToast","generateRandomId","prevToasts","isTopPosition","isToastUpdate","updatedToasts","pt","closeToast","id","toast","cn","toast_default","toast","data","openToast","id","closeToast"]}
|
|
1
|
+
{"version":3,"sources":["#style-inject:#style-inject","../src/styles/globals.css","../src/components/toaster.tsx","../src/components/toast.tsx","../src/icons/index.tsx","../src/hooks/useTimeout.tsx","../src/utils/index.ts","../src/components/default-options.ts","../src/components/toast-functions.ts"],"sourcesContent":["\n export default function styleInject(css, { insertAt } = {}) {\n if (!css || typeof document === 'undefined') return\n \n const head = document.head || document.getElementsByTagName('head')[0]\n const style = document.createElement('style')\n style.type = 'text/css'\n \n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild)\n } else {\n head.appendChild(style)\n }\n } else {\n head.appendChild(style)\n }\n \n if (style.styleSheet) {\n style.styleSheet.cssText = css\n } else {\n style.appendChild(document.createTextNode(css))\n }\n }\n ","import styleInject from '#style-inject';styleInject(\":root{--pheralb-toast-animation-enter: .4s;--pheralb-toast-animation-exit: .4s}:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_light-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_dark-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}@media (prefers-color-scheme: dark){:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}}.t_toasts{display:flex;flex-direction:column;gap:10px;padding:14px;position:fixed;z-index:999;overflow:hidden;transition:max-height .5s ease-in-out;width:100%}.t_default_font{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.t_top-left{top:0;left:0}.t_top-right{top:0;right:0}.t_top-center{top:0;left:50%;transform:translate(-50%)}.t_bottom-left{bottom:0;left:0}.t_bottom-right{bottom:0;right:0}.t_bottom-center{bottom:0;left:50%;transform:translate(-50%)}@media (min-width: 768px){.t_toasts{max-width:355px}}.t_global{display:flex;justify-content:space-between;padding:0;margin:0;list-style:none;outline:none;background-color:var(--background-color);width:auto;box-shadow:0 1px 3px 0 var(--box-shadow),0 1px 2px -1px var(--box-shadow);border:1px solid var(--border-color);border-radius:.375rem;font-size:.875rem;line-height:1.25rem;overflow:hidden}.t_global button{border:none;outline:none}.t_global button:focus{outline:1px solid var(--focus-color);outline-offset:0px;background-color:var(--hover-color)}.t_container{display:flex;flex-direction:row;align-items:center;width:100%;max-width:20rem;height:100wh;gap:.6rem;padding:12px;word-wrap:break-word;overflow-wrap:break-word}.t_icon{fill:var(--text-color);margin-top:.1rem;flex-shrink:0}.t_content{display:flex;flex-direction:column;justify-content:center;max-width:100%}.t_content p{font-weight:600;color:var(--text-color);margin:0}.t_content p:nth-of-type(2){font-weight:400;font-size:.75rem;color:var(--description-color)}.t_actions{display:flex;flex-direction:column;border-left:1px solid var(--border-color);height:100wh}.t_actions>button{flex:1 1 0%;width:100%;padding:6px 20px;font-size:13px;background-color:transparent;cursor:pointer;border:none}.t_actions>button:nth-child(1){color:var(--text-color);font-weight:500}.t_actions>button:nth-child(2){color:var(--text-color);border-top:1px solid var(--border-color)}.t_actions>button:hover{background-color:var(--hover-color)}.t_loading{animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.t_slide-enter-top{animation:slide-top var(--pheralb-toast-animation-enter) ease}@keyframes slide-top{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.t_slide-enter-bottom{animation:slide-bottom var(--pheralb-toast-animation-enter) ease}@keyframes slide-bottom{0%{opacity:0;transform:translateY(100%)}to{opacity:1;transform:translateY(0)}}.t-slide-exit-top,.t-slide-exit-bottom{will-change:transform,opacity}.t-slide-exit-top{animation:slide-top-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-top-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t-slide-exit-bottom{animation:slide-bottom-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-bottom-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(100%)}}.t_swipe-exit-center{animation:swipe-center-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-center-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t_swipe-exit-left{animation:swipe-left-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-left-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100%)}}.t_swipe-exit-right{animation:swipe-right-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-right-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(100%)}}\\n\")","import { useEffect, useState } from \"react\";\n\nimport type {\n ToastId,\n ToastPropsInternal,\n ToastPropsWithVariant,\n ToasterProperties,\n} from \"../types/toast.types\";\n\nimport ToastComponent from \"./toast\";\nimport { cn, generateRandomId } from \"../utils\";\n\n// Ensure openToastGlobal is initialized correctly\nlet openToastGlobal: (data: ToastPropsWithVariant) => void;\n// Ensure closeToastGlobal is initialized correctly\nlet closeToastGlobal: (id: ToastId) => void;\n\nexport const Toaster = ({\n maxToasts = 4,\n position = \"bottom-right\",\n theme = \"system\",\n toastOptions,\n ...htmlProps\n}: ToasterProperties) => {\n const [toasts, setToasts] = useState<ToastPropsInternal[]>([]);\n const [isMounted, setIsMounted] = useState<boolean>(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // Define the openToast function\n const openToast = (data: ToastPropsWithVariant) => {\n const newToast: ToastPropsInternal = {\n _key_: generateRandomId(),\n id: generateRandomId(),\n ...data,\n };\n setToasts((prevToasts) => {\n const isTopPosition =\n position === \"top-left\" ||\n position === \"top-right\" ||\n position === \"top-center\";\n\n // If the `id` exists, update the notification\n let isToastUpdate = false;\n const updatedToasts = prevToasts.map(pt => {\n if (pt.id === newToast.id) {\n isToastUpdate = true;\n return { ...pt, ...newToast, isUpdate: true } satisfies ToastPropsInternal;\n }\n return pt\n })\n\n if (isToastUpdate) {\n // `newToast` is embedded, array preserves length\n return [...updatedToasts]\n }\n\n if (prevToasts.length >= maxToasts) {\n return isTopPosition\n ? [newToast, ...prevToasts.slice(0, -1)]\n : [...prevToasts.slice(1), newToast];\n }\n\n return isTopPosition\n ? [newToast, ...prevToasts]\n : [...prevToasts, newToast];\n });\n };\n\n // Define the closeToast function\n const closeToast = (id: ToastId) => {\n setToasts((prevToasts) => prevToasts.filter((toast) => toast.id !== id));\n };\n\n // Assign openToast to the global variable\n openToastGlobal = openToast;\n // Assign closeToast to the global variable\n closeToastGlobal = closeToast;\n\n // Render the component\n return (\n isMounted &&\n toasts.length > 0 && (\n <section\n {...htmlProps}\n aria-label=\"Toast Notifications\"\n role=\"alert\"\n aria-live=\"polite\"\n className={cn(\n \"t_toasts\",\n position === \"top-left\" ? \"t_top-left\" : \"\",\n position === \"top-right\" ? \"t_top-right\" : \"\",\n position === \"top-center\" ? \"t_top-center\" : \"\",\n position === \"bottom-left\" ? \"t_bottom-left\" : \"\",\n position === \"bottom-right\" ? \"t_bottom-right\" : \"\",\n position === \"bottom-center\" ? \"t_bottom-center\" : \"\",\n toastOptions?.font ? toastOptions?.font : \"t_default_font\",\n )}\n >\n {toasts.map((toast) => (\n <ToastComponent\n key={toast._key_}\n theme={theme}\n toastPosition={position}\n onClose={() => closeToast(toast.id!)}\n toastOptions={toastOptions}\n active={toasts.indexOf(toast) === toasts.length - 1}\n {...toast}\n />\n ))}\n </section>\n )\n );\n};\n\n// Export the openToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const openToast = (data: ToastPropsWithVariant): void => {\n if (openToastGlobal) {\n openToastGlobal(data);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n\n// Export the closeToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const closeToast = (id: ToastId): void => {\n if (closeToastGlobal) {\n closeToastGlobal(id);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n","import type {\n ToastPosition,\n ToastIcons,\n ToastOptions,\n ToastPropsWithLoading,\n Variant,\n ToastPropsInternal,\n} from \"../types/toast.types\";\n\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { Error, Info, Loading, Success, Warning } from \"../icons\";\nimport { useTimeout } from \"../hooks/useTimeout\";\nimport { cn, getSystemTheme, prefersReducedMotion } from \"../utils\";\n\nimport { iconsColors, getAnimationClass } from \"./default-options\";\n\ntype ToastComponentProps = ToastPropsInternal &\n Pick<ToastPropsWithLoading, 'options'> &\n{\n toastPosition: ToastPosition;\n toastOptions?: ToastOptions;\n active?: boolean;\n onClose: () => void;\n};\n\nconst DEFAULT_DURATION = 4000;\n\nconst Toast = (props: ToastComponentProps) => {\n const [status, setStatus] = useState<Variant>(props.variant || \"info\");\n const [iconColor, setIconColor] = useState<string>(iconsColors[status]);\n const [toastText, setToastText] = useState<string>(props.text);\n const [isExiting, setIsExiting] = useState<boolean>(false);\n\n const delayDuration = props.delayDuration || DEFAULT_DURATION;\n\n const { pause, resume } = useTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n\n const iconClass = cn(\n \"t_icon\",\n props.variant === \"loading\" && status === \"loading\" ? \"t_loading\" : \"\",\n );\n\n const icons: ToastIcons = {\n success: (\n <Success\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n error: (\n <Error\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n warning: (\n <Warning\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n info: (\n <Info\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n loading: (\n <Loading\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n };\n\n const IconComponent = props.toastOptions?.icons\n ? props.toastOptions?.icons[status]\n : icons[status];\n\n const handleCloseToast = useCallback(() => {\n setIsExiting(true);\n const animationDisabled = prefersReducedMotion();\n if (!animationDisabled) {\n setTimeout(() => {\n if (props.onClose) {\n props.onClose();\n }\n }, 300);\n } else if (props.onClose) {\n props.onClose();\n }\n }, [props]);\n\n const handleMouseLeave = () => {\n resume();\n };\n\n const handleMouseEnter = () => {\n pause();\n };\n\n useEffect(() => {\n if (props.variant === \"loading\" && props.options) {\n pause();\n\n const executePromise =\n typeof props.options.promise === \"function\"\n ? props.options.promise()\n : Promise.resolve(props.options.promise);\n\n executePromise\n .then((data) => {\n resume();\n setStatus(\"success\");\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n setToastText(props.options!.success);\n setIconColor(iconsColors.success);\n if (props.options?.onSuccess) {\n props.options.onSuccess(data, props.id!);\n }\n })\n .catch((error) => {\n setStatus(\"error\");\n setToastText(props.options!.error);\n setIconColor(iconsColors.error);\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n if (props.options?.onError) {\n props.options.onError(error, props.id!);\n }\n });\n }\n }, [delayDuration, handleCloseToast, pause, props.id, props.options, props.variant, resume]);\n\n return (\n <div\n {...props.attrs}\n role=\"alert\"\n aria-labelledby={`toast-title-${props.id}`}\n aria-describedby={`toast-description-${props.id}`}\n title={props.text}\n className={cn(\n prefersReducedMotion() || props.isUpdate\n ? \"\"\n : getAnimationClass(\n isExiting,\n props.toastOptions?.animationOnClose || \"slide\",\n props.toastPosition,\n ),\n !props.toastOptions?.headless && props.theme === \"system\"\n ? getSystemTheme()\n : \"\",\n !props.toastOptions?.headless && props.theme === \"dark\"\n ? \"t_dark-theme\"\n : \"\",\n !props.toastOptions?.headless && props.theme === \"light\"\n ? \"t_light-theme\"\n : \"\",\n !props.toastOptions?.headless ? \"t_global\" : \"\",\n props.toastOptions?.classNames?.toast,\n props.attrs?.className,\n )}\n style={{\n zIndex: props.active ? 1000 : 999,\n ...props.attrs?.style,\n }}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleMouseEnter}\n onBlur={handleMouseLeave}\n >\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_container\" : \"\",\n props.toastOptions?.classNames?.container,\n )}\n >\n {props.variant && !props.icon ? (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {IconComponent}\n </div>\n ) : (\n props.icon && (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {props.icon}\n </div>\n )\n )}\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_content\" : \"\",\n props.toastOptions?.classNames?.content,\n )}\n >\n <p id={`toast-title-${props.id}`}>{toastText}</p>\n {props.description && (\n <p id={`toast-description-${props.id}`}>{props.description}</p>\n )}\n </div>\n </div>\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_actions\" : \"\",\n props.toastOptions?.classNames?.actions?.container,\n )}\n >\n {props.action && (\n <button\n onClick={props.action.onClick}\n title={\n typeof props.action.content === \"string\"\n ? props.action.content\n : \"Action Button\"\n }\n className={cn(props.toastOptions?.classNames?.actions?.actionBtn)}\n >\n {props.action.content ??\n props.toastOptions?.defaultActionContent ??\n \"Action\"}\n </button>\n )}\n <button\n onClick={handleCloseToast}\n title=\"Close toast\"\n className={cn(props.toastOptions?.classNames?.actions?.closeBtn)}\n >\n {props.toastOptions?.defaultCloseContent ?? \"Close\"}\n </button>\n </div>\n </div>\n );\n};\n\nexport default Toast;\n","import type { ComponentProps, FC } from \"react\";\n\nexport const Success: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z\"></path>\n </svg>\n);\n\nexport const Warning: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Error: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Info: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z\"></path>\n </svg>\n);\n\nexport const Loading: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M136 32v32a8 8 0 01-16 0V32a8 8 0 0116 0zm37.25 58.75a8 8 0 005.66-2.35l22.63-22.62a8 8 0 00-11.32-11.32L167.6 77.09a8 8 0 005.65 13.66zM224 120h-32a8 8 0 000 16h32a8 8 0 000-16zm-45.09 47.6a8 8 0 00-11.31 11.31l22.62 22.63a8 8 0 0011.32-11.32zM128 184a8 8 0 00-8 8v32a8 8 0 0016 0v-32a8 8 0 00-8-8zm-50.91-16.4l-22.63 22.62a8 8 0 0011.32 11.32l22.62-22.63a8 8 0 00-11.31-11.31zM72 128a8 8 0 00-8-8H32a8 8 0 000 16h32a8 8 0 008-8zm-6.22-73.54a8 8 0 00-11.32 11.32L77.09 88.4A8 8 0 0088.4 77.09z\"></path>\n </svg>\n);\n","import { useCallback, useEffect, useRef } from \"react\";\n\ninterface UseTimeoutReturn {\n pause: () => void;\n resume: () => void;\n reset: () => void;\n isActive: boolean;\n}\n\nexport const useTimeout = (\n callback: () => void,\n delay: number,\n): UseTimeoutReturn => {\n const timeoutRef = useRef<number>(0);\n const callbackRef = useRef(callback);\n const startTimeRef = useRef<number>(0);\n const remainingRef = useRef(delay);\n const isActiveRef = useRef(true);\n\n const cleanup = useCallback(() => {\n if (timeoutRef.current) {\n window.clearTimeout(timeoutRef.current);\n }\n }, []);\n\n const pause = useCallback(() => {\n if (!isActiveRef.current || !startTimeRef.current) return;\n\n cleanup();\n remainingRef.current -= Date.now() - startTimeRef.current;\n isActiveRef.current = false;\n }, [cleanup]);\n\n const resume = useCallback(() => {\n if (isActiveRef.current) return;\n\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(\n callbackRef.current,\n remainingRef.current,\n );\n isActiveRef.current = true;\n }, []);\n\n const reset = useCallback(() => {\n cleanup();\n remainingRef.current = delay;\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(callbackRef.current, delay);\n isActiveRef.current = true;\n }, [cleanup, delay]);\n\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n reset();\n return cleanup;\n }, [delay, reset, cleanup]);\n\n return {\n pause,\n resume,\n reset,\n isActive: isActiveRef.current,\n };\n};\n","export const cn = (...classes: (string | undefined)[]) => {\n return classes.filter(Boolean).join(\" \");\n};\n\nexport const generateRandomId = () =>\n Math.random().toString(16).slice(2, 10);\n\nexport const prefersReducedMotion = (() => {\n let shouldReduceMotion: boolean | undefined = undefined;\n return () => {\n if (shouldReduceMotion === undefined) {\n if (typeof window !== \"undefined\" && window.matchMedia !== undefined) {\n const mediaQuery = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n );\n shouldReduceMotion = mediaQuery.matches;\n } else {\n shouldReduceMotion = false;\n }\n }\n return shouldReduceMotion;\n };\n})();\n\n// Get system theme:\nexport const getSystemTheme = () => {\n if (typeof window !== \"undefined\") {\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n ? \"t_dark-theme\"\n : \"t_light-theme\";\n }\n return \"t_light-theme\";\n};\n","import type { ToastPosition, ToastAnimations, Variant } from \"../types/toast.types\";\n\n/* Default icon colors */\n\nexport const iconsColors: Record<Variant, string> = {\n success: \"#22c55e\",\n error: \"#ef4444\",\n warning: \"#eab308\",\n info: \"#3b82f6\",\n loading: \"currentColor\",\n};\n\n/* Default animations */\n\nconst ANIMATION_ENTER_MAP: Record<ToastPosition, string> = {\n \"top-left\": \"t_slide-enter-top\",\n \"top-right\": \"t_slide-enter-top\",\n \"top-center\": \"t_slide-enter-top\",\n \"bottom-left\": \"t_slide-enter-bottom\",\n \"bottom-right\": \"t_slide-enter-bottom\",\n \"bottom-center\": \"t_slide-enter-bottom\",\n};\n\nconst ANIMATION_EXIT_MAP: Record<ToastPosition, string> = {\n \"top-left\": \"t-slide-exit-top\",\n \"top-right\": \"t-slide-exit-top\",\n \"top-center\": \"t-slide-exit-top\",\n \"bottom-left\": \"t-slide-exit-bottom\",\n \"bottom-right\": \"t-slide-exit-bottom\",\n \"bottom-center\": \"t-slide-exit-bottom\",\n};\n\n/* Swipe exit animations */\n\nconst ANIMATION_SWIPE_EXIT_MAP: Record<ToastPosition, string> = {\n \"top-left\": \"t_swipe-exit-left\",\n \"top-right\": \"t_swipe-exit-right\",\n \"top-center\": \"t_swipe-exit-center\",\n \"bottom-left\": \"t_swipe-exit-left\",\n \"bottom-right\": \"t_swipe-exit-right\",\n \"bottom-center\": \"t_swipe-exit-center\",\n};\n\nexport const getAnimationClass = (\n isExiting: boolean,\n animationType: ToastAnimations,\n position: ToastPosition,\n) => {\n if (!isExiting) {\n return ANIMATION_ENTER_MAP[position];\n }\n\n if (animationType === \"swipe\") {\n return ANIMATION_SWIPE_EXIT_MAP[position];\n }\n\n return ANIMATION_EXIT_MAP[position];\n};\n","import type {\n ToastId,\n ToastPropsWithLoading,\n ToastPropsWithVariant\n} from '../types/toast.types';\nimport { openToast, closeToast } from './toaster';\n\ninterface ToastFunctions {\n default: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n success: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n error: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n warning: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n info: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n loading: <T = unknown>(data: ToastPropsWithLoading<T>) => ToastPropsWithLoading<T>;\n close: (id: ToastId) => void;\n}\n\nexport const toast: ToastFunctions = {\n default: (data: ToastPropsWithVariant) => {\n openToast({ ...data });\n return data;\n },\n success: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'success' });\n return data;\n },\n error: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'error' });\n return data;\n },\n warning: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'warning' });\n return data;\n },\n info: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'info' });\n return data;\n },\n loading: <T = unknown>(data: ToastPropsWithLoading<T>) => {\n openToast({ ...data, variant: 'loading' });\n return data;\n },\n close: (id: ToastId) => closeToast(id)\n};\n"],"mappings":";AACyB,SAARA,EAA6BC,EAAK,CAAE,SAAAC,CAAS,EAAI,CAAC,EAAG,CAC1D,GAAI,CAACD,GAAO,OAAO,SAAa,IAAa,OAE7C,IAAME,EAAO,SAAS,MAAQ,SAAS,qBAAqB,MAAM,EAAE,CAAC,EAC/DC,EAAQ,SAAS,cAAc,OAAO,EAC5CA,EAAM,KAAO,WAETF,IAAa,OACXC,EAAK,WACPA,EAAK,aAAaC,EAAOD,EAAK,UAAU,EAK1CA,EAAK,YAAYC,CAAK,EAGpBA,EAAM,WACRA,EAAM,WAAW,QAAUH,EAE3BG,EAAM,YAAY,SAAS,eAAeH,CAAG,CAAC,CAElD,CCvB8BI,EAAY;AAAA,CAAu6I,ECA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D,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,KAAOA,IACLC,EAAU,CAAE,GAAGD,EAAM,QAAS,MAAO,CAAC,EAC/BA,GAET,QAAuBA,IACrBC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,MAAQE,GAAgBC,EAAWD,CAAE,CACvC","names":["styleInject","css","insertAt","head","style","styleInject","useEffect","useState","useCallback","useEffect","useState","jsx","Success","props","Warning","Error","Info","Loading","useCallback","useEffect","useRef","useTimeout","callback","delay","timeoutRef","callbackRef","startTimeRef","remainingRef","isActiveRef","cleanup","pause","resume","reset","cn","classes","generateRandomId","prefersReducedMotion","shouldReduceMotion","getSystemTheme","iconsColors","ANIMATION_ENTER_MAP","ANIMATION_EXIT_MAP","ANIMATION_SWIPE_EXIT_MAP","getAnimationClass","isExiting","animationType","position","jsx","jsxs","DEFAULT_DURATION","Toast","props","status","setStatus","useState","iconColor","setIconColor","iconsColors","toastText","setToastText","isExiting","setIsExiting","delayDuration","pause","resume","useTimeout","handleCloseToast","iconClass","cn","icons","Success","Error","Warning","Info","Loading","IconComponent","useCallback","prefersReducedMotion","handleMouseLeave","handleMouseEnter","useEffect","data","error","getAnimationClass","getSystemTheme","toast_default","jsx","openToastGlobal","closeToastGlobal","Toaster","maxToasts","position","theme","toastOptions","htmlProps","toasts","setToasts","useState","isMounted","setIsMounted","useEffect","openToast","data","newToast","generateRandomId","prevToasts","isTopPosition","isToastUpdate","updatedToasts","pt","closeToast","id","toast","cn","toast_default","toast","data","openToast","id","closeToast"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nicojones/toast",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"author": "@nicojones",
|
|
5
5
|
"description": "A simple notification library for React. Fully customizable and lightweight.",
|
|
6
6
|
"repository": {
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
"test": "vitest run --config ./vitest.config.ts",
|
|
44
44
|
"test:watch": "vitest --watch",
|
|
45
45
|
"lint": "eslint ./src",
|
|
46
|
-
"prepublishOnly": "pnpm build"
|
|
46
|
+
"prepublishOnly": "pnpm build",
|
|
47
|
+
"publish:dry-run": "pnpm build && npm pack --dry-run",
|
|
48
|
+
"publish:package": "pnpm build && npm publish --access public"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
49
51
|
"@testing-library/jest-dom": "6.6.3",
|