sonner 0.0.1 → 0.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Emil Kowalski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,179 @@
1
- # react-temps
1
+ https://user-images.githubusercontent.com/36730035/220868994-f0c92862-7e7d-487c-ab3a-540e7b48ab4a.mp4
2
2
 
3
- An opinionated toast component for React.
3
+ # Introduction
4
+
5
+ [Sonner](https://sonner.emilkowal.ski/) is an opinionated toast component for React. It's customizable, but styled by default. Comes with a swipe to dismiss animation.
4
6
 
5
7
  ## Usage
6
8
 
7
- `npm install react-temps`
9
+ To start using the library, install it in your project:
10
+
11
+ ```bash
12
+ npm install sonner
13
+ ```
14
+
15
+ Add `<Toaster />` to your app, it will be the place where all your toasts will be rendered.
16
+ After that you can use `toast()` from anywhere in your app.
17
+
18
+ ```jsx
19
+ import { Toaster, toast } from 'sonner';
20
+
21
+ // ...
22
+
23
+ function App() {
24
+ return (
25
+ <div>
26
+ <Toaster />
27
+ <button onClick={() => toast('My first toast')}>Give me a toast</button>
28
+ </div>
29
+ );
30
+ }
31
+ ```
32
+
33
+ ## Types
34
+
35
+ ### Default
36
+
37
+ Most basic toast. You can customize it (and any other type) by passing an options object as the second argument.
38
+
39
+ ```jsx
40
+ toast('Event has been created');
41
+ ```
42
+
43
+ With icon and description:
44
+
45
+ ```jsx
46
+ toast('Event has been created', {
47
+ description: 'Monday, January 3rd at 6:00pm',
48
+ icon: <MyIcon />,
49
+ });
50
+ ```
51
+
52
+ ### Success
53
+
54
+ Render a checkmark icon in front of the message.
55
+
56
+ ```jsx
57
+ toast.success('Event has been created');
58
+ ```
59
+
60
+ ### Error
61
+
62
+ Renders an error icon in front of the message.
63
+
64
+ ```jsx
65
+ toast.error('Event has not been created');
66
+ ```
67
+
68
+ ### Action
69
+
70
+ Renders a button.
71
+
72
+ ```jsx
73
+ toast('Event has been created', {
74
+ action: {
75
+ label: 'Undo',
76
+ onClick: () => console.log('Undo'),
77
+ },
78
+ });
79
+ ```
80
+
81
+ ### Promise
82
+
83
+ Starts in a loading state and will update automatically after the promise resolves or fails.
84
+
85
+ ```jsx
86
+ toast.promise(() => new Promise((resolve) => setTimeout(resolve, 2000)), {
87
+ loading: 'Loading',
88
+ success: 'Success',
89
+ error: 'Error',
90
+ });
91
+ ```
92
+
93
+ ### Custom
94
+
95
+ Render custom JSX.
96
+
97
+ ```jsx
98
+ toast.custom(() => <div>This is a custom component</div>);
99
+ ```
100
+
101
+ ## Customization
102
+
103
+ ### Theme
104
+
105
+ You can change the theme using the `theme` prop. Default theme is light.
106
+
107
+ ```jsx
108
+ <Toaster theme="dark" />
109
+ ```
110
+
111
+ ### Position
112
+
113
+ You can change the position through the `position` prop on the `<Toaster />` component. Default is `bottom-right`.
114
+
115
+ ```jsx
116
+ // Available positions
117
+ // top-left, top-center, top-right, bottom-left, bottom-center, bottom-right
118
+
119
+ <Toaster position="top-center" />
120
+ ```
121
+
122
+ ### Expanded
123
+
124
+ Toasts can also be expanded by default through the `expand` prop. You can also change the amount of visible toasts which is 3 by default.
125
+
126
+ ```jsx
127
+ <Toaster expand visibleToasts={9} />
128
+ ```
129
+
130
+ ### Styling for all toasts
131
+
132
+ You can style your toasts globally with the `toastOptions` prop in the `Toaster` component.
133
+
134
+ ```jsx
135
+ <Toaster toastOptions={{ style: { background: 'red' }, className: 'my-toast' }} />
136
+ ```
137
+
138
+ ### Styling for individual toast
139
+
140
+ ```jsx
141
+ toast('Event has been created', {
142
+ style: {
143
+ background: 'red',
144
+ },
145
+ className: 'my-toast',
146
+ });
147
+ ```
148
+
149
+ ### Close button
150
+
151
+ Add a close button to all toasts that shows on hover by adding the `closeButton` prop.
152
+
153
+ ```jsx
154
+ <Toaster closeButton />
155
+ ```
156
+
157
+ ### Rich colors
158
+
159
+ You can make error and success state more colorful by adding the `richColors` prop.
160
+
161
+ ```jsx
162
+ <Toaster richColors />
163
+ ```
164
+
165
+ ### Custom offset
166
+
167
+ Offset from the edges of the screen.
168
+
169
+ ```jsx
170
+ <Toaster offset="80px" />
171
+ ```
172
+
173
+ ## Keyboard focus
174
+
175
+ You can focus on the toast area by pressing ⌥/alt + T. You can override it by providing an array of event.code values for each key.
176
+
177
+ ```jsx
178
+ <Toaster hotkey={['KeyC']} />
179
+ ```
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ type PromiseData = {
6
6
  success: string | React.ReactNode;
7
7
  error: string | React.ReactNode;
8
8
  };
9
- type PromiseT = () => Promise<any>;
9
+ type PromiseT = Promise<any> | (() => Promise<any>);
10
10
  interface ToastT {
11
11
  id: number;
12
12
  title?: string;
@@ -41,13 +41,25 @@ declare const toast: ((message: string, data?: ExternalToast) => void) & {
41
41
  promise: (promise: PromiseT, data?: PromiseData) => void;
42
42
  };
43
43
 
44
+ interface ToastOptions {
45
+ className?: string;
46
+ style?: React.CSSProperties;
47
+ }
44
48
  interface ToasterProps {
45
49
  invert?: boolean;
50
+ theme?: 'light' | 'dark';
46
51
  position?: Position;
47
52
  hotkey?: string[];
53
+ richColors?: boolean;
48
54
  expand?: boolean;
49
- dismissable?: boolean;
55
+ duration?: number;
56
+ visibleToasts?: number;
57
+ closeButton?: boolean;
58
+ toastOptions?: ToastOptions;
59
+ className?: string;
60
+ style?: React.CSSProperties;
61
+ offset?: number;
50
62
  }
51
63
  declare const Toaster: (props: ToasterProps) => JSX.Element;
52
64
 
53
- export { Toaster as default, toast };
65
+ export { Toaster, toast };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  "use client"
2
- import e from"react";function U(r,{insertAt:o}={}){if(!r||typeof document=="undefined")return;let t=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css",o==="top"&&t.firstChild?t.insertBefore(i,t.firstChild):t.appendChild(i),i.styleSheet?i.styleSheet.cssText=r:i.appendChild(document.createTextNode(r))}U(`.toaster{position:fixed;width:var(--width);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;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 6px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999}.toaster[data-x-position=right]{right:var(--offset)}.toaster[data-x-position=left]{left:var(--offset)}.toaster[data-x-position=center]{left:50%;transform:translate(-50%)}.toaster[data-y-position=top]{top:var(--offset)}.toaster[data-y-position=bottom]{bottom:var(--offset)}[data-react-temps-toast]{--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));--background: white;--border-color: var(--gray3);--color: var(--gray12);z-index:var(--z-index);display:flex;align-items:center;gap:6px;position:absolute;opacity:0;transform:var(--y);padding:16px;background:var(--background);border:1px solid var(--border-color);color:var(--color);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;touch-action:none;will-change:transform,opacity,height;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none}[data-react-temps-toast][data-invert=true]{--background: var(--gray12);--border-color: var(--gray11);--color: var(--gray1)}[data-react-temps-toast]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-react-temps-toast][data-y-position=top]{top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}[data-react-temps-toast][data-y-position=bottom]{bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}[data-react-temps-toast] [data-description]{font-weight:400;line-height:1.4;color:var(--color)}[data-react-temps-toast] [data-title]{font-weight:500;color:var(--color)}[data-react-temps-toast] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:-3px;margin-right:4px}[data-react-temps-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);animation:fade-in .3s ease forwards}[data-react-temps-toast] [data-icon]>*{flex-shrink:0}[data-react-temps-toast] [data-content]{display:flex;flex-direction:column;gap:2px}[data-react-temps-toast] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--background);background:var(--color);border:none;cursor:pointer;outline:none;transition:opacity .4s,box-shadow .2s}[data-react-temps-toast] [data-button]:focus-visible{box-shadow:0 0 0 2px #0006}[data-react-temps-toast] [data-button]:first-of-type{margin-left:auto}[data-react-temps-toast] [data-cancel]{color:var(--color);background:var(--border-color)}[data-react-temps-toast] [data-close-button]{position:absolute;left:0;top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;background:var(--gray1);border:1px solid var(--gray4);transform:translate(-35%,-35%);border-radius:50%;opacity:0;cursor:pointer;transition:opacity .1s,background .2s,border-color .2s}[data-react-temps-toast]:hover [data-close-button]{opacity:1}[data-react-temps-toast]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-react-temps-toast][data-swiping=true]:before{content:"";position:absolute;top:50%;left:0;right:0;height:100%;transform:scaleX(3) translateY(-50%)}[data-react-temps-toast][data-swiping=false][data-removed=true]:before{content:"";position:absolute;inset:0;transform:scaleY(2)}[data-react-temps-toast]:after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-react-temps-toast][data-mounted=true]{--y: translateY(0);opacity:1}[data-react-temps-toast][data-expanded=false][data-front=false]{--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-react-temps-toast]>*{transition:opacity .4s}[data-react-temps-toast][data-expanded=false][data-front=false]>*{opacity:0}[data-react-temps-toast][data-visible=false]{opacity:0;pointer-events:none}[data-react-temps-toast][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-react-temps-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y: translateY(100%);opacity:0}[data-react-temps-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset) + 150%));opacity:0;transtion:transform .2s,opacity .1s}[data-react-temps-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{opacity:0;transtion:opacity .2s}[data-react-temps-toast][data-removed=true][data-front=false]:before{height:calc(var(--initial-height) + 20%)}[data-react-temps-toast][data-swiping=true]{transform:var(--y) translate(var(--swipe-amount, 0px));transition:none}[data-react-temps-toast][data-swipe-out=true][data-x-position=right],[data-react-temps-toast][data-swipe-out=true][data-x-position=center]{animation:swipe-out-right .2s ease-out}[data-react-temps-toast][data-swipe-out=true][data-x-position=left]{animation:swipe-out-left .2s ease-out}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount, 0px));opacity:1}to{transform:var(--y) translate(-100%);opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount, 0px));opacity:1}to{transform:var(--y) translate(100%);opacity:0}}@media (max-width: 600px){.toaster{position:fixed;bottom:20px;right:20px;left:20px;width:100%}[data-react-temps-toast]{bottom:0;width:calc(100% - 40px)}}.react-temps-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.react-temps-loading-wrapper[data-visible=false]{animation:fade-out .2s ease forwards}.react-temps-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.react-temps-loading-bar{animation:spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.react-temps-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.react-temps-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.react-temps-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.react-temps-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.react-temps-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.react-temps-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.react-temps-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.react-temps-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.react-temps-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.react-temps-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.react-temps-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.react-temps-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-react-temps-toast],[data-react-temps-toast]>*,.react-temps-loading-bar{transition:none!important;animation:none!important}}
3
- `);import g from"react";var W=r=>{switch(r){case"success":return rt;case"error":return it;default:}},st=Array(12).fill(0),J=({visible:r})=>g.createElement("div",{className:"react-temps-loading-wrapper","data-visible":r},g.createElement("div",{className:"react-temps-spinner"},st.map((o,t)=>g.createElement("div",{className:"react-temps-loading-bar",key:`spinner-bar-${t}`})))),rt=g.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},g.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"}));var it=g.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},g.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"}));var E=0,$=class{constructor(){this.subscribe=o=>(this.subscribers.push(o),()=>{let t=this.subscribers.indexOf(o);this.subscribers.splice(t,1)});this.publish=o=>{this.subscribers.forEach(t=>t(o))};this.message=(o,t)=>{this.publish({...t,id:E++,title:o})};this.error=(o,t)=>{this.publish({...t,id:E++,type:"error",title:o})};this.success=(o,t)=>{this.publish({...t,id:E++,type:"success",title:o})};this.promise=(o,t)=>{this.publish({promiseData:t,promise:o,id:E++})};this.custom=o=>{let t=E++;this.publish({jsx:o(t),id:t})};this.subscribers=[]}},m=new $,nt=(r,o)=>{m.publish({title:r,...o,id:E++})},lt=nt,dt=Object.assign(lt,{success:m.success,error:m.error,custom:m.custom,message:m.message,promise:m.promise});var ct=3,pt=32,mt=4e3,ut=356,G=14,ft=40,gt=200,ht=r=>{var V;let{invert:o,toast:t,interacting:i,setHeights:u,heights:h,index:l,toasts:P,expanded:b,removeToast:C,dismissable:A,position:p,expandByDefault:f}=r,[S,L]=e.useState(!1),[M,y]=e.useState(!1),[O,z]=e.useState(!1),[k,d]=e.useState(!1),[s,v]=e.useState(null),[H,I]=e.useState(0),[q,Q]=e.useState(0),x=e.useRef(null),Z=l===0,tt=l+1<=ct,F=t.type,N=e.useMemo(()=>h.findIndex(a=>a.toastId===t.id)||0,[h,t.id]),j=e.useMemo(()=>t.duration||mt,[t.duration]),Y=e.useRef(0),K=e.useRef(j),B=e.useRef(null),[et,_]=p.split("-"),X=e.useMemo(()=>h.reduce((a,n,c)=>c>=N?a:a+n.height,0),[h,N]),at=t.invert||o,R=e.useMemo(()=>N*G+X,[N,X]);e.useEffect(()=>{L(!0)},[]),e.useEffect(()=>{t.promise&&(v("loading"),t.promise().then(()=>{v("success")}).catch(()=>{v("error")}))},[t.promise]);let w=e.useCallback(()=>{y(!0),u(a=>a.filter(n=>n.toastId!==t.id)),setTimeout(()=>{C(t)},gt)},[t,C,u]);e.useEffect(()=>{if(t.promise&&s==="loading")return;let a;return!b&&!i||f?(()=>{Y.current||(Y.current=new Date().getTime()),a=setTimeout(()=>{w()},K.current)})():(()=>{let T=new Date().getTime(),D=Y.current+j-T;K.current=D})(),()=>clearTimeout(a)},[b,f,t,j,w,t.promise,s,i]),e.useEffect(()=>{let a=x.current;if(a){let n=a.getBoundingClientRect().height;return Q(n),u(c=>[{toastId:t.id,height:n},...c]),()=>u(c=>c.filter(T=>T.toastId!==t.id))}},[u,t.id]);let ot=e.useMemo(()=>{switch(s){case"loading":return t.promiseData.loading;case"success":return t.promiseData.success;case"error":return t.promiseData.error;default:return null}},[t.promiseData,s]);return e.createElement("li",{"aria-live":t.important?"assertive":"polite","aria-atomic":"true",role:"status",tabIndex:0,ref:x,className:t.className,"data-react-temps-toast":"","data-mounted":S,"data-promise":Boolean(t.promise),"data-removed":M,"data-visible":tt,"data-y-position":et,"data-x-position":_,"data-index":l,"data-front":Z,"data-swiping":O,"data-type":F,"data-invert":at,"data-swipe-out":k,"data-expanded":Boolean(b||f&&S),style:{"--index":l,"--toasts-before":l,"--z-index":P.length-l,"--offset":`${M?H:R}px`,"--initial-height":f?"auto":`${q}px`,...t.style},onPointerDown:a=>{I(R),a.target.setPointerCapture(a.pointerId),a.target.tagName!=="BUTTON"&&(z(!0),B.current=a.clientX)},onPointerUp:()=>{var n,c;if(k)return;let a=Number(((n=x.current)==null?void 0:n.style.getPropertyValue("--swipe-amount").replace("px",""))||0);if(Math.abs(a)>=ft){I(R),w(),d(!0);return}(c=x.current)==null||c.style.setProperty("--swipe-amount","0px"),B.current=null,z(!1)},onPointerMove:a=>{var T,D;if(!B.current)return;let n=a.clientX-B.current;if(_==="right"||_==="center"?n<0:n>0){(T=x.current)==null||T.style.setProperty("--swipe-amount","0px");return}(D=x.current)==null||D.style.setProperty("--swipe-amount",`${n}px`)}},A?e.createElement("button",{"aria-label":"Close toast","data-close-button":!0,onClick:w},e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"}))):null,t.jsx?t.jsx:e.createElement(e.Fragment,null,F||t.icon||t.promise?e.createElement("div",{"data-icon":""},t.promise?e.createElement(J,{visible:s==="loading"}):null,t.icon||W(s!=null?s:t.type)):null,e.createElement("div",{"data-content":""},e.createElement("div",{"data-title":""},(V=t.title)!=null?V:ot),t.description?e.createElement("div",{"data-description":""},t.description):null),t.cancel?e.createElement("button",{"data-button":!0,"data-cancel":!0,onClick:()=>{var a;w(),(a=t.cancel)!=null&&a.onClick&&t.cancel.onClick()}},t.cancel.label):null,t.action?e.createElement("button",{"data-button":"",onClick:()=>{var a;w(),(a=t.action)==null||a.onClick()}},t.action.label):null))},bt=r=>{var k;let{invert:o,position:t="bottom-right",hotkey:i=["altKey","KeyT"],expand:u,dismissable:h}=r,[l,P]=e.useState([]),[b,C]=e.useState([]),[A,p]=e.useState(!1),[f,S]=e.useState(!1),[L,M]=t.split("-"),y=e.useRef(null),O=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),z=e.useCallback(d=>P(s=>s.filter(({id:v})=>v!==d.id)),[]);return e.useEffect(()=>m.subscribe(d=>{P(s=>[d,...s])}),[]),e.useEffect(()=>{l.length<=1&&p(!1)},[l]),e.useEffect(()=>{let d=s=>{var H;i.every(I=>s[I]||s.code===I)&&(p(!0),(H=y.current)==null||H.focus()),s.code==="Escape"&&(document.activeElement===y.current||y.current.contains(document.activeElement))&&p(!1)};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[i]),e.createElement("div",{role:"region","aria-label":`Notifications ${O}`,tabIndex:-1},e.createElement("ol",{tabIndex:-1,ref:y,className:"toaster","data-y-position":L,"data-x-position":M,style:{"--front-toast-height":`${(k=b[0])==null?void 0:k.height}px`,"--offset":`${pt}px`,"--width":`${ut}px`,"--gap":`${G}px`},onMouseEnter:()=>p(!0),onMouseMove:()=>p(!0),onMouseLeave:()=>{f||p(!1)},onPointerDown:()=>{S(!0)},onPointerUp:()=>S(!1)},l.map((d,s)=>e.createElement(ht,{key:d.id,index:s,toast:d,invert:o,dismissable:h,interacting:f,position:t,removeToast:z,toasts:l,heights:b,setHeights:C,expandByDefault:u,expanded:A}))))};var Pt=bt;export{Pt as default,dt as toast};
2
+ import e from"react";function J(s,{insertAt:o}={}){if(!s||typeof document=="undefined")return;let t=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",o==="top"&&t.firstChild?t.insertBefore(r,t.firstChild):t.appendChild(r),r.styleSheet?r.styleSheet.cssText=s:r.appendChild(document.createTextNode(s))}J(`[data-sonner-toaster]{position:fixed;width:var(--width);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;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 6px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999}[data-sonner-toaster][data-x-position=right]{right:max(var(--offset),env(safe-area-inset-right))}[data-sonner-toaster][data-x-position=left]{left:max(var(--offset),env(safe-area-inset-left))}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translate(-50%)}[data-sonner-toaster][data-y-position=top]{top:max(var(--offset),env(safe-area-inset-top))}[data-sonner-toaster][data-y-position=bottom]{bottom:max(var(--offset),env(safe-area-inset-bottom))}[data-sonner-toast]{--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);display:flex;align-items:center;gap:6px;position:absolute;opacity:0;transform:var(--y);padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;touch-action:none;will-change:transform,opacity,height;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-sonner-toast][data-y-position=top]{top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}[data-sonner-toast] [data-description]{font-weight:400;line-height:1.4;color:inherit}[data-sonner-toast] [data-title]{font-weight:500;color:inherit}[data-sonner-toast] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:-3px;margin-right:4px}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);animation:sonner-fade-in .3s ease forwards}[data-sonner-toast] [data-icon]>*{flex-shrink:0}[data-sonner-toast] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:auto;border:none;cursor:pointer;outline:none;transition:opacity .4s,box-shadow .2s}[data-sonner-toast] [data-button]:focus-visible{box-shadow:0 0 0 2px #0006}[data-sonner-toast] [data-button]:first-of-type{margin-left:auto}[data-sonner-toast] [data-cancel]{color:var(--color);background:var(--border-color)}[data-sonner-toast] [data-close-button]{position:absolute;left:0;top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;background:var(--gray1);color:var(--gray12);border:1px solid var(--gray4);transform:translate(-35%,-35%);border-radius:50%;opacity:0;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast]:hover [data-close-button]{opacity:1}[data-sonner-toast]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]:before{content:"";position:absolute;left:0;right:0;height:100%}[data-sonner-toast][data-y-position=top][data-swiping=true]:before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]:before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]:before{content:"";position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast]:after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y: translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-expanded=false][data-front=false]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y: translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{opacity:0}[data-sonner-toast][data-removed=true][data-front=false]:before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount, 0px));transition:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation:swipe-out .2s ease-out forwards}@keyframes swipe-out{0%{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount)));opacity:1}to{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount) + var(--lift) * -100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;--mobile-offset: 16px;right:var(--mobile-offset);left:var(--mobile-offset);width:100%}[data-sonner-toast]{left:0;right:0;width:calc(100% - 32px)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset)}[data-sonner-toaster][data-y-position=bottom]{bottom:20px}[data-sonner-toaster][data-y-position=top]{top:20px}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset);right:var(--mobile-offset);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-rich-colors=true] [data-sonner-toast][data-type=success],[data-rich-colors=true] [data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true] [data-sonner-toast][data-type=error],[data-rich-colors=true] [data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}
3
+ `);import y from"react";var ot=s=>{switch(s){case"success":return pt;case"error":return ft;default:}},ut=Array(12).fill(0),st=({visible:s})=>y.createElement("div",{className:"sonner-loading-wrapper","data-visible":s},y.createElement("div",{className:"sonner-spinner"},ut.map((o,t)=>y.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${t}`})))),pt=y.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},y.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"}));var ft=y.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},y.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"}));var P=0,G=class{constructor(){this.subscribe=o=>(this.subscribers.push(o),()=>{let t=this.subscribers.indexOf(o);this.subscribers.splice(t,1)});this.publish=o=>{this.subscribers.forEach(t=>t(o))};this.message=(o,t)=>{this.publish({...t,id:P++,title:o})};this.error=(o,t)=>{this.publish({...t,id:P++,type:"error",title:o})};this.success=(o,t)=>{this.publish({...t,id:P++,type:"success",title:o})};this.promise=(o,t)=>{this.publish({promiseData:t,promise:o,id:P++})};this.custom=o=>{let t=P++;this.publish({jsx:o(t),id:t})};this.subscribers=[]}},h=new G,mt=(s,o)=>{h.publish({title:s,...o,id:P++})},ht=mt,gt=Object.assign(ht,{success:h.success,error:h.error,custom:h.custom,message:h.message,promise:h.promise});var bt=3,vt="32px",yt=4e3,xt=356,rt=14,Tt=20,wt=200,St=s=>{var et;let{invert:o,toast:t,interacting:r,setHeights:g,visibleToasts:j,heights:x,index:f,toasts:U,expanded:C,removeToast:I,closeButton:_,style:F,className:m="",duration:b,position:N,expandByDefault:T}=s,[M,$]=e.useState(!1),[u,B]=e.useState(!1),[z,H]=e.useState(!1),[D,w]=e.useState(!1),[l,v]=e.useState(null),[Y,i]=e.useState(0),[d,A]=e.useState(0),p=e.useRef(null),L=f===0,nt=f+1<=j,X=t.type,it=t.className||"",O=e.useMemo(()=>x.findIndex(a=>a.toastId===t.id)||0,[x,t.id]),q=e.useMemo(()=>t.duration||b||yt,[t.duration,b]),K=e.useRef(0),S=e.useRef(0),V=e.useRef(q),Q=e.useRef(0),R=e.useRef(null),[Z,lt]=N.split("-"),tt=e.useMemo(()=>x.reduce((a,n,c)=>c>=O?a:a+n.height,0),[x,O]),dt=t.invert||o,W=l==="loading";S.current=e.useMemo(()=>O*rt+tt,[O,tt]),e.useEffect(()=>{$(!0)},[]),e.useEffect(()=>{t.promise&&(v("loading"),t.promise instanceof Promise?t.promise.then(()=>{v("success")}).catch(()=>{v("error")}):typeof t.promise=="function"&&t.promise().then(()=>{v("success")}).catch(()=>{v("error")}))},[t]);let E=e.useCallback(()=>{B(!0),i(S.current),g(a=>a.filter(n=>n.toastId!==t.id)),setTimeout(()=>{I(t)},wt)},[t,I,g,S]);e.useEffect(()=>{if(t.promise&&l==="loading")return;let a;return C||r?(()=>{if(Q.current<K.current){let k=new Date().getTime()-K.current;V.current=V.current-k}Q.current=new Date().getTime()})():(()=>{K.current=new Date().getTime(),a=setTimeout(()=>{E()},V.current)})(),()=>clearTimeout(a)},[C,r,T,t,q,E,t.promise,l]),e.useEffect(()=>{let a=p.current;if(a){let n=a.getBoundingClientRect().height;return A(n),g(c=>[{toastId:t.id,height:n},...c]),()=>g(c=>c.filter(k=>k.toastId!==t.id))}},[g,t.id]);let ct=e.useMemo(()=>{switch(l){case"loading":return t.promiseData.loading;case"success":return t.promiseData.success;case"error":return t.promiseData.error;default:return null}},[t.promiseData,l]);return e.createElement("li",{"aria-live":t.important?"assertive":"polite","aria-atomic":"true",role:"status",tabIndex:0,ref:p,className:m+" "+it,"data-sonner-toast":"","data-mounted":M,"data-promise":Boolean(t.promise),"data-removed":u,"data-visible":nt,"data-y-position":Z,"data-x-position":lt,"data-index":f,"data-front":L,"data-swiping":z,"data-type":X,"data-invert":dt,"data-swipe-out":D,"data-expanded":Boolean(C||T&&M),style:{"--index":f,"--toasts-before":f,"--z-index":U.length-f,"--offset":`${u?Y:S.current}px`,"--initial-height":T?"auto":`${d}px`,...F,...t.style},onPointerDown:a=>{W||(i(S.current),a.target.setPointerCapture(a.pointerId),a.target.tagName!=="BUTTON"&&(H(!0),R.current=a.clientY))},onPointerUp:()=>{var n,c;if(D)return;let a=Number(((n=p.current)==null?void 0:n.style.getPropertyValue("--swipe-amount").replace("px",""))||0);if(Math.abs(a)>=Tt){i(S.current),E(),w(!0);return}(c=p.current)==null||c.style.setProperty("--swipe-amount","0px"),R.current=null,H(!1)},onPointerMove:a=>{var k,at;if(!R.current)return;let n=a.clientY-R.current;if(!(Z==="top"?n<0:n>0)){(k=p.current)==null||k.style.setProperty("--swipe-amount","0px");return}(at=p.current)==null||at.style.setProperty("--swipe-amount",`${n}px`)}},_?e.createElement("button",{"aria-label":"Close toast","data-disabled":W,"data-close-button":!0,onClick:W?void 0:E},e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"}))):null,t.jsx?t.jsx:e.createElement(e.Fragment,null,X||t.icon||t.promise?e.createElement("div",{"data-icon":""},t.promise?e.createElement(st,{visible:l==="loading"}):null,t.icon||ot(l!=null?l:t.type)):null,e.createElement("div",{"data-content":""},e.createElement("div",{"data-title":""},(et=t.title)!=null?et:ct),t.description?e.createElement("div",{"data-description":""},t.description):null),t.cancel?e.createElement("button",{"data-button":!0,"data-cancel":!0,onClick:()=>{var a;E(),(a=t.cancel)!=null&&a.onClick&&t.cancel.onClick()}},t.cancel.label):null,t.action?e.createElement("button",{"data-button":"",onClick:()=>{var a;E(),(a=t.action)==null||a.onClick()}},t.action.label):null))},Ht=s=>{var Y;let{invert:o,position:t="bottom-right",hotkey:r=["altKey","KeyT"],expand:g,closeButton:j,className:x,offset:f,theme:U="light",richColors:C,duration:I,style:_,visibleToasts:F=bt,toastOptions:m}=s,[b,N]=e.useState([]),[T,M]=e.useState([]),[$,u]=e.useState(!1),[B,z]=e.useState(!1),[H,D]=t.split("-"),w=e.useRef(null),l=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),v=e.useCallback(i=>N(d=>d.filter(({id:A})=>A!==i.id)),[]);return e.useEffect(()=>h.subscribe(i=>{N(d=>[i,...d])}),[]),e.useEffect(()=>{b.length<=1&&u(!1)},[b]),e.useEffect(()=>{let i=d=>{var p;r.every(L=>d[L]||d.code===L)&&(u(!0),(p=w.current)==null||p.focus()),d.code==="Escape"&&(document.activeElement===w.current||w.current.contains(document.activeElement))&&u(!1)};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[r]),e.createElement("div",{role:"region","aria-label":`Notifications ${l}`,tabIndex:-1},e.createElement("ol",{tabIndex:-1,ref:w,className:x,"data-sonner-toaster":!0,"data-theme":U,"data-rich-colors":C,"data-y-position":H,"data-x-position":D,style:{"--front-toast-height":`${(Y=T[0])==null?void 0:Y.height}px`,"--offset":f||vt,"--width":`${xt}px`,"--gap":`${rt}px`,..._},onMouseEnter:()=>u(!0),onMouseMove:()=>u(!0),onMouseLeave:()=>{B||u(!1)},onPointerDown:()=>{z(!0)},onPointerUp:()=>z(!1)},b.map((i,d)=>e.createElement(St,{key:i.id,index:d,toast:i,duration:I,className:m==null?void 0:m.className,invert:o,visibleToasts:F,closeButton:j,interacting:B,position:t,style:m==null?void 0:m.style,removeToast:v,toasts:b,heights:T,setHeights:M,expandByDefault:g,expanded:$}))))};export{Ht as Toaster,gt as toast};
4
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.tsx","#style-inject:#style-inject","../src/styles.css","../src/assets.tsx","../src/state.ts"],"sourcesContent":["'use client';\n\nimport React from 'react';\n\nimport './styles.css';\nimport { getAsset, Loader } from './assets';\nimport { HeightT, Position, ToastT } from './types';\nimport { ToastState, toast } from './state';\n\n// Visible toasts amount\nconst VISIBLE_TOASTS_AMOUNT = 3;\n\n// Viewport padding\nconst VIEWPORT_OFFSET = 32;\n\n// Default lifetime of a toasts (in ms)\nconst TOAST_LIFETIME = 4_000;\n\n// Default toast width\nconst TOAST_WIDTH = 356;\n\n// Default gap between toasts\nconst GAP = 14;\n\nconst SWIPE_TRESHOLD = 40;\n\nconst TIME_BEFORE_UNMOUNT = 200;\n\ninterface ToastProps {\n toast: ToastT;\n toasts: ToastT[];\n index: number;\n expanded: boolean;\n invert: boolean;\n heights: HeightT[];\n setHeights: React.Dispatch<React.SetStateAction<HeightT[]>>;\n removeToast: (toast: ToastT) => void;\n position: Position;\n expandByDefault: boolean;\n dismissable: boolean;\n interacting: boolean;\n}\n\nconst Toast = (props: ToastProps) => {\n const {\n invert: ToasterInvert,\n toast,\n interacting,\n setHeights,\n heights,\n index,\n toasts,\n expanded,\n removeToast,\n dismissable,\n position,\n expandByDefault,\n } = props;\n const [mounted, setMounted] = React.useState(false);\n const [removed, setRemoved] = React.useState(false);\n const [swiping, setSwiping] = React.useState(false);\n const [swipeOut, setSwipeOut] = React.useState(false);\n const [promiseStatus, setPromiseStatus] = React.useState<\n 'loading' | 'success' | 'error' | null\n >(null);\n const [offsetBeforeRemove, setOffsetBeforeRemove] = React.useState(0);\n const [initialHeight, setInitialHeight] = React.useState(0);\n const toastRef = React.useRef<HTMLLIElement>(null);\n const isFront = index === 0;\n const isVisible = index + 1 <= VISIBLE_TOASTS_AMOUNT;\n const toastType = toast.type;\n // Height index is used to calculate the offset as it gets updated before the toast array, which means we can calculate the new layout faster.\n const heightIndex = React.useMemo(\n () => heights.findIndex((height) => height.toastId === toast.id) || 0,\n [heights, toast.id]\n );\n const duration = React.useMemo(\n () => toast.duration || TOAST_LIFETIME,\n [toast.duration]\n );\n const closeTimerStartTimeRef = React.useRef(0);\n const closeTimerRemainingTimeRef = React.useRef(duration);\n const pointerStartXRef = React.useRef<number | null>(null);\n const [y, x] = position.split('-');\n const toastsHeightBefore = React.useMemo(() => {\n return heights.reduce((prev, curr, reducerIndex) => {\n // Calculate offset up untill current toast\n if (reducerIndex >= heightIndex) {\n return prev;\n }\n\n return prev + curr.height;\n }, 0);\n }, [heights, heightIndex]);\n const invert = toast.invert || ToasterInvert;\n\n const offset = React.useMemo(\n () => heightIndex * GAP + toastsHeightBefore,\n [heightIndex, toastsHeightBefore]\n );\n\n React.useEffect(() => {\n // Trigger enter animation without using CSS animation\n setMounted(true);\n }, []);\n\n React.useEffect(() => {\n if (toast.promise) {\n setPromiseStatus('loading');\n toast\n .promise()\n .then(() => {\n setPromiseStatus('success');\n })\n .catch(() => {\n setPromiseStatus('error');\n });\n }\n }, [toast.promise]);\n\n const deleteToast = React.useCallback(() => {\n // Save the offset for the exit swipe animation\n setRemoved(true);\n setHeights((h) => h.filter((height) => height.toastId !== toast.id));\n\n setTimeout(() => {\n removeToast(toast);\n }, TIME_BEFORE_UNMOUNT);\n }, [toast, removeToast, setHeights]);\n\n React.useEffect(() => {\n if (toast.promise && promiseStatus === 'loading') return;\n let timeoutId: NodeJS.Timeout;\n\n // Pause the timer on each hover\n const pauseTimer = () => {\n const now = new Date().getTime();\n // Calculate how much time is left (total duration + start time - current time) will give us the remaining time\n const timeRemaining = closeTimerStartTimeRef.current + duration - now;\n closeTimerRemainingTimeRef.current = timeRemaining;\n };\n\n const startTimer = () => {\n if (!closeTimerStartTimeRef.current) {\n closeTimerStartTimeRef.current = new Date().getTime();\n }\n\n timeoutId = setTimeout(() => {\n deleteToast();\n }, closeTimerRemainingTimeRef.current);\n };\n\n // Stop the timer if the toast is expanded/expanded by default or we are interacting with it (e.g. mobile swipe without expand)\n if ((!expanded && !interacting) || expandByDefault) {\n startTimer();\n } else {\n pauseTimer();\n }\n\n return () => clearTimeout(timeoutId);\n }, [\n expanded,\n expandByDefault,\n toast,\n duration,\n deleteToast,\n toast.promise,\n promiseStatus,\n interacting,\n ]);\n\n React.useEffect(() => {\n const toastNode = toastRef.current;\n\n if (toastNode) {\n const height = toastNode.getBoundingClientRect().height;\n\n setInitialHeight(height);\n setHeights((h) => [{ toastId: toast.id, height }, ...h]);\n\n return () =>\n setHeights((h) => h.filter((height) => height.toastId !== toast.id));\n }\n }, [setHeights, toast.id]);\n\n const promiseTitle = React.useMemo(() => {\n switch (promiseStatus) {\n case 'loading':\n return toast.promiseData.loading;\n case 'success':\n return toast.promiseData.success;\n case 'error':\n return toast.promiseData.error;\n default:\n return null;\n }\n }, [toast.promiseData, promiseStatus]);\n\n return (\n <li\n aria-live={toast.important ? 'assertive' : 'polite'}\n aria-atomic=\"true\"\n role=\"status\"\n tabIndex={0}\n ref={toastRef}\n className={toast.className}\n data-react-temps-toast=\"\"\n data-mounted={mounted}\n data-promise={Boolean(toast.promise)}\n data-removed={removed}\n data-visible={isVisible}\n data-y-position={y}\n data-x-position={x}\n data-index={index}\n data-front={isFront}\n data-swiping={swiping}\n data-type={toastType}\n data-invert={invert}\n data-swipe-out={swipeOut}\n data-expanded={Boolean(expanded || (expandByDefault && mounted))}\n style={\n {\n '--index': index,\n '--toasts-before': index,\n '--z-index': toasts.length - index,\n '--offset': `${removed ? offsetBeforeRemove : offset}px`,\n '--initial-height': expandByDefault ? 'auto' : `${initialHeight}px`,\n ...toast.style,\n } as React.CSSProperties\n }\n onPointerDown={(event) => {\n setOffsetBeforeRemove(offset);\n // Ensure we maintain correct pointer capture even when going outside of the toast (e.g. when swiping)\n (event.target as HTMLElement).setPointerCapture(event.pointerId);\n if ((event.target as HTMLElement).tagName === 'BUTTON') return;\n setSwiping(true);\n pointerStartXRef.current = event.clientX;\n }}\n onPointerUp={() => {\n if (swipeOut) return;\n const swipeAmount = Number(\n toastRef.current?.style\n .getPropertyValue('--swipe-amount')\n .replace('px', '') || 0\n );\n\n // Remove only if treshold is met\n if (Math.abs(swipeAmount) >= SWIPE_TRESHOLD) {\n setOffsetBeforeRemove(offset);\n deleteToast();\n setSwipeOut(true);\n return;\n }\n\n toastRef.current?.style.setProperty('--swipe-amount', '0px');\n pointerStartXRef.current = null;\n setSwiping(false);\n }}\n onPointerMove={(event) => {\n if (!pointerStartXRef.current) return;\n const xPosition = event.clientX - pointerStartXRef.current;\n const isAllowedToSwipe =\n x === 'right' || x === 'center' ? xPosition < 0 : xPosition > 0;\n // We don't want to swipe to the left and vice versa depending on toast position\n if (isAllowedToSwipe) {\n toastRef.current?.style.setProperty('--swipe-amount', '0px');\n return;\n }\n\n toastRef.current?.style.setProperty('--swipe-amount', `${xPosition}px`);\n }}\n >\n {dismissable ? (\n <button\n aria-label=\"Close toast\"\n data-close-button\n onClick={deleteToast}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"></line>\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"></line>\n </svg>\n </button>\n ) : null}\n {toast.jsx ? (\n toast.jsx\n ) : (\n <>\n {toastType || toast.icon || toast.promise ? (\n <div data-icon=\"\">\n {toast.promise ? (\n <Loader visible={promiseStatus === 'loading'} />\n ) : null}\n {toast.icon || getAsset(promiseStatus ?? toast.type)}\n </div>\n ) : null}\n\n <div data-content=\"\">\n <div data-title=\"\">{toast.title ?? promiseTitle}</div>\n {toast.description ? (\n <div data-description=\"\">{toast.description}</div>\n ) : null}\n </div>\n {toast.cancel ? (\n <button\n data-button\n data-cancel\n onClick={() => {\n deleteToast();\n if (toast.cancel?.onClick) {\n toast.cancel.onClick();\n }\n }}\n >\n {toast.cancel.label}\n </button>\n ) : null}\n {toast.action ? (\n <button\n data-button=\"\"\n onClick={() => {\n deleteToast();\n toast.action?.onClick();\n }}\n >\n {toast.action.label}\n </button>\n ) : null}\n </>\n )}\n </li>\n );\n};\n\ninterface ToasterProps {\n invert?: boolean;\n position?: Position;\n hotkey?: string[];\n expand?: boolean;\n dismissable?: boolean;\n}\n\nconst Toaster = (props: ToasterProps) => {\n const {\n invert,\n position = 'bottom-right',\n hotkey = ['altKey', 'KeyT'],\n expand,\n dismissable,\n } = props;\n const [toasts, setToasts] = React.useState<ToastT[]>([]);\n const [heights, setHeights] = React.useState<HeightT[]>([]);\n const [expanded, setExpanded] = React.useState(false);\n const [interacting, setInteracting] = React.useState(false);\n const [y, x] = position.split('-');\n const listRef = React.useRef<HTMLOListElement>(null);\n const hotkeyLabel = hotkey\n .join('+')\n .replace(/Key/g, '')\n .replace(/Digit/g, '');\n\n const removeToast = React.useCallback(\n (toast: ToastT) =>\n setToasts((toasts) => toasts.filter(({ id }) => id !== toast.id)),\n []\n );\n\n React.useEffect(() => {\n return ToastState.subscribe((toast) => {\n setToasts((toasts) => [toast, ...toasts]);\n });\n }, []);\n\n React.useEffect(() => {\n // Ensure expanded is always false when no toasts are present / only one left\n if (toasts.length <= 1) {\n setExpanded(false);\n }\n }, [toasts]);\n\n React.useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n const isHotkeyPressed = hotkey.every(\n (key) => (event as any)[key] || event.code === key\n );\n\n if (isHotkeyPressed) {\n setExpanded(true);\n listRef.current?.focus();\n }\n\n if (\n event.code === 'Escape' &&\n (document.activeElement === listRef.current ||\n listRef.current.contains(document.activeElement))\n ) {\n setExpanded(false);\n }\n };\n document.addEventListener('keydown', handleKeyDown);\n\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [hotkey]);\n\n return (\n // Remove item from normal navigation flow, only available via hotkey\n <div\n role=\"region\"\n aria-label={`Notifications ${hotkeyLabel}`}\n tabIndex={-1}\n >\n <ol\n tabIndex={-1}\n ref={listRef}\n className=\"toaster\"\n data-y-position={y}\n data-x-position={x}\n style={\n {\n '--front-toast-height': `${heights[0]?.height}px`,\n '--offset': `${VIEWPORT_OFFSET}px`,\n '--width': `${TOAST_WIDTH}px`,\n '--gap': `${GAP}px`,\n } as React.CSSProperties\n }\n onMouseEnter={() => setExpanded(true)}\n onMouseMove={() => setExpanded(true)}\n onMouseLeave={() => {\n // Avoid setting expanded to false when interacting with a toast, e.g. swiping\n if (!interacting) {\n setExpanded(false);\n }\n }}\n onPointerDown={() => {\n setInteracting(true);\n }}\n onPointerUp={() => setInteracting(false)}\n >\n {toasts.map((toast, index) => (\n <Toast\n key={toast.id}\n index={index}\n toast={toast}\n invert={invert}\n dismissable={dismissable}\n interacting={interacting}\n position={position}\n removeToast={removeToast}\n toasts={toasts}\n heights={heights}\n setHeights={setHeights}\n expandByDefault={expand}\n expanded={expanded}\n />\n ))}\n </ol>\n </div>\n );\n};\nexport { toast };\nexport default Toaster;\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(\".toaster{position:fixed;width:var(--width);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;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 6px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999}.toaster[data-x-position=right]{right:var(--offset)}.toaster[data-x-position=left]{left:var(--offset)}.toaster[data-x-position=center]{left:50%;transform:translate(-50%)}.toaster[data-y-position=top]{top:var(--offset)}.toaster[data-y-position=bottom]{bottom:var(--offset)}[data-react-temps-toast]{--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));--background: white;--border-color: var(--gray3);--color: var(--gray12);z-index:var(--z-index);display:flex;align-items:center;gap:6px;position:absolute;opacity:0;transform:var(--y);padding:16px;background:var(--background);border:1px solid var(--border-color);color:var(--color);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;touch-action:none;will-change:transform,opacity,height;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none}[data-react-temps-toast][data-invert=true]{--background: var(--gray12);--border-color: var(--gray11);--color: var(--gray1)}[data-react-temps-toast]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-react-temps-toast][data-y-position=top]{top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}[data-react-temps-toast][data-y-position=bottom]{bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}[data-react-temps-toast] [data-description]{font-weight:400;line-height:1.4;color:var(--color)}[data-react-temps-toast] [data-title]{font-weight:500;color:var(--color)}[data-react-temps-toast] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:-3px;margin-right:4px}[data-react-temps-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);animation:fade-in .3s ease forwards}[data-react-temps-toast] [data-icon]>*{flex-shrink:0}[data-react-temps-toast] [data-content]{display:flex;flex-direction:column;gap:2px}[data-react-temps-toast] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--background);background:var(--color);border:none;cursor:pointer;outline:none;transition:opacity .4s,box-shadow .2s}[data-react-temps-toast] [data-button]:focus-visible{box-shadow:0 0 0 2px #0006}[data-react-temps-toast] [data-button]:first-of-type{margin-left:auto}[data-react-temps-toast] [data-cancel]{color:var(--color);background:var(--border-color)}[data-react-temps-toast] [data-close-button]{position:absolute;left:0;top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;background:var(--gray1);border:1px solid var(--gray4);transform:translate(-35%,-35%);border-radius:50%;opacity:0;cursor:pointer;transition:opacity .1s,background .2s,border-color .2s}[data-react-temps-toast]:hover [data-close-button]{opacity:1}[data-react-temps-toast]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-react-temps-toast][data-swiping=true]:before{content:\\\"\\\";position:absolute;top:50%;left:0;right:0;height:100%;transform:scaleX(3) translateY(-50%)}[data-react-temps-toast][data-swiping=false][data-removed=true]:before{content:\\\"\\\";position:absolute;inset:0;transform:scaleY(2)}[data-react-temps-toast]:after{content:\\\"\\\";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-react-temps-toast][data-mounted=true]{--y: translateY(0);opacity:1}[data-react-temps-toast][data-expanded=false][data-front=false]{--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-react-temps-toast]>*{transition:opacity .4s}[data-react-temps-toast][data-expanded=false][data-front=false]>*{opacity:0}[data-react-temps-toast][data-visible=false]{opacity:0;pointer-events:none}[data-react-temps-toast][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-react-temps-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y: translateY(100%);opacity:0}[data-react-temps-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset) + 150%));opacity:0;transtion:transform .2s,opacity .1s}[data-react-temps-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{opacity:0;transtion:opacity .2s}[data-react-temps-toast][data-removed=true][data-front=false]:before{height:calc(var(--initial-height) + 20%)}[data-react-temps-toast][data-swiping=true]{transform:var(--y) translate(var(--swipe-amount, 0px));transition:none}[data-react-temps-toast][data-swipe-out=true][data-x-position=right],[data-react-temps-toast][data-swipe-out=true][data-x-position=center]{animation:swipe-out-right .2s ease-out}[data-react-temps-toast][data-swipe-out=true][data-x-position=left]{animation:swipe-out-left .2s ease-out}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount, 0px));opacity:1}to{transform:var(--y) translate(-100%);opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount, 0px));opacity:1}to{transform:var(--y) translate(100%);opacity:0}}@media (max-width: 600px){.toaster{position:fixed;bottom:20px;right:20px;left:20px;width:100%}[data-react-temps-toast]{bottom:0;width:calc(100% - 40px)}}.react-temps-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.react-temps-loading-wrapper[data-visible=false]{animation:fade-out .2s ease forwards}.react-temps-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.react-temps-loading-bar{animation:spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.react-temps-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.react-temps-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.react-temps-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.react-temps-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.react-temps-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.react-temps-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.react-temps-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.react-temps-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.react-temps-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.react-temps-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.react-temps-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.react-temps-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-react-temps-toast],[data-react-temps-toast]>*,.react-temps-loading-bar{transition:none!important;animation:none!important}}\\n\")","'use client';\nimport React from 'react';\nimport { ToastTypes } from './types';\n\nexport const getAsset = (type: ToastTypes): JSX.Element | null => {\n switch (type) {\n case 'success':\n return SuccessIcon;\n\n case 'error':\n return ErrorIcon;\n\n default:\n null;\n }\n};\n\nconst bars = Array(12).fill(0);\n\nexport const Loader = ({ visible }: { visible: boolean }) => {\n return (\n <div className=\"react-temps-loading-wrapper\" data-visible={visible}>\n <div className=\"react-temps-spinner\">\n {bars.map((_, i) => (\n <div className=\"react-temps-loading-bar\" key={`spinner-bar-${i}`} />\n ))}\n </div>\n </div>\n );\n};\n\nconst SuccessIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 20 20\"\n fill=\"currentColor\"\n height=\"20\"\n width=\"20\"\n >\n <path\n fillRule=\"evenodd\"\n d=\"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z\"\n clipRule=\"evenodd\"\n />\n </svg>\n);\n\nconst InfoIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 20 20\"\n fill=\"currentColor\"\n height=\"20\"\n width=\"20\"\n >\n <path\n fillRule=\"evenodd\"\n d=\"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z\"\n clipRule=\"evenodd\"\n />\n </svg>\n);\n\nconst ErrorIcon = (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 20 20\"\n fill=\"currentColor\"\n height=\"20\"\n width=\"20\"\n >\n <path\n fillRule=\"evenodd\"\n d=\"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z\"\n clipRule=\"evenodd\"\n />\n </svg>\n);\n","import React from 'react';\nimport { ExternalToast, ToastT, PromiseData, PromiseT } from './types';\n\nlet toastsCounter = 0;\n\nclass Observer {\n subscribers: Array<(toast: ExternalToast) => void>;\n\n constructor() {\n this.subscribers = [];\n }\n\n // We use arrow functions to maintain the correct `this` reference\n subscribe = (subscriber: (toast: ToastT) => void) => {\n this.subscribers.push(subscriber);\n\n return () => {\n const index = this.subscribers.indexOf(subscriber);\n this.subscribers.splice(index, 1);\n };\n };\n\n publish = (data: ToastT) => {\n this.subscribers.forEach((subscriber) => subscriber(data));\n };\n\n message = (message: string, data?: ExternalToast) => {\n this.publish({ ...data, id: toastsCounter++, title: message });\n };\n\n error = (message: string, data?: ExternalToast) => {\n this.publish({ ...data, id: toastsCounter++, type: 'error', title: message });\n };\n\n success = (message: string, data?: ExternalToast) => {\n this.publish({ ...data, id: toastsCounter++, type: 'success', title: message });\n };\n\n promise = (promise: PromiseT, data?: PromiseData) => {\n this.publish({ promiseData: data, promise, id: toastsCounter++ });\n };\n\n // We can't provide the toast we just created as a prop as we didn't creat it yet, so we can create a default toast object, I just don't know how to use function in argument when calling()?\n custom = (jsx: (id: number) => React.ReactElement) => {\n const id = toastsCounter++;\n this.publish({ jsx: jsx(id), id });\n };\n}\n\nexport const ToastState = new Observer();\n\n// bind this to the toast function\nconst toastFunction = (message: string, data?: ExternalToast) => {\n ToastState.publish({\n title: message,\n ...data,\n id: toastsCounter++,\n });\n};\n\nconst basicToast = toastFunction;\n\n// We use `Object.assign` to maintain the correct types as we would lose them otherwise\nexport const toast = Object.assign(basicToast, {\n success: ToastState.success,\n error: ToastState.error,\n custom: ToastState.custom,\n message: ToastState.message,\n promise: ToastState.promise,\n});\n"],"mappings":";AAEA,OAAOA,MAAW,QCDO,SAARC,EAA6BC,EAAK,CAAE,SAAAC,CAAS,EAAI,CAAC,EAAG,CAC1D,GAAI,CAACD,GAAO,OAAO,UAAa,YAAa,OAE7C,IAAME,EAAO,SAAS,MAAQ,SAAS,qBAAqB,MAAM,EAAE,GAC9DC,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,CAAq8P,ECCz/P,OAAOC,MAAW,QAGX,IAAMC,EAAYC,GAAyC,CAChE,OAAQA,EAAM,CACZ,IAAK,UACH,OAAOC,GAET,IAAK,QACH,OAAOC,GAET,QAEF,CACF,EAEMC,GAAO,MAAM,EAAE,EAAE,KAAK,CAAC,EAEhBC,EAAS,CAAC,CAAE,QAAAC,CAAQ,IA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,SAClCA,EAAQ,QAAQ,SAAS,SAAS,aAAa,IAEjDF,EAAY,EAAK,CAErB,EACA,gBAAS,iBAAiB,UAAWM,CAAa,EAE3C,IAAM,SAAS,oBAAoB,UAAWA,CAAa,CACpE,EAAG,CAACT,CAAM,CAAC,EAIT7C,EAAA,cAAC,OACC,KAAK,SACL,aAAY,iBAAiBmD,IAC7B,SAAU,IAEVnD,EAAA,cAAC,MACC,SAAU,GACV,IAAKkD,EACL,UAAU,UACV,kBAAiB3B,EACjB,kBAAiBC,EACjB,MACE,CACE,uBAAwB,IAAGvC,EAAAK,EAAQ,KAAR,YAAAL,EAAY,WACvC,WAAY,GAAGR,OACf,UAAW,GAAGE,OACd,QAAS,GAAGC,KACd,EAEF,aAAc,IAAMoE,EAAY,EAAI,EACpC,YAAa,IAAMA,EAAY,EAAI,EACnC,aAAc,IAAM,CAEb5D,GACH4D,EAAY,EAAK,CAErB,EACA,cAAe,IAAM,CACnBC,EAAe,EAAI,CACrB,EACA,YAAa,IAAMA,EAAe,EAAK,GAEtCzD,EAAO,IAAI,CAACL,EAAOI,IAClBS,EAAA,cAACjB,GAAA,CACC,IAAKI,EAAM,GACX,MAAOI,EACP,MAAOJ,EACP,OAAQ0C,EACR,YAAalC,EACb,YAAaP,EACb,SAAUQ,EACV,YAAaF,EACb,OAAQF,EACR,QAASF,EACT,WAAYD,EACZ,gBAAiByD,EACjB,SAAUrD,EACZ,CACD,CACH,CACF,CAEJ,EAEA,IAAO+D,GAAQC","names":["React","styleInject","css","insertAt","head","style","styleInject","React","getAsset","type","SuccessIcon","ErrorIcon","bars","Loader","visible","_","i","ErrorIcon","React","toastsCounter","Observer","subscriber","index","data","message","promise","jsx","id","ToastState","toastFunction","basicToast","toast","VISIBLE_TOASTS_AMOUNT","VIEWPORT_OFFSET","TOAST_LIFETIME","TOAST_WIDTH","GAP","SWIPE_TRESHOLD","TIME_BEFORE_UNMOUNT","Toast","props","_a","ToasterInvert","toast","interacting","setHeights","heights","index","toasts","expanded","removeToast","dismissable","position","expandByDefault","mounted","setMounted","React","removed","setRemoved","swiping","setSwiping","swipeOut","setSwipeOut","promiseStatus","setPromiseStatus","offsetBeforeRemove","setOffsetBeforeRemove","initialHeight","setInitialHeight","toastRef","isFront","isVisible","toastType","heightIndex","height","duration","closeTimerStartTimeRef","closeTimerRemainingTimeRef","pointerStartXRef","y","x","toastsHeightBefore","prev","curr","reducerIndex","invert","offset","deleteToast","h","timeoutId","now","timeRemaining","toastNode","promiseTitle","event","_b","swipeAmount","xPosition","Loader","getAsset","Toaster","hotkey","expand","setToasts","setExpanded","setInteracting","listRef","hotkeyLabel","id","ToastState","handleKeyDown","key","src_default","Toaster"]}
1
+ {"version":3,"sources":["../src/index.tsx","#style-inject:#style-inject","../src/styles.css","../src/assets.tsx","../src/state.ts"],"sourcesContent":["'use client';\n\nimport React from 'react';\n\nimport './styles.css';\nimport { getAsset, Loader } from './assets';\nimport { HeightT, Position, ToastT } from './types';\nimport { ToastState, toast } from './state';\n\n// Visible toasts amount\nconst VISIBLE_TOASTS_AMOUNT = 3;\n\n// Viewport padding\nconst VIEWPORT_OFFSET = '32px';\n\n// Default lifetime of a toasts (in ms)\nconst TOAST_LIFETIME = 4000;\n\n// Default toast width\nconst TOAST_WIDTH = 356;\n\n// Default gap between toasts\nconst GAP = 14;\n\nconst SWIPE_TRESHOLD = 20;\n\nconst TIME_BEFORE_UNMOUNT = 200;\n\ninterface ToastProps {\n toast: ToastT;\n toasts: ToastT[];\n index: number;\n expanded: boolean;\n invert: boolean;\n heights: HeightT[];\n setHeights: React.Dispatch<React.SetStateAction<HeightT[]>>;\n removeToast: (toast: ToastT) => void;\n position: Position;\n visibleToasts: number;\n expandByDefault: boolean;\n closeButton: boolean;\n interacting: boolean;\n style?: React.CSSProperties;\n duration?: number;\n className?: string;\n}\n\nconst Toast = (props: ToastProps) => {\n const {\n invert: ToasterInvert,\n toast,\n interacting,\n setHeights,\n visibleToasts,\n heights,\n index,\n toasts,\n expanded,\n removeToast,\n closeButton,\n style,\n className = '',\n duration: durationFromToaster,\n position,\n expandByDefault,\n } = props;\n const [mounted, setMounted] = React.useState(false);\n const [removed, setRemoved] = React.useState(false);\n const [swiping, setSwiping] = React.useState(false);\n const [swipeOut, setSwipeOut] = React.useState(false);\n const [promiseStatus, setPromiseStatus] = React.useState<'loading' | 'success' | 'error' | null>(null);\n const [offsetBeforeRemove, setOffsetBeforeRemove] = React.useState(0);\n const [initialHeight, setInitialHeight] = React.useState(0);\n const toastRef = React.useRef<HTMLLIElement>(null);\n const isFront = index === 0;\n const isVisible = index + 1 <= visibleToasts;\n const toastType = toast.type;\n const toastClassname = toast.className || '';\n // Height index is used to calculate the offset as it gets updated before the toast array, which means we can calculate the new layout faster.\n const heightIndex = React.useMemo(\n () => heights.findIndex((height) => height.toastId === toast.id) || 0,\n [heights, toast.id],\n );\n const duration = React.useMemo(\n () => toast.duration || durationFromToaster || TOAST_LIFETIME,\n [toast.duration, durationFromToaster],\n );\n const closeTimerStartTimeRef = React.useRef(0);\n const offset = React.useRef(0);\n const closeTimerRemainingTimeRef = React.useRef(duration);\n const lastCloseTimerStartTimeRef = React.useRef(0);\n const pointerStartYRef = React.useRef<number | null>(null);\n const [y, x] = position.split('-');\n const toastsHeightBefore = React.useMemo(() => {\n return heights.reduce((prev, curr, reducerIndex) => {\n // Calculate offset up untill current toast\n if (reducerIndex >= heightIndex) {\n return prev;\n }\n\n return prev + curr.height;\n }, 0);\n }, [heights, heightIndex]);\n const invert = toast.invert || ToasterInvert;\n const disabled = promiseStatus === 'loading';\n offset.current = React.useMemo(() => heightIndex * GAP + toastsHeightBefore, [heightIndex, toastsHeightBefore]);\n\n React.useEffect(() => {\n // Trigger enter animation without using CSS animation\n setMounted(true);\n }, []);\n\n React.useEffect(() => {\n if (toast.promise) {\n setPromiseStatus('loading');\n if (toast.promise instanceof Promise) {\n toast.promise\n .then(() => {\n setPromiseStatus('success');\n })\n .catch(() => {\n setPromiseStatus('error');\n });\n } else if (typeof toast.promise === 'function') {\n toast\n .promise()\n .then(() => {\n setPromiseStatus('success');\n })\n .catch(() => {\n setPromiseStatus('error');\n });\n }\n }\n }, [toast]);\n\n const deleteToast = React.useCallback(() => {\n // Save the offset for the exit swipe animation\n setRemoved(true);\n setOffsetBeforeRemove(offset.current);\n setHeights((h) => h.filter((height) => height.toastId !== toast.id));\n\n setTimeout(() => {\n removeToast(toast);\n }, TIME_BEFORE_UNMOUNT);\n }, [toast, removeToast, setHeights, offset]);\n\n React.useEffect(() => {\n if (toast.promise && promiseStatus === 'loading') return;\n let timeoutId: NodeJS.Timeout;\n\n // Pause the timer on each hover\n const pauseTimer = () => {\n if (lastCloseTimerStartTimeRef.current < closeTimerStartTimeRef.current) {\n // Get the elapsed time since the timer started\n const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current;\n\n closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;\n }\n\n lastCloseTimerStartTimeRef.current = new Date().getTime();\n };\n\n const startTimer = () => {\n closeTimerStartTimeRef.current = new Date().getTime();\n // Let the toast know it has started\n timeoutId = setTimeout(() => {\n deleteToast();\n }, closeTimerRemainingTimeRef.current);\n };\n\n if (expanded || interacting) {\n pauseTimer();\n } else {\n startTimer();\n }\n\n return () => clearTimeout(timeoutId);\n }, [expanded, interacting, expandByDefault, toast, duration, deleteToast, toast.promise, promiseStatus]);\n\n React.useEffect(() => {\n const toastNode = toastRef.current;\n\n if (toastNode) {\n const height = toastNode.getBoundingClientRect().height;\n // Add toast height tot heights array after the toast is mounted\n setInitialHeight(height);\n setHeights((h) => [{ toastId: toast.id, height }, ...h]);\n\n return () => setHeights((h) => h.filter((height) => height.toastId !== toast.id));\n }\n }, [setHeights, toast.id]);\n\n const promiseTitle = React.useMemo(() => {\n switch (promiseStatus) {\n case 'loading':\n return toast.promiseData.loading;\n case 'success':\n return toast.promiseData.success;\n case 'error':\n return toast.promiseData.error;\n default:\n return null;\n }\n }, [toast.promiseData, promiseStatus]);\n\n return (\n <li\n aria-live={toast.important ? 'assertive' : 'polite'}\n aria-atomic=\"true\"\n role=\"status\"\n tabIndex={0}\n ref={toastRef}\n className={className + ' ' + toastClassname}\n data-sonner-toast=\"\"\n data-mounted={mounted}\n data-promise={Boolean(toast.promise)}\n data-removed={removed}\n data-visible={isVisible}\n data-y-position={y}\n data-x-position={x}\n data-index={index}\n data-front={isFront}\n data-swiping={swiping}\n data-type={toastType}\n data-invert={invert}\n data-swipe-out={swipeOut}\n data-expanded={Boolean(expanded || (expandByDefault && mounted))}\n style={\n {\n '--index': index,\n '--toasts-before': index,\n '--z-index': toasts.length - index,\n '--offset': `${removed ? offsetBeforeRemove : offset.current}px`,\n '--initial-height': expandByDefault ? 'auto' : `${initialHeight}px`,\n ...style,\n ...toast.style,\n } as React.CSSProperties\n }\n onPointerDown={(event) => {\n if (disabled) return;\n setOffsetBeforeRemove(offset.current);\n // Ensure we maintain correct pointer capture even when going outside of the toast (e.g. when swiping)\n (event.target as HTMLElement).setPointerCapture(event.pointerId);\n if ((event.target as HTMLElement).tagName === 'BUTTON') return;\n setSwiping(true);\n pointerStartYRef.current = event.clientY;\n }}\n onPointerUp={() => {\n if (swipeOut) return;\n const swipeAmount = Number(toastRef.current?.style.getPropertyValue('--swipe-amount').replace('px', '') || 0);\n\n // Remove only if treshold is met\n if (Math.abs(swipeAmount) >= SWIPE_TRESHOLD) {\n setOffsetBeforeRemove(offset.current);\n deleteToast();\n setSwipeOut(true);\n return;\n }\n\n toastRef.current?.style.setProperty('--swipe-amount', '0px');\n pointerStartYRef.current = null;\n setSwiping(false);\n }}\n onPointerMove={(event) => {\n if (!pointerStartYRef.current) return;\n\n const yPosition = event.clientY - pointerStartYRef.current;\n\n const isAllowedToSwipe = y === 'top' ? yPosition < 0 : yPosition > 0;\n // We don't want to swipe to the left and vice versa depending on toast position\n if (!isAllowedToSwipe) {\n toastRef.current?.style.setProperty('--swipe-amount', '0px');\n return;\n }\n\n toastRef.current?.style.setProperty('--swipe-amount', `${yPosition}px`);\n }}\n >\n {closeButton ? (\n <button\n aria-label=\"Close toast\"\n data-disabled={disabled}\n data-close-button\n onClick={disabled ? undefined : deleteToast}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"12\"\n height=\"12\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"></line>\n <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"></line>\n </svg>\n </button>\n ) : null}\n {toast.jsx ? (\n toast.jsx\n ) : (\n <>\n {toastType || toast.icon || toast.promise ? (\n <div data-icon=\"\">\n {toast.promise ? <Loader visible={promiseStatus === 'loading'} /> : null}\n {toast.icon || getAsset(promiseStatus ?? toast.type)}\n </div>\n ) : null}\n\n <div data-content=\"\">\n <div data-title=\"\">{toast.title ?? promiseTitle}</div>\n {toast.description ? <div data-description=\"\">{toast.description}</div> : null}\n </div>\n {toast.cancel ? (\n <button\n data-button\n data-cancel\n onClick={() => {\n deleteToast();\n if (toast.cancel?.onClick) {\n toast.cancel.onClick();\n }\n }}\n >\n {toast.cancel.label}\n </button>\n ) : null}\n {toast.action ? (\n <button\n data-button=\"\"\n onClick={() => {\n deleteToast();\n toast.action?.onClick();\n }}\n >\n {toast.action.label}\n </button>\n ) : null}\n </>\n )}\n </li>\n );\n};\n\ninterface ToastOptions {\n className?: string;\n style?: React.CSSProperties;\n}\n\ninterface ToasterProps {\n invert?: boolean;\n theme?: 'light' | 'dark';\n position?: Position;\n hotkey?: string[];\n richColors?: boolean;\n expand?: boolean;\n duration?: number;\n visibleToasts?: number;\n closeButton?: boolean;\n toastOptions?: ToastOptions;\n className?: string;\n style?: React.CSSProperties;\n offset?: number;\n}\n\nconst Toaster = (props: ToasterProps) => {\n const {\n invert,\n position = 'bottom-right',\n hotkey = ['altKey', 'KeyT'],\n expand,\n closeButton,\n className,\n offset,\n theme = 'light',\n richColors,\n duration,\n style,\n visibleToasts = VISIBLE_TOASTS_AMOUNT,\n toastOptions,\n } = props;\n const [toasts, setToasts] = React.useState<ToastT[]>([]);\n const [heights, setHeights] = React.useState<HeightT[]>([]);\n const [expanded, setExpanded] = React.useState(false);\n const [interacting, setInteracting] = React.useState(false);\n const [y, x] = position.split('-');\n const listRef = React.useRef<HTMLOListElement>(null);\n const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');\n\n const removeToast = React.useCallback(\n (toast: ToastT) => setToasts((toasts) => toasts.filter(({ id }) => id !== toast.id)),\n [],\n );\n\n React.useEffect(() => {\n return ToastState.subscribe((toast) => {\n setToasts((toasts) => [toast, ...toasts]);\n });\n }, []);\n\n React.useEffect(() => {\n // Ensure expanded is always false when no toasts are present / only one left\n if (toasts.length <= 1) {\n setExpanded(false);\n }\n }, [toasts]);\n\n React.useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n const isHotkeyPressed = hotkey.every((key) => (event as any)[key] || event.code === key);\n\n if (isHotkeyPressed) {\n setExpanded(true);\n listRef.current?.focus();\n }\n\n if (\n event.code === 'Escape' &&\n (document.activeElement === listRef.current || listRef.current.contains(document.activeElement))\n ) {\n setExpanded(false);\n }\n };\n document.addEventListener('keydown', handleKeyDown);\n\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [hotkey]);\n\n return (\n // Remove item from normal navigation flow, only available via hotkey\n <div role=\"region\" aria-label={`Notifications ${hotkeyLabel}`} tabIndex={-1}>\n <ol\n tabIndex={-1}\n ref={listRef}\n className={className}\n data-sonner-toaster\n data-theme={theme}\n data-rich-colors={richColors}\n data-y-position={y}\n data-x-position={x}\n style={\n {\n '--front-toast-height': `${heights[0]?.height}px`,\n '--offset': offset || VIEWPORT_OFFSET,\n '--width': `${TOAST_WIDTH}px`,\n '--gap': `${GAP}px`,\n ...style,\n } as React.CSSProperties\n }\n onMouseEnter={() => setExpanded(true)}\n onMouseMove={() => setExpanded(true)}\n onMouseLeave={() => {\n // Avoid setting expanded to false when interacting with a toast, e.g. swiping\n if (!interacting) {\n setExpanded(false);\n }\n }}\n onPointerDown={() => {\n setInteracting(true);\n }}\n onPointerUp={() => setInteracting(false)}\n >\n {toasts.map((toast, index) => (\n <Toast\n key={toast.id}\n index={index}\n toast={toast}\n duration={duration}\n className={toastOptions?.className}\n invert={invert}\n visibleToasts={visibleToasts}\n closeButton={closeButton}\n interacting={interacting}\n position={position}\n style={toastOptions?.style}\n removeToast={removeToast}\n toasts={toasts}\n heights={heights}\n setHeights={setHeights}\n expandByDefault={expand}\n expanded={expanded}\n />\n ))}\n </ol>\n </div>\n );\n};\nexport { toast, Toaster };\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(\"[data-sonner-toaster]{position:fixed;width:var(--width);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;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 6px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999}[data-sonner-toaster][data-x-position=right]{right:max(var(--offset),env(safe-area-inset-right))}[data-sonner-toaster][data-x-position=left]{left:max(var(--offset),env(safe-area-inset-left))}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translate(-50%)}[data-sonner-toaster][data-y-position=top]{top:max(var(--offset),env(safe-area-inset-top))}[data-sonner-toaster][data-y-position=bottom]{bottom:max(var(--offset),env(safe-area-inset-bottom))}[data-sonner-toast]{--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);display:flex;align-items:center;gap:6px;position:absolute;opacity:0;transform:var(--y);padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;touch-action:none;will-change:transform,opacity,height;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-sonner-toast][data-y-position=top]{top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}[data-sonner-toast] [data-description]{font-weight:400;line-height:1.4;color:inherit}[data-sonner-toast] [data-title]{font-weight:500;color:inherit}[data-sonner-toast] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:-3px;margin-right:4px}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);animation:sonner-fade-in .3s ease forwards}[data-sonner-toast] [data-icon]>*{flex-shrink:0}[data-sonner-toast] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:auto;border:none;cursor:pointer;outline:none;transition:opacity .4s,box-shadow .2s}[data-sonner-toast] [data-button]:focus-visible{box-shadow:0 0 0 2px #0006}[data-sonner-toast] [data-button]:first-of-type{margin-left:auto}[data-sonner-toast] [data-cancel]{color:var(--color);background:var(--border-color)}[data-sonner-toast] [data-close-button]{position:absolute;left:0;top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;background:var(--gray1);color:var(--gray12);border:1px solid var(--gray4);transform:translate(-35%,-35%);border-radius:50%;opacity:0;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast]:hover [data-close-button]{opacity:1}[data-sonner-toast]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]:before{content:\\\"\\\";position:absolute;left:0;right:0;height:100%}[data-sonner-toast][data-y-position=top][data-swiping=true]:before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]:before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]:before{content:\\\"\\\";position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast]:after{content:\\\"\\\";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y: translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-expanded=false][data-front=false]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y: translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{opacity:0}[data-sonner-toast][data-removed=true][data-front=false]:before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount, 0px));transition:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation:swipe-out .2s ease-out forwards}@keyframes swipe-out{0%{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount)));opacity:1}to{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount) + var(--lift) * -100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;--mobile-offset: 16px;right:var(--mobile-offset);left:var(--mobile-offset);width:100%}[data-sonner-toast]{left:0;right:0;width:calc(100% - 32px)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset)}[data-sonner-toaster][data-y-position=bottom]{bottom:20px}[data-sonner-toaster][data-y-position=top]{top:20px}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset);right:var(--mobile-offset);transform:none}}[data-sonner-toaster][data-theme=light]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 91%);--success-text: hsl(140, 100%, 27%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-theme=dark]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-rich-colors=true] [data-sonner-toast][data-type=success],[data-rich-colors=true] [data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true] [data-sonner-toast][data-type=error],[data-rich-colors=true] [data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}\\n\")","'use client';\nimport React from 'react';\nimport { ToastTypes } from './types';\n\nexport const getAsset = (type: ToastTypes): JSX.Element | null => {\n switch (type) {\n case 'success':\n return SuccessIcon;\n\n case 'error':\n return ErrorIcon;\n\n default:\n null;\n }\n};\n\nconst bars = Array(12).fill(0);\n\nexport const Loader = ({ visible }: { visible: boolean }) => {\n return (\n <div className=\"sonner-loading-wrapper\" data-visible={visible}>\n <div className=\"sonner-spinner\">\n {bars.map((_, i) => (\n <div className=\"sonner-loading-bar\" key={`spinner-bar-${i}`} />\n ))}\n </div>\n </div>\n );\n};\n\nconst SuccessIcon = (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" fill=\"currentColor\" height=\"20\" width=\"20\">\n <path\n fillRule=\"evenodd\"\n d=\"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z\"\n clipRule=\"evenodd\"\n />\n </svg>\n);\n\nconst InfoIcon = (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" fill=\"currentColor\" height=\"20\" width=\"20\">\n <path\n fillRule=\"evenodd\"\n d=\"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z\"\n clipRule=\"evenodd\"\n />\n </svg>\n);\n\nconst ErrorIcon = (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 20 20\" fill=\"currentColor\" height=\"20\" width=\"20\">\n <path\n fillRule=\"evenodd\"\n d=\"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z\"\n clipRule=\"evenodd\"\n />\n </svg>\n);\n","import React from 'react';\nimport { ExternalToast, ToastT, PromiseData, PromiseT } from './types';\n\nlet toastsCounter = 0;\n\nclass Observer {\n subscribers: Array<(toast: ExternalToast) => void>;\n\n constructor() {\n this.subscribers = [];\n }\n\n // We use arrow functions to maintain the correct `this` reference\n subscribe = (subscriber: (toast: ToastT) => void) => {\n this.subscribers.push(subscriber);\n\n return () => {\n const index = this.subscribers.indexOf(subscriber);\n this.subscribers.splice(index, 1);\n };\n };\n\n publish = (data: ToastT) => {\n this.subscribers.forEach((subscriber) => subscriber(data));\n };\n\n message = (message: string, data?: ExternalToast) => {\n this.publish({ ...data, id: toastsCounter++, title: message });\n };\n\n error = (message: string, data?: ExternalToast) => {\n this.publish({ ...data, id: toastsCounter++, type: 'error', title: message });\n };\n\n success = (message: string, data?: ExternalToast) => {\n this.publish({ ...data, id: toastsCounter++, type: 'success', title: message });\n };\n\n promise = (promise: PromiseT, data?: PromiseData) => {\n this.publish({ promiseData: data, promise, id: toastsCounter++ });\n };\n\n // We can't provide the toast we just created as a prop as we didn't creat it yet, so we can create a default toast object, I just don't know how to use function in argument when calling()?\n custom = (jsx: (id: number) => React.ReactElement) => {\n const id = toastsCounter++;\n this.publish({ jsx: jsx(id), id });\n };\n}\n\nexport const ToastState = new Observer();\n\n// bind this to the toast function\nconst toastFunction = (message: string, data?: ExternalToast) => {\n ToastState.publish({\n title: message,\n ...data,\n id: toastsCounter++,\n });\n};\n\nconst basicToast = toastFunction;\n\n// We use `Object.assign` to maintain the correct types as we would lose them otherwise\nexport const toast = Object.assign(basicToast, {\n success: ToastState.success,\n error: ToastState.error,\n custom: ToastState.custom,\n message: ToastState.message,\n promise: ToastState.promise,\n});\n"],"mappings":";AAEA,OAAOA,MAAW,QCDO,SAARC,EAA6BC,EAAK,CAAE,SAAAC,CAAS,EAAI,CAAC,EAAG,CAC1D,GAAI,CAACD,GAAO,OAAO,UAAa,YAAa,OAE7C,IAAME,EAAO,SAAS,MAAQ,SAAS,qBAAqB,MAAM,EAAE,GAC9DC,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,CAA2lT,ECC/oT,OAAOC,MAAW,QAGX,IAAMC,GAAYC,GAAyC,CAChE,OAAQA,EAAM,CACZ,IAAK,UACH,OAAOC,GAET,IAAK,QACH,OAAOC,GAET,QAEF,CACF,EAEMC,GAAO,MAAM,EAAE,EAAE,KAAK,CAAC,EAEhBC,GAAS,CAAC,CAAE,QAAAC,CAAQ,IAE7BP,EAAA,cAAC,OAAI,UAAU,yBAAyB,eAAcO,GACpDP,EAAA,cAAC,OAAI,UAAU,kBACZK,GAAK,IAAI,CAACG,EAAGC,IACZT,EAAA,cAAC,OAAI,UAAU,qBAAqB,IAAK,eAAeS,IAAK,CAC9D,CACH,CACF,EAIEN,GACJH,EAAA,cAAC,OAAI,MAAM,6BAA6B,QAAQ,YAAY,KAAK,eAAe,OAAO,KAAK,MAAM,MAChGA,EAAA,cAAC,QACC,SAAS,UAC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AAAA,EAAc,UACzB,OAAQnB,EACR,cAAe9C,EACf,YAAaM,EACb,YAAaR,EACb,SAAUY,EACV,MAAOuD,GAAA,YAAAA,EAAc,MACrB,YAAa5D,EACb,OAAQF,EACR,QAASF,EACT,WAAYF,EACZ,gBAAiB+D,EACjB,SAAU1D,EACZ,CACD,CACH,CACF,CAEJ","names":["React","styleInject","css","insertAt","head","style","styleInject","React","getAsset","type","SuccessIcon","ErrorIcon","bars","Loader","visible","_","i","ErrorIcon","React","toastsCounter","Observer","subscriber","index","data","message","promise","jsx","id","ToastState","toastFunction","basicToast","toast","VISIBLE_TOASTS_AMOUNT","VIEWPORT_OFFSET","TOAST_LIFETIME","TOAST_WIDTH","GAP","SWIPE_TRESHOLD","TIME_BEFORE_UNMOUNT","Toast","props","_a","ToasterInvert","toast","interacting","setHeights","visibleToasts","heights","index","toasts","expanded","removeToast","closeButton","style","className","durationFromToaster","position","expandByDefault","mounted","setMounted","React","removed","setRemoved","swiping","setSwiping","swipeOut","setSwipeOut","promiseStatus","setPromiseStatus","offsetBeforeRemove","setOffsetBeforeRemove","initialHeight","setInitialHeight","toastRef","isFront","isVisible","toastType","toastClassname","heightIndex","height","duration","closeTimerStartTimeRef","offset","closeTimerRemainingTimeRef","lastCloseTimerStartTimeRef","pointerStartYRef","y","x","toastsHeightBefore","prev","curr","reducerIndex","invert","disabled","deleteToast","h","timeoutId","elapsedTime","toastNode","promiseTitle","event","_b","swipeAmount","yPosition","Loader","getAsset","Toaster","hotkey","expand","theme","richColors","toastOptions","setToasts","setExpanded","setInteracting","listRef","hotkeyLabel","id","ToastState","handleKeyDown","key"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sonner",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "description": "An opinionated toast component for React.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "build": "tsup src/index.tsx",
13
13
  "dev": "tsup src/index.tsx --watch",
14
- "dev:website": "turbo run dev --filter=website..."
14
+ "dev:website": "turbo run dev --filter=website...",
15
+ "format": "prettier --write ."
15
16
  },
16
17
  "keywords": [
17
18
  "react",
@@ -23,8 +24,10 @@
23
24
  "author": "Emil Kowalski <e@emilkowal.ski>",
24
25
  "license": "MIT",
25
26
  "devDependencies": {
27
+ "@playwright/test": "^1.30.0",
26
28
  "@types/node": "^18.11.13",
27
29
  "@types/react": "^18.0.26",
30
+ "prettier": "^2.8.4",
28
31
  "react": "^18.2.0",
29
32
  "tsup": "^6.4.0",
30
33
  "turbo": "1.6",