react-strawberry-toast 1.5.4 → 1.6.0
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 +5 -0
- package/dist/headless.d.mts +5 -2
- package/dist/headless.d.ts +5 -2
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ function App() {
|
|
|
53
53
|
| style | Style of ToastContainer | Object | |
|
|
54
54
|
| gap | Gap Between toasts | Number | 9 |
|
|
55
55
|
| pauseOnActivate | Pause Toast timer when blur events occurs | Boolean | true |
|
|
56
|
+
| limit | Limit the number of toast to be displayed | Number | |
|
|
56
57
|
|
|
57
58
|
|
|
58
59
|
### toast
|
|
@@ -66,6 +67,10 @@ function App() {
|
|
|
66
67
|
| icon | The icon to be displayed in the toast | ReactNode | |
|
|
67
68
|
| timeOut | Time for toast to disappear | Number | 3000 |
|
|
68
69
|
| removeTimeOut | Time for toast to remove In Toast List | Number | 200 |
|
|
70
|
+
| className | Class of toast | String | |
|
|
71
|
+
| style | Style of toast | Object | |
|
|
72
|
+
| target | Target element where toast will be located | Object | |
|
|
73
|
+
|
|
69
74
|
|
|
70
75
|
## License
|
|
71
76
|
|
package/dist/headless.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ interface BaseOptions {
|
|
|
6
6
|
toastId?: string;
|
|
7
7
|
timeOut?: number;
|
|
8
8
|
removeTimeOut?: number;
|
|
9
|
-
className?: string;
|
|
9
|
+
className?: string | null;
|
|
10
10
|
style?: React.CSSProperties;
|
|
11
11
|
}
|
|
12
12
|
interface ToastBaseState {
|
|
@@ -22,7 +22,10 @@ interface Options extends BaseOptions {
|
|
|
22
22
|
position?: Position | null;
|
|
23
23
|
containerId?: string | null;
|
|
24
24
|
pauseOnHover?: boolean;
|
|
25
|
-
|
|
25
|
+
target?: {
|
|
26
|
+
element: HTMLElement;
|
|
27
|
+
offset?: [number, number];
|
|
28
|
+
} | null;
|
|
26
29
|
}
|
|
27
30
|
interface ToastDataCallback {
|
|
28
31
|
toastId: ToastBaseState['toastId'];
|
package/dist/headless.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface BaseOptions {
|
|
|
6
6
|
toastId?: string;
|
|
7
7
|
timeOut?: number;
|
|
8
8
|
removeTimeOut?: number;
|
|
9
|
-
className?: string;
|
|
9
|
+
className?: string | null;
|
|
10
10
|
style?: React.CSSProperties;
|
|
11
11
|
}
|
|
12
12
|
interface ToastBaseState {
|
|
@@ -22,7 +22,10 @@ interface Options extends BaseOptions {
|
|
|
22
22
|
position?: Position | null;
|
|
23
23
|
containerId?: string | null;
|
|
24
24
|
pauseOnHover?: boolean;
|
|
25
|
-
|
|
25
|
+
target?: {
|
|
26
|
+
element: HTMLElement;
|
|
27
|
+
offset?: [number, number];
|
|
28
|
+
} | null;
|
|
26
29
|
}
|
|
27
30
|
interface ToastDataCallback {
|
|
28
31
|
toastId: ToastBaseState['toastId'];
|
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ interface BaseOptions {
|
|
|
7
7
|
toastId?: string;
|
|
8
8
|
timeOut?: number;
|
|
9
9
|
removeTimeOut?: number;
|
|
10
|
-
className?: string;
|
|
10
|
+
className?: string | null;
|
|
11
11
|
style?: React.CSSProperties;
|
|
12
12
|
}
|
|
13
13
|
interface ToastBaseState {
|
|
@@ -23,7 +23,10 @@ interface Options extends BaseOptions {
|
|
|
23
23
|
position?: Position | null;
|
|
24
24
|
containerId?: string | null;
|
|
25
25
|
pauseOnHover?: boolean;
|
|
26
|
-
|
|
26
|
+
target?: {
|
|
27
|
+
element: HTMLElement;
|
|
28
|
+
offset?: [number, number];
|
|
29
|
+
} | null;
|
|
27
30
|
}
|
|
28
31
|
interface ToastDataCallback {
|
|
29
32
|
toastId: ToastBaseState['toastId'];
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ interface BaseOptions {
|
|
|
7
7
|
toastId?: string;
|
|
8
8
|
timeOut?: number;
|
|
9
9
|
removeTimeOut?: number;
|
|
10
|
-
className?: string;
|
|
10
|
+
className?: string | null;
|
|
11
11
|
style?: React.CSSProperties;
|
|
12
12
|
}
|
|
13
13
|
interface ToastBaseState {
|
|
@@ -23,7 +23,10 @@ interface Options extends BaseOptions {
|
|
|
23
23
|
position?: Position | null;
|
|
24
24
|
containerId?: string | null;
|
|
25
25
|
pauseOnHover?: boolean;
|
|
26
|
-
|
|
26
|
+
target?: {
|
|
27
|
+
element: HTMLElement;
|
|
28
|
+
offset?: [number, number];
|
|
29
|
+
} | null;
|
|
27
30
|
}
|
|
28
31
|
interface ToastDataCallback {
|
|
29
32
|
toastId: ToastBaseState['toastId'];
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var L=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var st=(t,e)=>{for(var n in e)L(t,n,{get:e[n],enumerable:!0})},nt=(t,e,n,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of rt(e))!ot.call(t,r)&&r!==n&&L(t,r,{get:()=>e[r],enumerable:!(p=at(e,r))||p.enumerable});return t};var it=t=>nt(L({},"__esModule",{value:!0}),t);var ut={};st(ut,{ToastContainer:()=>mt,toast:()=>o,toastStore:()=>h,useToasts:()=>V});module.exports=it(ut);var B=()=>{let t=0;return()=>`react-strawberry-toast_${t++}`};var $=class{state=[];listeners=new Set;activatedToasts=new Set;toastTimers=new Map;constructor(){}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setState(e){this.state=typeof e=="function"?e(this.state):e,this.listeners.forEach(n=>n())}getSnapShot(){return this.state}};var l="react-strawberry-toast";var b=require("react/jsx-runtime");function ct(){return(0,b.jsxs)("svg",{stroke:"none",fill:"none",strokeWidth:"2",viewBox:"0 0 24 24",strokeLinecap:"round",strokeLinejoin:"round",height:"22",width:"22",xmlns:"http://www.w3.org/2000/svg",children:[(0,b.jsx)("path",{stroke:"none",d:"M0 0h24v24H0z"}),(0,b.jsx)("path",{d:"M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-1.293 5.953a1 1 0 0 0 -1.32 -.083l-.094 .083l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.403 1.403l.083 .094l2 2l.094 .083a1 1 0 0 0 1.226 0l.094 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z",strokeWidth:"0",fill:"#1dca82"})]})}function dt(){return(0,b.jsx)("svg",{stroke:"none",fill:"#eb2639",strokeWidth:"2",viewBox:"0 0 24 24",height:"22",width:"22",xmlns:"http://www.w3.org/2000/svg",children:(0,b.jsx)("path",{d:"M11.953 2C6.465 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.493 2 11.953 2zM13 17h-2v-2h2v2zm0-4h-2V7h2v6z"})})}function lt(){return(0,b.jsx)("svg",{stroke:"none",fill:"#fcba03",strokeWidth:"0",viewBox:"0 0 1024 1024",height:"22",width:"22",xmlns:"http://www.w3.org/2000/svg",children:(0,b.jsx)("path",{d:"M955.7 856l-416-720c-6.2-10.7-16.9-16-27.7-16s-21.6 5.3-27.7 16l-416 720C56 877.4 71.4 904 96 904h832c24.6 0 40-26.6 27.7-48zM480 416c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v184c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V416zm32 352a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z"})})}var g={success:(0,b.jsx)(ct,{}),error:(0,b.jsx)(dt,{}),loading:(0,b.jsx)("div",{className:`${l}__loading`}),warn:(0,b.jsx)(lt,{})};var X=t=>{let e=a=>{let i=t.toastTimers.get(a);clearTimeout(i),t.toastTimers.delete(a)},n=a=>{t.activatedToasts.add(a)},p=a=>t.activatedToasts.has(a),r=(a,i=200)=>{p(a)&&(t.activatedToasts.delete(a),setTimeout(()=>{t.state=t.state.filter(d=>d.toastId!==a),t.setState([...t.state])},i),e(a))},T=()=>{t.setState([])},m=(a,i,d)=>{t.state=t.state.map(w=>w.toastId===a?{...w,...d,updated:new Date().getTime(),data:i}:w),t.setState([...t.state])},v=a=>{let i=new Date().getTime();t.state=t.state.map(d=>d.toastId===a?{...d,pausedAt:i}:d),e(a)},u=(a,i)=>{let d=setTimeout(()=>{var s;t.state=t.state.map(c=>c.toastId===a?{...c,isVisible:!1}:c),t.setState([...t.state]);let w=(s=t.state.find(c=>c.toastId===a))==null?void 0:s.removeTimeOut;r(a,w)},i>2147483647?2147483647:i);t.toastTimers.set(a,d)};return{setActive:n,isActive:p,disappear:u,resume:a=>{if(t.toastTimers.has(a))return;let i=t.state.find(w=>w.toastId===a);if(!i)return;let d=i.createdAt+(i.timeOut||3e3)-(i.pausedAt||0);u(a,d)},pause:v,replace:m,remove:r,allClear:T}};var h=new $,pt=B(),A=(t="default")=>(e,n={})=>{let{timeOut:p=3e3,removeTimeOut:r=200,pauseOnHover:T=!0,toastId:m,className:v,style:u,target:f}=n,a=m||pt();if(o.isActive(a))throw new Error("A duplicate custom ID is not available.");let i=new Date().getTime(),d={updated:null,pausedAt:null,className:v||null,style:u||{},icon:n.icon||null,containerId:n.containerId||null,position:n.position||null,timeOut:p>2147483647?2147483647:p,toastId:a,data:e,createdAt:i,toastType:t,pauseOnHover:T,removeTimeOut:r,target:f||null,isVisible:!0};return h.state.push(d),h.setState([...h.state]),a},o=(t,e={})=>A()(t,e),E=X(h);o.setActive=E.setActive;o.isActive=E.isActive;o.disappear=E.disappear;o.resume=E.resume;o.pause=E.pause;o.replace=E.replace;o.remove=E.remove;o.allClear=E.allClear;o.success=A("success");o.error=A("error");o.warn=A("warn");o.loading=A("loading");o.custom=A("custom");o.promise=(t,e,n={})=>{let{loading:p,success:r,error:T}=e,m=o.loading(p,{...n,timeOut:2147483647}),v={toastId:m,close:()=>o.disappear(m,0),immediatelyClose:()=>{o.disappear(m,0),o.remove(m,0)},icons:{success:g.success,error:g.error,warn:g.warn,loading:g.loading},isVisible:!0},u=n.timeOut||=3e3;t.then(f=>{o.replace(m,typeof r=="function"?r(f,v):r,{...n,timeOut:u>2147483647?2147483647:u,toastType:"success"})}).catch(f=>{o.replace(m,typeof T=="function"?T(f,v):T,{...n,timeOut:u>2147483647?2147483647:u,toastType:"error"})})};var U=require("react");var P=require("react");var G=require("react");function F({condition:t,children:e}){let n=G.Children.toArray(e);if(n.length>2)throw new Error("The number of children exceeds two.");return n.find(p=>t?p.key===".0":p.key===".1")}function j({children:t}){return t}function q({children:t}){return t}var J=({isVisible:t,position:e})=>e?t?/top/i.test(e)?`${l}__fade-in`:`${l}__fade-in-reverse`:/bottom/i.test(e)?`${l}__fade-out-reverse`:`${l}__fade-out`:t?`${l}__fade-in`:`${l}__fade-out`;var O=require("react"),W=(t,e)=>{let n=(0,O.useRef)(e);(0,O.useEffect)(()=>{n.current=e},[e]),(0,O.useEffect)(()=>(window.addEventListener(t,n.current),()=>{window.removeEventListener(t,n.current)}),[t])};var I=require("react/jsx-runtime"),Y=(0,P.forwardRef)(function({toastProps:e,pauseOnActivate:n},p){let{toastId:r,isVisible:T,timeOut:m,containerId:v,className:u,style:f,icon:a,updated:i,toastType:d,position:w,data:s,pauseOnHover:c}=e,y=J({isVisible:T,position:w}),S=typeof s=="function"?s({toastId:r,close:()=>o.disappear(r,0),immediatelyClose:()=>{o.disappear(r,0),o.remove(r,0)},icons:{success:g.success,error:g.error,warn:g.warn,loading:g.loading},isVisible:T}):s,_=()=>{n&&o.resume(r)},k=()=>{n&&o.pause(r)};W("focus",_),W("blur",k),(0,P.useEffect)(()=>{o.isActive(r)||(o.setActive(r),o.disappear(r,m))},[r]),(0,P.useEffect)(()=>{i!==null&&o.disappear(r,m)},[i]);let R=a||(d==="custom"||d==="default"?null:g[d]);return(0,I.jsx)("div",{role:"alert",ref:p,className:`${l}__toast-content-container`,"data-testid":`container-${v||"default"}`,onMouseEnter:()=>{c&&o.pause(r)},onMouseLeave:()=>{c&&o.resume(r)},children:(0,I.jsxs)(F,{condition:d!=="custom",children:[(0,I.jsx)(j,{children:(0,I.jsxs)("div",{className:u??`${l}__toast-content ${o.isActive(r)?"":y}`,style:f,children:[R&&(0,I.jsx)("span",{className:`${l}__toast-icon`,children:R}),S]})}),(0,I.jsx)(q,{children:S})]})})});var K=require("react");var V=()=>(0,K.useSyncExternalStore)(h.subscribe.bind(h),h.getSnapShot.bind(h),h.getSnapShot.bind(h));var C=require("react/jsx-runtime");function mt({className:t,style:e,limit:n,position:p="top-center",containerId:r="",gap:T=9,reverse:m=!1,pauseOnActivate:v=!0}){let u=V(),f=(0,U.useRef)({}),a=(0,U.useRef)({}),i=s=>{var c;return(c=s.target)==null?void 0:c.element},d=u.filter(i),w=u.filter(s=>!i(s)).reduce((s,c)=>{let y=c.position||p;return c.position=y,s[y]=s[y]||[],s[y].push(c),s},{});return(0,C.jsxs)("div",{id:`${l}__root`,"data-container-id":r,children:[d.filter(s=>r?s.containerId===r:!s.containerId).map(s=>(0,C.jsx)(Y,{ref:c=>{let y=s.target;if(!y||!c){delete a.current[s.toastId];return}let S=a.current[s.toastId]||y.element.getBoundingClientRect();a.current[s.toastId]={y:S.y,x:S.x};let[_,k]=y.offset||[0,0];c.style.top=`${S.y+k+window.scrollY}px`,c.style.left=`${S.x+_+window.scrollX}px`},toastProps:s,pauseOnActivate:v},s.toastId)),Object.entries(w).map(([s,c])=>{let y=c.filter(_=>r?_.containerId===r:!_.containerId).slice(0,n),S=m?y.reverse():y;return(0,C.jsx)("div",{"data-testid":s,className:`${`${l}__z9999`} ${t??`${l}__toast-container ${l}__${s}`}`,style:e,children:S.map((_,k,R)=>(0,C.jsx)(Y,{ref:N=>{if(!N){delete f.current[_.toastId];return}let Q=f.current[_.toastId]||N.getBoundingClientRect().height;f.current[_.toastId]=Q;let Z=/left/.test(s)?50:/center/.test(s)?0:-50,tt=/bottom/.test(s)?0:1,et=R.filter((H,M)=>M<=k-tt).reduce((H,M)=>/bottom/.test(s)?H-=T+f.current[M.toastId]:H+=T+f.current[M.toastId],0);N.style.transition="transform 0.2s cubic-bezier(0.43, 0.14, 0.2, 1.05)",N.style.transform=`translate(${Z}%, ${et}px)`},toastProps:_,pauseOnActivate:v},_.toastId))},s)})]})}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var
|
|
2
|
+
var D=()=>{let t=0;return()=>`react-strawberry-toast_${t++}`};var P=class{state=[];listeners=new Set;activatedToasts=new Set;toastTimers=new Map;constructor(){}subscribe(o){return this.listeners.add(o),()=>{this.listeners.delete(o)}}setState(o){this.state=typeof o=="function"?o(this.state):o,this.listeners.forEach(n=>n())}getSnapShot(){return this.state}};var l="react-strawberry-toast";import{jsx as g,jsxs as rt}from"react/jsx-runtime";function tt(){return rt("svg",{stroke:"none",fill:"none",strokeWidth:"2",viewBox:"0 0 24 24",strokeLinecap:"round",strokeLinejoin:"round",height:"22",width:"22",xmlns:"http://www.w3.org/2000/svg",children:[g("path",{stroke:"none",d:"M0 0h24v24H0z"}),g("path",{d:"M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-1.293 5.953a1 1 0 0 0 -1.32 -.083l-.094 .083l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.403 1.403l.083 .094l2 2l.094 .083a1 1 0 0 0 1.226 0l.094 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z",strokeWidth:"0",fill:"#1dca82"})]})}function et(){return g("svg",{stroke:"none",fill:"#eb2639",strokeWidth:"2",viewBox:"0 0 24 24",height:"22",width:"22",xmlns:"http://www.w3.org/2000/svg",children:g("path",{d:"M11.953 2C6.465 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.493 2 11.953 2zM13 17h-2v-2h2v2zm0-4h-2V7h2v6z"})})}function at(){return g("svg",{stroke:"none",fill:"#fcba03",strokeWidth:"0",viewBox:"0 0 1024 1024",height:"22",width:"22",xmlns:"http://www.w3.org/2000/svg",children:g("path",{d:"M955.7 856l-416-720c-6.2-10.7-16.9-16-27.7-16s-21.6 5.3-27.7 16l-416 720C56 877.4 71.4 904 96 904h832c24.6 0 40-26.6 27.7-48zM480 416c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v184c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V416zm32 352a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z"})})}var v={success:g(tt,{}),error:g(et,{}),loading:g("div",{className:`${l}__loading`}),warn:g(at,{})};var W=t=>{let o=e=>{let i=t.toastTimers.get(e);clearTimeout(i),t.toastTimers.delete(e)},n=e=>{t.activatedToasts.add(e)},m=e=>t.activatedToasts.has(e),s=(e,i=200)=>{m(e)&&(t.activatedToasts.delete(e),setTimeout(()=>{t.state=t.state.filter(d=>d.toastId!==e),t.setState([...t.state])},i),o(e))},T=()=>{t.setState([])},p=(e,i,d)=>{t.state=t.state.map(h=>h.toastId===e?{...h,...d,updated:new Date().getTime(),data:i}:h),t.setState([...t.state])},_=e=>{let i=new Date().getTime();t.state=t.state.map(d=>d.toastId===e?{...d,pausedAt:i}:d),o(e)},u=(e,i)=>{let d=setTimeout(()=>{var r;t.state=t.state.map(c=>c.toastId===e?{...c,isVisible:!1}:c),t.setState([...t.state]);let h=(r=t.state.find(c=>c.toastId===e))==null?void 0:r.removeTimeOut;s(e,h)},i>2147483647?2147483647:i);t.toastTimers.set(e,d)};return{setActive:n,isActive:m,disappear:u,resume:e=>{if(t.toastTimers.has(e))return;let i=t.state.find(h=>h.toastId===e);if(!i)return;let d=i.createdAt+(i.timeOut||3e3)-(i.pausedAt||0);u(e,d)},pause:_,replace:p,remove:s,allClear:T}};var w=new P,ot=D(),I=(t="default")=>(o,n={})=>{let{timeOut:m=3e3,removeTimeOut:s=200,pauseOnHover:T=!0,toastId:p,className:_,style:u,target:f}=n,e=p||ot();if(a.isActive(e))throw new Error("A duplicate custom ID is not available.");let i=new Date().getTime(),d={updated:null,pausedAt:null,className:_||null,style:u||{},icon:n.icon||null,containerId:n.containerId||null,position:n.position||null,timeOut:m>2147483647?2147483647:m,toastId:e,data:o,createdAt:i,toastType:t,pauseOnHover:T,removeTimeOut:s,target:f||null,isVisible:!0};return w.state.push(d),w.setState([...w.state]),e},a=(t,o={})=>I()(t,o),E=W(w);a.setActive=E.setActive;a.isActive=E.isActive;a.disappear=E.disappear;a.resume=E.resume;a.pause=E.pause;a.replace=E.replace;a.remove=E.remove;a.allClear=E.allClear;a.success=I("success");a.error=I("error");a.warn=I("warn");a.loading=I("loading");a.custom=I("custom");a.promise=(t,o,n={})=>{let{loading:m,success:s,error:T}=o,p=a.loading(m,{...n,timeOut:2147483647}),_={toastId:p,close:()=>a.disappear(p,0),immediatelyClose:()=>{a.disappear(p,0),a.remove(p,0)},icons:{success:v.success,error:v.error,warn:v.warn,loading:v.loading},isVisible:!0},u=n.timeOut||=3e3;t.then(f=>{a.replace(p,typeof s=="function"?s(f,_):s,{...n,timeOut:u>2147483647?2147483647:u,toastType:"success"})}).catch(f=>{a.replace(p,typeof T=="function"?T(f,_):T,{...n,timeOut:u>2147483647?2147483647:u,toastType:"error"})})};import{useRef as q}from"react";import{useEffect as G,forwardRef as it}from"react";import{Children as st}from"react";function Y({condition:t,children:o}){let n=st.toArray(o);if(n.length>2)throw new Error("The number of children exceeds two.");return n.find(m=>t?m.key===".0":m.key===".1")}function V({children:t}){return t}function U({children:t}){return t}var B=({isVisible:t,position:o})=>o?t?/top/i.test(o)?`${l}__fade-in`:`${l}__fade-in-reverse`:/bottom/i.test(o)?`${l}__fade-out-reverse`:`${l}__fade-out`:t?`${l}__fade-in`:`${l}__fade-out`;import{useEffect as X,useRef as nt}from"react";var z=(t,o)=>{let n=nt(o);X(()=>{n.current=o},[o]),X(()=>(window.addEventListener(t,n.current),()=>{window.removeEventListener(t,n.current)}),[t])};import{jsx as N,jsxs as F}from"react/jsx-runtime";var H=it(function({toastProps:o,pauseOnActivate:n},m){let{toastId:s,isVisible:T,timeOut:p,containerId:_,className:u,style:f,icon:e,updated:i,toastType:d,position:h,data:r,pauseOnHover:c}=o,y=B({isVisible:T,position:h}),S=typeof r=="function"?r({toastId:s,close:()=>a.disappear(s,0),immediatelyClose:()=>{a.disappear(s,0),a.remove(s,0)},icons:{success:v.success,error:v.error,warn:v.warn,loading:v.loading},isVisible:T}):r,b=()=>{n&&a.resume(s)},A=()=>{n&&a.pause(s)};z("focus",b),z("blur",A),G(()=>{a.isActive(s)||(a.setActive(s),a.disappear(s,p))},[s]),G(()=>{i!==null&&a.disappear(s,p)},[i]);let C=e||(d==="custom"||d==="default"?null:v[d]);return N("div",{role:"alert",ref:m,className:`${l}__toast-content-container`,"data-testid":`container-${_||"default"}`,onMouseEnter:()=>{c&&a.pause(s)},onMouseLeave:()=>{c&&a.resume(s)},children:F(Y,{condition:d!=="custom",children:[N(V,{children:F("div",{className:u??`${l}__toast-content ${a.isActive(s)?"":y}`,style:f,children:[C&&N("span",{className:`${l}__toast-icon`,children:C}),S]})}),N(U,{children:S})]})})});import{useSyncExternalStore as ct}from"react";var j=()=>ct(w.subscribe.bind(w),w.getSnapShot.bind(w),w.getSnapShot.bind(w));import{jsx as L,jsxs as dt}from"react/jsx-runtime";function Jt({className:t,style:o,limit:n,position:m="top-center",containerId:s="",gap:T=9,reverse:p=!1,pauseOnActivate:_=!0}){let u=j(),f=q({}),e=q({}),i=r=>{var c;return(c=r.target)==null?void 0:c.element},d=u.filter(i),h=u.filter(r=>!i(r)).reduce((r,c)=>{let y=c.position||m;return c.position=y,r[y]=r[y]||[],r[y].push(c),r},{});return dt("div",{id:`${l}__root`,"data-container-id":s,children:[d.filter(r=>s?r.containerId===s:!r.containerId).map(r=>L(H,{ref:c=>{let y=r.target;if(!y||!c){delete e.current[r.toastId];return}let S=e.current[r.toastId]||y.element.getBoundingClientRect();e.current[r.toastId]={y:S.y,x:S.x};let[b,A]=y.offset||[0,0];c.style.top=`${S.y+A+window.scrollY}px`,c.style.left=`${S.x+b+window.scrollX}px`},toastProps:r,pauseOnActivate:_},r.toastId)),Object.entries(h).map(([r,c])=>{let y=c.filter(b=>s?b.containerId===s:!b.containerId).slice(0,n),S=p?y.reverse():y;return L("div",{"data-testid":r,className:`${`${l}__z9999`} ${t??`${l}__toast-container ${l}__${r}`}`,style:o,children:S.map((b,A,C)=>L(H,{ref:k=>{if(!k){delete f.current[b.toastId];return}let J=f.current[b.toastId]||k.getBoundingClientRect().height;f.current[b.toastId]=J;let K=/left/.test(r)?50:/center/.test(r)?0:-50,Q=/bottom/.test(r)?0:1,Z=C.filter((M,O)=>O<=A-Q).reduce((M,O)=>/bottom/.test(r)?M-=T+f.current[O.toastId]:M+=T+f.current[O.toastId],0);k.style.transition="transform 0.2s cubic-bezier(0.43, 0.14, 0.2, 1.05)",k.style.transform=`translate(${K}%, ${Z}px)`},toastProps:b,pauseOnActivate:_},b.toastId))},r)})]})}export{Jt as ToastContainer,a as toast,w as toastStore,j as useToasts};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@keyframes l3{to{transform:rotate(1turn)}}@keyframes react-strawberry-toast_fade-in{0%{transform:translateY(-100%) scale(.
|
|
1
|
+
@keyframes l3{to{transform:rotate(1turn)}}@keyframes react-strawberry-toast_fade-in{0%{transform:translateY(-100%) scale(.2);opacity:.2}to{transform:translateY(0) scale(1);opacity:1}}@keyframes react-strawberry-toast_fade-out{0%{transform:translateY(0);opacity:1}to{transform:translateY(-100%);opacity:.2}}@keyframes react-strawberry-toast_fade-in-reverse{0%{transform:translateY(100%) scale(.2);opacity:.2}to{transform:translateY(0) scale(1);opacity:1}}@keyframes react-strawberry-toast_fade-out-reverse{0%{transform:translateY(0);opacity:1}to{transform:translateY(100%);opacity:.2}}.react-strawberry-toast__z9999{z-index:9999}.react-strawberry-toast__toast-container{width:100%;position:fixed;z-index:9999;display:flex;align-items:center;flex-direction:column}.react-strawberry-toast__top-left{top:16px;left:calc(-50% + 16px)}.react-strawberry-toast__top-center{top:16px;left:50%;transform:translate(-50%)}.react-strawberry-toast__top-right{top:16px;right:calc(-50% + 16px)}.react-strawberry-toast__bottom-left{bottom:8px;left:calc(-50% + 16px)}.react-strawberry-toast__bottom-center{bottom:8px;left:50%;transform:translate(-50%)}.react-strawberry-toast__bottom-right{bottom:8px;right:calc(-50% + 16px)}.react-strawberry-toast__toast-content-container{position:absolute;pointer-events:none}.react-strawberry-toast__toast-content{pointer-events:auto;box-sizing:border-box;background-color:#fff;padding:10px;display:flex;align-items:center;gap:5px;border-radius:8px;box-shadow:2px 4px 10px #0000001a;min-height:47px;max-width:368px}.react-strawberry-toast__toast-icon{width:22px;height:22px;display:flex;align-items:center;justify-content:center}.react-strawberry-toast__fade-in{animation:react-strawberry-toast_fade-in .3s cubic-bezier(.43,.14,.2,1.05)}.react-strawberry-toast__fade-out{animation:react-strawberry-toast_fade-out .3s cubic-bezier(.43,.14,.2,1.05)}.react-strawberry-toast__fade-in-reverse{animation:react-strawberry-toast_fade-in-reverse .3s cubic-bezier(.43,.14,.2,1.05)}.react-strawberry-toast__fade-out-reverse{animation:react-strawberry-toast_fade-out-reverse .3s cubic-bezier(.43,.14,.2,1.05)}.react-strawberry-toast__loading{width:18px;padding:3.5px;aspect-ratio:1;border-radius:50%;background:#6f6f70;--_m: conic-gradient(#0000 10%, #000), linear-gradient(#000 0 0) content-box;-webkit-mask:var(--_m);mask:var(--_m);-webkit-mask-composite:source-out;mask-composite:subtract;animation:l3 1s infinite linear}
|