@propellerads/toast 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,18 +112,49 @@ failure stays one toast.
112
112
  | prop | what it does |
113
113
  | --- | --- |
114
114
  | `limit` | How many toasts stand at once: `1`–`5`, `3` by default. A toast over the limit is not dropped: it waits unseen and comes forward when one in front closes. The stack does not scroll, so it stops at five. |
115
+ | `position` | The corner: `'top-left'`, `'top-center'`, `'top-right'`, `'bottom-left'`, `'bottom-center'` or `'bottom-right'`; `'top-right'` by default. `ToastPosition.TopRight` and the rest name them. |
115
116
  | `toastManager` | A manager of your own from `createToastManager()`: a second Toaster with it is a second stack. |
116
117
 
117
- The stack always stands in the bottom right — the full width at the bottom on a
118
- phone — for every toast of every product, cookie consent included. It is at
119
- `z-index: 3100`, above dialogs and tooltips at 3000; `--toast-layer` on any
120
- ancestor changes it.
118
+ Every toast of a Toaster stands in its corner, cookie consent included. At the
119
+ top the stack is turned over: the toasts behind peek out under the front one,
120
+ fan out downwards, and come in and leave through the top edge. A toast swipes
121
+ off towards the edges it stands at — up or down, and to its side; one in the
122
+ middle only up or down. On a phone, under 640px, the stack takes the full
123
+ width at the top or the bottom.
124
+
125
+ The stack is at `z-index: 3100`, above dialogs and tooltips at 3000;
126
+ `--toast-layer` on any ancestor changes it.
127
+
128
+ ### Offsets
129
+
130
+ The distance from the edges is four custom properties, `var(--space-16)` each
131
+ by default. A corner uses its two; a stack in the middle uses the top or the
132
+ bottom one, and the left and right ones on both sides. Set them in the app's
133
+ own CSS, media queries included:
134
+
135
+ ```css
136
+ /* A product with a fixed 56px header keeps the stack under it. */
137
+ :root {
138
+ --toast-offset-top: calc(56px + var(--space-16));
139
+ }
140
+ ```
141
+
142
+ ```tsx
143
+ <Toaster position="top-right" />
144
+ ```
145
+
146
+ | property | edge |
147
+ | --- | --- |
148
+ | `--toast-offset-top` | top |
149
+ | `--toast-offset-right` | right |
150
+ | `--toast-offset-bottom` | bottom |
151
+ | `--toast-offset-left` | left |
121
152
 
122
153
  ## From react-toastify
123
154
 
124
155
  | react-toastify | here |
125
156
  | --- | --- |
126
- | `<ToastContainer position="top-right" autoClose={5000} />` | `<Toaster />` — the bottom right and five seconds, always |
157
+ | `<ToastContainer position="top-right" autoClose={5000} />` | `<Toaster />` — the top right and five seconds, always |
127
158
  | `toast.error(text)`, `toast.success(text)` | the same |
128
159
  | `toast.warn(text)`, `toast.info(text)`, `toast(text)` | `toast.warning(text)`, `toast.info(text)`, `toast.add({title: text})` |
129
160
  | `{autoClose: false}` | `{persistent: true}`; any other `autoClose` goes |
package/dist/index.css CHANGED
@@ -1 +1 @@
1
- .toast-viewport{z-index:var(--toast-layer,3100);inset-inline:var(--space-16);bottom:var(--space-16);pointer-events:none;outline:none;width:auto;max-width:384px;margin-inline:auto;position:fixed}@media (width>=640px){.toast-viewport{left:auto;right:var(--space-16);width:100%;margin-inline:var(--space-0)}}.toast{--toast-bg:var(--color-light-inversion);--toast-contour:var(--color-formal);--toast-shadow:var(--shadow-big);--toast-title:var(--color-dark-inversion);--toast-text:var(--color-quiet-text);--toast-icon:var(--color-quiet);--gap:var(--space-12);--peek:var(--space-12);--height:var(--toast-frontmost-height,var(--toast-height));--offset-y:calc(var(--toast-offset-y) * -1 + var(--toast-index) * var(--gap) * -1 + var(--toast-swipe-movement-y));--scale:max(0, 1 - var(--toast-index) * .1);--shrink:calc(1 - var(--scale));--toast-move:var(--duration-300) var(--ease-enter);--toast-fade:var(--duration-300);box-sizing:border-box;z-index:calc(1000 - var(--toast-index));width:100%;height:var(--height);border-radius:var(--radius-16);background-color:var(--toast-bg);box-shadow:inset 0 0 0 var(--space-1) var(--toast-contour), var(--toast-shadow);color:var(--toast-text);font:var(--font-paragraph);font-family:var(--font-family);transform-origin:bottom;transform:translateX(var(--toast-swipe-movement-x)) translateY(calc(var(--toast-swipe-movement-y) - var(--toast-index) * var(--peek) - var(--shrink) * var(--height))) scale(var(--scale));transition:transform var(--toast-move), opacity var(--toast-fade) var(--ease-flat), height var(--duration-100) var(--ease-flat);outline:var(--space-2) solid transparent;outline-offset:var(--space-1);pointer-events:auto;-webkit-user-select:none;user-select:none;will-change:transform;position:absolute;bottom:0;right:0}.toast:focus-visible{outline-color:var(--color-action)}.toast:after{content:"";width:100%;height:calc(var(--gap) + 1px);position:absolute;top:100%;left:0}.toast[data-expanded]{height:var(--toast-height);transform:translateX(var(--toast-swipe-movement-x)) translateY(var(--offset-y))}.toast[data-ending-style]{--toast-move:var(--duration-200) var(--ease-exit);--toast-fade:var(--duration-200)}.toast[data-starting-style],.toast[data-ending-style]:not([data-limited]):not([data-swipe-direction]){transform:translateY(150%)}.toast[data-limited]{opacity:0}.toast[data-ending-style][data-swipe-direction=down]{transform:translateY(calc(var(--toast-swipe-movement-y) + 150%))}.toast[data-ending-style][data-swipe-direction=up]{transform:translateY(calc(var(--toast-swipe-movement-y) - 150%))}.toast[data-ending-style][data-swipe-direction=left]{transform:translateX(calc(var(--toast-swipe-movement-x) - 150%)) translateY(var(--offset-y))}.toast[data-ending-style][data-swipe-direction=right]{transform:translateX(calc(var(--toast-swipe-movement-x) + 150%)) translateY(var(--offset-y))}.toast[data-type=success]{--toast-icon:var(--color-success)}.toast[data-type=info]{--toast-icon:var(--color-action)}.toast[data-type=warning]{--toast-icon:var(--color-warning)}.toast[data-type=error]{--toast-icon:var(--color-danger)}.toast__content{--toast-line:36px;--toast-text-line:var(--space-20);box-sizing:border-box;align-items:flex-start;gap:var(--space-12);height:100%;padding:var(--space-16);transition:opacity var(--duration-200) var(--ease-flat);padding-inline-start:calc(var(--space-16) + var(--space-4));display:flex;overflow:hidden}.toast__content[data-behind]{opacity:0}.toast__content[data-expanded]{opacity:1}.toast__icon{width:var(--space-16);height:var(--space-16);color:var(--toast-icon);pointer-events:none;flex-shrink:0;margin-block-start:calc((var(--toast-line) - var(--space-16)) / 2);display:flex}.toast__icon>svg{width:100%;height:100%}.toast__ring{box-sizing:border-box;border:var(--space-2) solid var(--color-rich);border-top-color:var(--color-dark-inversion);border-radius:50%;width:100%;height:100%;animation:.8s linear infinite toast-turn}@keyframes toast-turn{to{transform:rotate(360deg)}}.toast__body{align-items:flex-start;gap:var(--space-4) var(--space-12);flex-wrap:wrap;flex:1;min-width:0;display:flex}.toast__text{gap:var(--space-4);min-width:0;padding-block:calc((var(--toast-line) - var(--toast-text-line)) / 2);flex-direction:column;flex:auto;display:flex}.toast__title{margin:var(--space-0);color:var(--toast-title);font:var(--font-h4);font-family:var(--font-family);line-height:var(--toast-text-line);white-space:pre-line;overflow-wrap:anywhere}.toast__description{margin:var(--space-0);color:var(--toast-text);font:var(--font-paragraph);font-family:var(--font-family);text-wrap:pretty;white-space:pre-line;overflow-wrap:anywhere}.toast__description a{color:inherit;text-underline-offset:var(--space-4);text-decoration:underline}.toast__action,.toast__close{flex-shrink:0}.toast__close>svg{width:var(--space-16);height:var(--space-16)}@media (prefers-reduced-motion:reduce){.toast__ring{animation-duration:2.4s}}
1
+ .toast-viewport{z-index:var(--toast-layer,3100);left:var(--toast-offset-left,var(--space-16));right:var(--toast-offset-right,var(--space-16));bottom:var(--toast-offset-bottom,var(--space-16));pointer-events:none;outline:none;width:auto;max-width:384px;margin-inline:auto;position:fixed}.toast-viewport[data-y-position=top]{top:var(--toast-offset-top,var(--space-16));bottom:auto}@media (width>=640px){.toast-viewport:not([data-x-position=left]):not([data-x-position=center]){width:100%;margin-inline:var(--space-0);left:auto}.toast-viewport[data-x-position=left]{width:100%;margin-inline:var(--space-0);right:auto}}.toast{--toast-bg:var(--color-light-inversion);--toast-contour:var(--color-formal);--toast-shadow:var(--shadow-big);--toast-title:var(--color-dark-inversion);--toast-text:var(--color-quiet-text);--toast-icon:var(--color-quiet);--gap:var(--space-12);--peek:var(--space-12);--lift:-1;--height:var(--toast-frontmost-height,var(--toast-height));--offset-y:calc(var(--lift) * (var(--toast-offset-y) + var(--toast-index) * var(--gap)) + var(--toast-swipe-movement-y));--scale:max(0, 1 - var(--toast-index) * .1);--shrink:calc(1 - var(--scale));--toast-move:var(--duration-300) var(--ease-enter);--toast-fade:var(--duration-300);box-sizing:border-box;z-index:calc(1000 - var(--toast-index));width:100%;height:var(--height);border-radius:var(--radius-16);background-color:var(--toast-bg);box-shadow:inset 0 0 0 var(--space-1) var(--toast-contour), var(--toast-shadow);color:var(--toast-text);font:var(--font-paragraph);font-family:var(--font-family);transform-origin:bottom;transform:translateX(var(--toast-swipe-movement-x)) translateY(calc(var(--toast-swipe-movement-y) + var(--lift) * (var(--toast-index) * var(--peek) + var(--shrink) * var(--height)))) scale(var(--scale));transition:transform var(--toast-move), opacity var(--toast-fade) var(--ease-flat), height var(--duration-100) var(--ease-flat);outline:var(--space-2) solid transparent;outline-offset:var(--space-1);pointer-events:auto;-webkit-user-select:none;user-select:none;will-change:transform;position:absolute;bottom:0;right:0}.toast-viewport[data-y-position=top] .toast{--lift:1;transform-origin:top;top:0;bottom:auto}.toast:focus-visible{outline-color:var(--color-action)}.toast:after{content:"";width:100%;height:calc(min(var(--toast-index), 1) * (var(--gap) + 1px));position:absolute;top:100%;left:0}.toast-viewport[data-y-position=top] .toast:after{top:auto;bottom:100%}.toast[data-expanded]{height:var(--toast-height);transform:translateX(var(--toast-swipe-movement-x)) translateY(var(--offset-y))}.toast[data-ending-style]{--toast-move:var(--duration-200) var(--ease-exit);--toast-fade:var(--duration-200)}.toast[data-starting-style],.toast[data-ending-style]:not([data-limited]):not([data-swipe-direction]){transform:translateY(calc(var(--lift) * -150%))}.toast[data-limited]{opacity:0}.toast[data-ending-style][data-swipe-direction=down]{transform:translateY(calc(var(--toast-swipe-movement-y) + 150%))}.toast[data-ending-style][data-swipe-direction=up]{transform:translateY(calc(var(--toast-swipe-movement-y) - 150%))}.toast[data-ending-style][data-swipe-direction=left]{transform:translateX(calc(var(--toast-swipe-movement-x) - 150%)) translateY(var(--offset-y))}.toast[data-ending-style][data-swipe-direction=right]{transform:translateX(calc(var(--toast-swipe-movement-x) + 150%)) translateY(var(--offset-y))}.toast[data-type=success]{--toast-icon:var(--color-success)}.toast[data-type=info]{--toast-icon:var(--color-action)}.toast[data-type=warning]{--toast-icon:var(--color-warning)}.toast[data-type=error]{--toast-icon:var(--color-danger)}.toast__content{--toast-line:36px;--toast-text-line:var(--space-20);box-sizing:border-box;align-items:flex-start;gap:var(--space-12);height:100%;padding:var(--space-16);transition:opacity var(--duration-200) var(--ease-flat);padding-inline-start:calc(var(--space-16) + var(--space-4));display:flex;overflow:hidden}.toast__content[data-behind]{opacity:0}.toast__content[data-expanded]{opacity:1}.toast__icon{width:var(--space-16);height:var(--space-16);color:var(--toast-icon);pointer-events:none;flex-shrink:0;margin-block-start:calc((var(--toast-line) - var(--space-16)) / 2);display:flex}.toast__icon>svg{width:100%;height:100%}.toast__ring{box-sizing:border-box;border:var(--space-2) solid var(--color-rich);border-top-color:var(--color-dark-inversion);border-radius:50%;width:100%;height:100%;animation:.8s linear infinite toast-turn}@keyframes toast-turn{to{transform:rotate(360deg)}}.toast__body{align-items:flex-start;gap:var(--space-4) var(--space-12);flex-wrap:wrap;flex:1;min-width:0;display:flex}.toast__text{gap:var(--space-4);min-width:0;padding-block:calc((var(--toast-line) - var(--toast-text-line)) / 2);flex-direction:column;flex:auto;display:flex}.toast__title{margin:var(--space-0);color:var(--toast-title);font:var(--font-h4);font-family:var(--font-family);line-height:var(--toast-text-line);white-space:pre-line;overflow-wrap:anywhere}.toast__description{margin:var(--space-0);color:var(--toast-text);font:var(--font-paragraph);font-family:var(--font-family);text-wrap:pretty;white-space:pre-line;overflow-wrap:anywhere}.toast__description a{color:inherit;text-underline-offset:var(--space-4);text-decoration:underline}.toast__action,.toast__close{flex-shrink:0}.toast__close>svg{width:var(--space-16);height:var(--space-16)}@media (prefers-reduced-motion:reduce){.toast__ring{animation-duration:2.4s}}
package/dist/index.d.ts CHANGED
@@ -25,6 +25,19 @@ declare const ToastType: {
25
25
  readonly Loading: "loading";
26
26
  };
27
27
  type ToastType = (typeof ToastType)[keyof typeof ToastType];
28
+ /**
29
+ * The corner the stack stands in, the top right by default. On a phone the
30
+ * stack takes the full width at the top or the bottom.
31
+ */
32
+ declare const ToastPosition: {
33
+ readonly TopLeft: "top-left";
34
+ readonly TopCenter: "top-center";
35
+ readonly TopRight: "top-right";
36
+ readonly BottomLeft: "bottom-left";
37
+ readonly BottomCenter: "bottom-center";
38
+ readonly BottomRight: "bottom-right";
39
+ };
40
+ type ToastPosition = (typeof ToastPosition)[keyof typeof ToastPosition];
28
41
  /**
29
42
  * What `toast.add` takes: Base UI's options without `timeout`. A toast either
30
43
  * goes away by itself after five seconds, or stays until the user closes it or
@@ -96,8 +109,17 @@ type ToasterProps = Omit<Toast$1.Provider.Props, 'timeout' | 'limit'> & {
96
109
  * scroll, so it stops at five. @default 3
97
110
  */
98
111
  limit?: ToastLimit;
112
+ /**
113
+ * The corner the stack stands in. Its distance from the edges is the
114
+ * `--toast-offset-top`, `-right`, `-bottom` and `-left` custom properties,
115
+ * 16px each by default. @default 'top-right'
116
+ */
117
+ position?: ToastPosition;
118
+ };
119
+ type ToastViewportProps = WithClassName<Toast$1.Viewport.Props> & {
120
+ /** The corner the stack stands in. @default 'top-right' */
121
+ position?: ToastPosition;
99
122
  };
100
- type ToastViewportProps = WithClassName<Toast$1.Viewport.Props>;
101
123
  type ToastProps = WithClassName<Toast$1.Root.Props>;
102
124
  type ToastContentProps = WithClassName<Toast$1.Content.Props>;
103
125
  type ToastTitleProps = WithClassName<Toast$1.Title.Props>;
@@ -129,10 +151,10 @@ declare const createToastManager: () => ToastManager;
129
151
  declare const toast: ToastManager;
130
152
  declare const ToastProvider: (props: Toast$1.Provider.Props) => react_jsx_runtime.JSX.Element;
131
153
  declare const ToastPortal: (props: Toast$1.Portal.Props) => react_jsx_runtime.JSX.Element;
132
- /** The corner the toasts stack in: the bottom right, and the full width on a phone. */
133
- declare const ToastViewport: ({ className, ...props }: ToastViewportProps) => react_jsx_runtime.JSX.Element;
154
+ /** The corner the toasts stack in; the full width at its edge on a phone. */
155
+ declare const ToastViewport: ({ className, position, ...props }: ToastViewportProps) => react_jsx_runtime.JSX.Element;
134
156
  /** One toast in the stack. The stylesheet moves it by the custom properties Base UI writes on it. */
135
- declare const Toast: ({ className, ...props }: ToastProps) => react_jsx_runtime.JSX.Element;
157
+ declare const Toast: ({ className, swipeDirection, ...props }: ToastProps) => react_jsx_runtime.JSX.Element;
136
158
  /** The row inside: the icon, the text, the action and the close button. It fades out behind the front toast. */
137
159
  declare const ToastContent: ({ className, ...props }: ToastContentProps) => react_jsx_runtime.JSX.Element;
138
160
  declare const ToastTitle: ({ className, ...props }: ToastTitleProps) => react_jsx_runtime.JSX.Element;
@@ -149,7 +171,7 @@ declare const ToastIcon: ({ type }: ToastIconProps) => react_jsx_runtime.JSX.Ele
149
171
  * corner — a reference, a preview — draws it with this too.
150
172
  */
151
173
  declare const ToastItem: ({ toast: item, ...props }: ToastProps) => react_jsx_runtime.JSX.Element;
152
- declare const Toaster: ({ children, toastManager, limit, ...props }: ToasterProps) => react_jsx_runtime.JSX.Element;
174
+ declare const Toaster: ({ children, toastManager, limit, position, ...props }: ToasterProps) => react_jsx_runtime.JSX.Element;
153
175
  /**
154
176
  * The toasts of the nearest Toaster or ToastProvider, to draw them — as
155
177
  * ToastItem does in a reference page. It reads and does not add: Base UI's own
@@ -159,5 +181,5 @@ declare const Toaster: ({ children, toastManager, limit, ...props }: ToasterProp
159
181
  */
160
182
  declare const useToasts: () => _base_ui_components_react_toast.ToastObject<any>[];
161
183
 
162
- export { Toast, ToastAction, ToastClose, ToastContent, ToastDescription, ToastIcon, ToastItem, ToastPortal, ToastProvider, ToastTitle, ToastType, ToastViewport, Toaster, createToastManager, Toaster as default, toast, useToasts };
184
+ export { Toast, ToastAction, ToastClose, ToastContent, ToastDescription, ToastIcon, ToastItem, ToastPortal, ToastPosition, ToastProvider, ToastTitle, ToastType, ToastViewport, Toaster, createToastManager, Toaster as default, toast, useToasts };
163
185
  export type { ToastActionProps, ToastCloseProps, ToastContentProps, ToastDescriptionProps, ToastIconProps, ToastLimit, ToastManager, ToastOptions, ToastProps, ToastShortcutOptions, ToastTitleProps, ToastViewportProps, ToasterProps };
package/dist/index.js CHANGED
@@ -1,22 +1,30 @@
1
1
  import { Toast as e } from "@base-ui-components/react/toast";
2
2
  import { buttonVariants as t } from "@propellerads/button";
3
- import { clsx as n } from "clsx";
4
- import { jsx as r, jsxs as i } from "react/jsx-runtime";
3
+ import { createContext as n, useContext as r } from "react";
4
+ import { clsx as i } from "clsx";
5
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
5
6
  import './index.css';//#region src/cn.ts
6
- var a = (...e) => n(e), o = {
7
+ var s = (...e) => i(e), c = {
7
8
  Default: "default",
8
9
  Success: "success",
9
10
  Info: "info",
10
11
  Warning: "warning",
11
12
  Error: "error",
12
13
  Loading: "loading"
13
- }, s = ({ persistent: e, ...t }) => {
14
+ }, l = {
15
+ TopLeft: "top-left",
16
+ TopCenter: "top-center",
17
+ TopRight: "top-right",
18
+ BottomLeft: "bottom-left",
19
+ BottomCenter: "bottom-center",
20
+ BottomRight: "bottom-right"
21
+ }, u = ({ persistent: e, ...t }) => {
14
22
  let n = { ...t };
15
23
  return delete n.timeout, e === !0 && (n.timeout = 0, n.priority = t.priority ?? "high"), n;
16
- }, c = () => {
17
- let t = e.createToastManager(), n = /* @__PURE__ */ new Map(), r = 0, i = 0, a = [], c = (e) => {
24
+ }, d = () => {
25
+ let t = e.createToastManager(), n = /* @__PURE__ */ new Map(), r = 0, i = 0, a = [], o = (e) => {
18
26
  i > 0 ? e() : a.push(e);
19
- }, l = (e) => {
27
+ }, s = (e) => {
20
28
  let r = t[" subscribe"](e);
21
29
  i += 1;
22
30
  for (let e of a.splice(0)) e();
@@ -27,9 +35,9 @@ var a = (...e) => n(e), o = {
27
35
  if (!(i > 0)) for (let [t, r] of e) n.get(t) === r && n.delete(t);
28
36
  });
29
37
  };
30
- }, u = (e) => n.get(e) ?? [...n.values()].find((t) => t.internal === e), d = (e, { onClose: t, onRemove: n }) => {
38
+ }, l = (e) => n.get(e) ?? [...n.values()].find((t) => t.internal === e), d = (e, { onClose: t, onRemove: n }) => {
31
39
  e.onClose = t ?? e.onClose, e.onRemove = n ?? e.onRemove;
32
- }, f = ({ onClose: e, onRemove: t, id: n, ...r }) => s(r), p = (e, t, r) => ({
40
+ }, f = ({ onClose: e, onRemove: t, id: n, ...r }) => u(r), p = (e, t, r) => ({
33
41
  ...f(r),
34
42
  id: t.internal,
35
43
  onClose: () => {
@@ -39,17 +47,17 @@ var a = (...e) => n(e), o = {
39
47
  n.get(e) === t && n.delete(e), t.onRemove?.();
40
48
  }
41
49
  }), m = (e, n) => {
42
- let r = u(e);
50
+ let r = l(e);
43
51
  if (!r) return;
44
52
  d(r, n);
45
53
  let i = r.pending;
46
- if (!i || n.type === void 0 || n.type === o.Loading) {
47
- c(() => t.update(r.internal, f(n)));
54
+ if (!i || n.type === void 0 || n.type === c.Loading) {
55
+ o(() => t.update(r.internal, f(n)));
48
56
  return;
49
57
  }
50
58
  r.pending = void 0;
51
59
  let { type: a } = n;
52
- a === o.Error ? i.reject(f(n)) : i.resolve(f(n)), a !== o.Success && a !== o.Error && c(() => queueMicrotask(() => t.update(r.internal, { type: a === o.Default ? void 0 : a })));
60
+ a === c.Error ? i.reject(f(n)) : i.resolve(f(n)), a !== c.Success && a !== c.Error && o(() => queueMicrotask(() => t.update(r.internal, { type: a === c.Default ? void 0 : a })));
53
61
  }, h = (e) => {
54
62
  if (e.id !== void 0 && n.get(e.id)?.active) return m(e.id, e), e.id;
55
63
  r += 1;
@@ -57,14 +65,14 @@ var a = (...e) => n(e), o = {
57
65
  internal: n.has(i) ? `${i}~${r}` : i,
58
66
  active: !0
59
67
  };
60
- if (d(a, e), n.set(i, a), e.type !== o.Loading) return c(() => t.add(p(i, a, e))), i;
68
+ if (d(a, e), n.set(i, a), e.type !== c.Loading) return o(() => t.add(p(i, a, e))), i;
61
69
  let s = new Promise((e, t) => {
62
70
  a.pending = {
63
71
  resolve: e,
64
72
  reject: t
65
73
  };
66
74
  });
67
- return c(() => {
75
+ return o(() => {
68
76
  t.promise(s, {
69
77
  loading: p(i, a, e),
70
78
  success: (e) => e,
@@ -72,22 +80,22 @@ var a = (...e) => n(e), o = {
72
80
  }).catch(() => void 0);
73
81
  }), i;
74
82
  }, g = (e) => {
75
- let n = u(e);
76
- n && (n.pending = void 0, c(() => t.close(n.internal)));
83
+ let n = l(e);
84
+ n && (n.pending = void 0, o(() => t.close(n.internal)));
77
85
  }, _ = (e, t) => {
78
86
  let n = typeof e == "function" ? e(t) : e;
79
87
  return typeof n == "string" ? { title: n } : n;
80
88
  }, v = (e, t) => {
81
89
  let n = h({
82
90
  ..._(t.loading),
83
- type: o.Loading
91
+ type: c.Loading
84
92
  });
85
93
  return e.then((e) => (m(n, {
86
- type: o.Success,
94
+ type: c.Success,
87
95
  ..._(t.success, e)
88
96
  }), e), (e) => {
89
97
  throw t.error === void 0 ? g(n) : m(n, {
90
- type: o.Error,
98
+ type: c.Error,
91
99
  ..._(t.error, e)
92
100
  }), e;
93
101
  });
@@ -98,99 +106,123 @@ var a = (...e) => n(e), o = {
98
106
  });
99
107
  return {
100
108
  ...t,
101
- " subscribe": l,
109
+ " subscribe": s,
102
110
  add: h,
103
111
  update: m,
104
112
  close: g,
105
113
  promise: v,
106
- isActive: (e) => u(e)?.active === !0,
107
- success: y(o.Success),
108
- info: y(o.Info),
109
- warning: y(o.Warning),
110
- error: y(o.Error),
111
- loading: y(o.Loading)
114
+ isActive: (e) => l(e)?.active === !0,
115
+ success: y(c.Success),
116
+ info: y(c.Info),
117
+ warning: y(c.Warning),
118
+ error: y(c.Error),
119
+ loading: y(c.Loading)
112
120
  };
113
- }, l = c(), u = (t) => /* @__PURE__ */ r(e.Provider, { ...t }), d = (t) => /* @__PURE__ */ r(e.Portal, {
121
+ }, f = d(), p = (t) => /* @__PURE__ */ a(e.Provider, { ...t }), m = (t) => /* @__PURE__ */ a(e.Portal, {
114
122
  "data-slot": "toast-portal",
115
123
  ...t
116
- }), f = ({ className: t, ...n }) => /* @__PURE__ */ r(e.Viewport, {
117
- "data-slot": "toast-viewport",
118
- className: a("toast-viewport", t),
119
- ...n
120
- }), p = ({ className: t, ...n }) => /* @__PURE__ */ r(e.Root, {
121
- "data-slot": "toast",
122
- className: a("toast", t),
123
- ...n
124
- }), m = ({ className: t, ...n }) => /* @__PURE__ */ r(e.Content, {
124
+ }), h = Object.values(l), g = (e) => {
125
+ let [t, n] = (h.includes(e) ? e : l.TopRight).split("-");
126
+ return {
127
+ x: n,
128
+ y: t
129
+ };
130
+ }, _ = (e) => {
131
+ let { x: t, y: n } = g(e), r = n === "top" ? "up" : "down";
132
+ return t === "center" ? [r] : [r, t];
133
+ }, v = n(l.TopRight), y = ({ className: t, position: n = l.TopRight, ...r }) => {
134
+ let { x: i, y: o } = g(n);
135
+ return /* @__PURE__ */ a(v.Provider, {
136
+ value: n,
137
+ children: /* @__PURE__ */ a(e.Viewport, {
138
+ "data-slot": "toast-viewport",
139
+ "data-x-position": i,
140
+ "data-y-position": o,
141
+ className: s("toast-viewport", t),
142
+ ...r
143
+ })
144
+ });
145
+ }, b = ({ className: t, swipeDirection: n, ...i }) => {
146
+ let o = r(v);
147
+ return /* @__PURE__ */ a(e.Root, {
148
+ "data-slot": "toast",
149
+ className: s("toast", t),
150
+ swipeDirection: n ?? _(o),
151
+ ...i
152
+ });
153
+ }, x = ({ className: t, ...n }) => /* @__PURE__ */ a(e.Content, {
125
154
  "data-slot": "toast-content",
126
- className: a("toast__content", t),
155
+ className: s("toast__content", t),
127
156
  ...n
128
- }), h = ({ className: t, ...n }) => /* @__PURE__ */ r(e.Title, {
157
+ }), S = ({ className: t, ...n }) => /* @__PURE__ */ a(e.Title, {
129
158
  "data-slot": "toast-title",
130
- className: a("toast__title", t),
159
+ className: s("toast__title", t),
131
160
  ...n
132
- }), g = ({ className: t, ...n }) => /* @__PURE__ */ r(e.Description, {
161
+ }), C = ({ className: t, ...n }) => /* @__PURE__ */ a(e.Description, {
133
162
  "data-slot": "toast-description",
134
- className: a("toast__description", t),
163
+ className: s("toast__description", t),
135
164
  ...n
136
- }), _ = ({ className: n, ...i }) => /* @__PURE__ */ r(e.Action, {
165
+ }), w = ({ className: n, ...r }) => /* @__PURE__ */ a(e.Action, {
137
166
  "data-slot": "toast-action",
138
- className: a(t({ variant: "secondary" }), "toast__action", n),
139
- ...i
140
- }), v = ({ children: e }) => /* @__PURE__ */ r("svg", {
167
+ className: s(t({ variant: "secondary" }), "toast__action", n),
168
+ ...r
169
+ }), T = ({ children: e }) => /* @__PURE__ */ a("svg", {
141
170
  viewBox: "0 0 24 24",
142
171
  fill: "currentColor",
143
172
  "aria-hidden": "true",
144
173
  focusable: "false",
145
174
  children: e
146
- }), y = () => /* @__PURE__ */ r(v, { children: /* @__PURE__ */ r("path", { d: "M18.3 5.71c-.39-.39-1.02-.39-1.41 0L12 10.59 7.11 5.7c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41L10.59 12 5.7 16.89c-.39.39-.39 1.02 0 1.41.39.39 1.02.39 1.41 0L12 13.41l4.89 4.89c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41L13.41 12l4.89-4.89c.38-.38.38-1.02 0-1.4z" }) }), b = {
147
- [o.Success]: /* @__PURE__ */ r(v, { children: /* @__PURE__ */ r("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" }) }),
148
- [o.Info]: /* @__PURE__ */ r(v, { children: /* @__PURE__ */ r("path", { d: "M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" }) }),
149
- [o.Warning]: /* @__PURE__ */ r(v, { children: /* @__PURE__ */ r("path", { d: "M12 5.98999L19.53 19H4.47L12 5.98999ZM2.74 18C1.97 19.33 2.93 21 4.47 21H19.53C21.07 21 22.03 19.33 21.26 18L13.73 4.98999C12.96 3.65999 11.04 3.65999 10.27 4.98999L2.74 18ZM11 11V13C11 13.55 11.45 14 12 14C12.55 14 13 13.55 13 13V11C13 10.45 12.55 9.99999 12 9.99999C11.45 9.99999 11 10.45 11 11ZM11 16H13V18H11V16Z" }) }),
150
- [o.Error]: /* @__PURE__ */ r(v, { children: /* @__PURE__ */ r("path", { d: "M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1zm-.01-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm1-3h-2v-2h2v2z" }) }),
151
- [o.Loading]: /* @__PURE__ */ r("span", { className: "toast__ring" })
152
- }, x = ({ className: n, children: i, ...o }) => /* @__PURE__ */ r(e.Close, {
175
+ }), E = () => /* @__PURE__ */ a(T, { children: /* @__PURE__ */ a("path", { d: "M18.3 5.71c-.39-.39-1.02-.39-1.41 0L12 10.59 7.11 5.7c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41L10.59 12 5.7 16.89c-.39.39-.39 1.02 0 1.41.39.39 1.02.39 1.41 0L12 13.41l4.89 4.89c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41L13.41 12l4.89-4.89c.38-.38.38-1.02 0-1.4z" }) }), D = {
176
+ [c.Success]: /* @__PURE__ */ a(T, { children: /* @__PURE__ */ a("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" }) }),
177
+ [c.Info]: /* @__PURE__ */ a(T, { children: /* @__PURE__ */ a("path", { d: "M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z" }) }),
178
+ [c.Warning]: /* @__PURE__ */ a(T, { children: /* @__PURE__ */ a("path", { d: "M12 5.98999L19.53 19H4.47L12 5.98999ZM2.74 18C1.97 19.33 2.93 21 4.47 21H19.53C21.07 21 22.03 19.33 21.26 18L13.73 4.98999C12.96 3.65999 11.04 3.65999 10.27 4.98999L2.74 18ZM11 11V13C11 13.55 11.45 14 12 14C12.55 14 13 13.55 13 13V11C13 10.45 12.55 9.99999 12 9.99999C11.45 9.99999 11 10.45 11 11ZM11 16H13V18H11V16Z" }) }),
179
+ [c.Error]: /* @__PURE__ */ a(T, { children: /* @__PURE__ */ a("path", { d: "M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1zm-.01-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm1-3h-2v-2h2v2z" }) }),
180
+ [c.Loading]: /* @__PURE__ */ a("span", { className: "toast__ring" })
181
+ }, O = ({ className: n, children: r, ...i }) => /* @__PURE__ */ a(e.Close, {
153
182
  "data-slot": "toast-close",
154
183
  "aria-label": "Close",
155
- className: a(t({
184
+ className: s(t({
156
185
  variant: "ghost",
157
186
  iconOnly: !0,
158
187
  quiet: !0
159
188
  }), "toast__close", n),
160
- ...o,
161
- children: i ?? /* @__PURE__ */ r(y, {})
162
- }), S = ({ type: e }) => {
163
- let t = e === void 0 ? void 0 : b[e];
164
- return t ? /* @__PURE__ */ r("span", {
189
+ ...i,
190
+ children: r ?? /* @__PURE__ */ a(E, {})
191
+ }), k = ({ type: e }) => {
192
+ let t = e === void 0 ? void 0 : D[e];
193
+ return t ? /* @__PURE__ */ a("span", {
165
194
  "data-slot": "toast-icon",
166
195
  className: "toast__icon",
167
196
  "aria-hidden": !0,
168
197
  children: t
169
198
  }) : null;
170
- }, C = ({ toast: e, ...t }) => /* @__PURE__ */ r(p, {
199
+ }, A = ({ toast: e, ...t }) => /* @__PURE__ */ a(b, {
171
200
  toast: e,
172
201
  ...t,
173
- children: /* @__PURE__ */ i(m, { children: [
174
- /* @__PURE__ */ r(S, { type: e.type }),
175
- /* @__PURE__ */ i("div", {
202
+ children: /* @__PURE__ */ o(x, { children: [
203
+ /* @__PURE__ */ a(k, { type: e.type }),
204
+ /* @__PURE__ */ o("div", {
176
205
  className: "toast__body",
177
- children: [/* @__PURE__ */ i("div", {
206
+ children: [/* @__PURE__ */ o("div", {
178
207
  className: "toast__text",
179
- children: [/* @__PURE__ */ r(h, {}), /* @__PURE__ */ r(g, {})]
180
- }), /* @__PURE__ */ r(_, {})]
208
+ children: [/* @__PURE__ */ a(S, {}), /* @__PURE__ */ a(C, {})]
209
+ }), /* @__PURE__ */ a(w, {})]
181
210
  }),
182
- /* @__PURE__ */ r(x, {})
211
+ /* @__PURE__ */ a(O, {})
183
212
  ] })
184
- }), w = () => {
213
+ }), j = () => {
185
214
  let { toasts: t } = e.useToastManager();
186
- return t.map((e) => /* @__PURE__ */ r(C, { toast: e }, e.id));
187
- }, T = 5, E = ({ children: e, toastManager: t = l, limit: n = 3, ...a }) => /* @__PURE__ */ i(u, {
215
+ return t.map((e) => /* @__PURE__ */ a(A, { toast: e }, e.id));
216
+ }, M = 5, N = ({ children: e, toastManager: t = f, limit: n = 3, position: r = l.TopRight, ...i }) => /* @__PURE__ */ o(p, {
188
217
  toastManager: t,
189
- limit: Math.min(Math.max(n, 1), T),
190
- ...a,
191
- children: [e, /* @__PURE__ */ r(d, { children: /* @__PURE__ */ r(f, { children: /* @__PURE__ */ r(w, {}) }) })]
192
- }), D = () => e.useToastManager().toasts;
218
+ limit: Math.min(Math.max(n, 1), M),
219
+ ...i,
220
+ children: [e, /* @__PURE__ */ a(m, { children: /* @__PURE__ */ a(y, {
221
+ position: r,
222
+ children: /* @__PURE__ */ a(j, {})
223
+ }) })]
224
+ }), P = () => e.useToastManager().toasts;
193
225
  //#endregion
194
- export { p as Toast, _ as ToastAction, x as ToastClose, m as ToastContent, g as ToastDescription, S as ToastIcon, C as ToastItem, d as ToastPortal, u as ToastProvider, h as ToastTitle, o as ToastType, f as ToastViewport, E as Toaster, E as default, c as createToastManager, l as toast, D as useToasts };
226
+ export { b as Toast, w as ToastAction, O as ToastClose, x as ToastContent, C as ToastDescription, k as ToastIcon, A as ToastItem, m as ToastPortal, l as ToastPosition, p as ToastProvider, S as ToastTitle, c as ToastType, y as ToastViewport, N as Toaster, N as default, d as createToastManager, f as toast, P as useToasts };
195
227
 
196
228
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/cn.ts","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the toast\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {\n ToastManagerAddOptions,\n Toast as ToastPrimitive,\n ToastManager as ToastPrimitiveManager,\n} from '@base-ui-components/react/toast';\nimport type {ReactNode} from 'react';\n\n/**\n * What the toast is about: the icon in front of the title and its colour. These\n * are the types shadcn's renderer recognises. The danger one is `error` rather\n * than the `danger` of Alert and the tokens, because `toast.promise` writes\n * `loading`, `success` and `error` itself, and a toast it settles has to look\n * like one added by hand.\n */\nexport const ToastType = {\n /** No status, no icon: the plain message. */\n Default: 'default',\n /** A scenario that worked: the --color-success icon. */\n Success: 'success',\n /** Something to know: the --color-action icon. */\n Info: 'info',\n /** Nothing is broken yet: the --color-warning icon. */\n Warning: 'warning',\n /** Something failed: the --color-danger icon. */\n Error: 'error',\n /** A task still running: a turning ring. It stays until it is updated or closed. */\n Loading: 'loading',\n} as const;\nexport type ToastType = (typeof ToastType)[keyof typeof ToastType];\n\n/**\n * What `toast.add` takes: Base UI's options without `timeout`. A toast either\n * goes away by itself after five seconds, or stays until the user closes it or\n * acts on it — `persistent`. No call site picks its own number of seconds.\n * `data` is anything of your own the toast carries.\n */\nexport type ToastOptions<Data extends object = {}> = Omit<ToastManagerAddOptions<Data>, 'timeout'> & {\n /**\n * Stays until the user closes it or presses its action: a new build to\n * reload for, a session that expired, cookie consent. It is announced at\n * once, as `priority: 'high'`, unless `priority` says otherwise.\n */\n persistent?: boolean;\n};\n\n/** What `toast.update` takes: any of the options, the rest stay as they were. */\nexport type ToastUpdateOptions<Data extends object = {}> = Partial<ToastOptions<Data>>;\n\n/** What the shortcuts take after the text: everything but the type and the title. */\nexport type ToastShortcutOptions<Data extends object = {}> = Omit<ToastOptions<Data>, 'type' | 'title'>;\n\n/** One stage of `toast.promise`: a title, the options, or a function of the result or the error. */\ntype ToastPromiseStage<Input, Data extends object> =\n | string\n | ToastUpdateOptions<Data>\n | ((input: Input) => string | ToastUpdateOptions<Data>);\n\nexport type ToastPromiseOptions<Value, Data extends object = {}> = {\n loading: string | ToastUpdateOptions<Data>;\n success: ToastPromiseStage<Value, Data>;\n /**\n * Left out, a failure closes the loading toast and says nothing: for a\n * request whose errors the app's own handler already shows, so that one\n * failure is one toast.\n */\n error?: ToastPromiseStage<any, Data>;\n};\n\n/** A shortcut for one type: the text is the title. Returns the toast's id. */\ntype Shortcut = <Data extends object>(title: ReactNode, options?: ToastShortcutOptions<Data>) => string;\n\n/**\n * Base UI's manager with what the cabinets lean on.\n *\n * - `add` with the `id` of a toast still on screen updates that toast instead\n * of stacking a second one, as react-toastify's `toastId` did.\n * - `update` of a loading toast to any other type starts its five seconds,\n * as `toast.promise` does when the promise settles.\n * - `isActive` says whether a toast is still on screen.\n * - One shortcut per type: `toast.error('Could not save')`.\n */\nexport type ToastManager = Omit<ToastPrimitiveManager, 'add' | 'update' | 'promise'> & {\n add: <Data extends object>(options: ToastOptions<Data>) => string;\n update: <Data extends object>(id: string, updates: ToastUpdateOptions<Data>) => void;\n promise: <Value, Data extends object>(\n promise: Promise<Value>,\n options: ToastPromiseOptions<Value, Data>,\n ) => Promise<Value>;\n isActive: (id: string) => boolean;\n success: Shortcut;\n info: Shortcut;\n warning: Shortcut;\n error: Shortcut;\n loading: Shortcut;\n};\n\n/**\n * A part's own props, with `className` as a string. Base UI also takes a\n * function of the part's state there; the parts here join the string with\n * their own class names, and a function cannot be joined.\n */\ntype WithClassName<Props> = Omit<Props, 'className'> & {className?: string};\n\n/** How many toasts stand in the stack at once: up to five, so a fanned-out stack fits a laptop's screen. */\nexport type ToastLimit = 1 | 2 | 3 | 4 | 5;\n\n/** Base UI's provider props without `timeout`: every toast that goes away by itself takes five seconds. */\nexport type ToasterProps = Omit<ToastPrimitive.Provider.Props, 'timeout' | 'limit'> & {\n /**\n * How many toasts stand at once. One over the limit is not dropped: it waits\n * unseen and comes forward when one in front closes. The stack does not\n * scroll, so it stops at five. @default 3\n */\n limit?: ToastLimit;\n};\nexport type ToastViewportProps = WithClassName<ToastPrimitive.Viewport.Props>;\nexport type ToastProps = WithClassName<ToastPrimitive.Root.Props>;\nexport type ToastContentProps = WithClassName<ToastPrimitive.Content.Props>;\nexport type ToastTitleProps = WithClassName<ToastPrimitive.Title.Props>;\nexport type ToastDescriptionProps = WithClassName<ToastPrimitive.Description.Props>;\nexport type ToastActionProps = WithClassName<ToastPrimitive.Action.Props>;\nexport type ToastCloseProps = WithClassName<ToastPrimitive.Close.Props>;\nexport type ToastIconProps = {type: string | undefined};\n","import {type ToastManagerAddOptions, Toast as ToastPrimitive} from '@base-ui-components/react/toast';\nimport {buttonVariants} from '@propellerads/button';\nimport type {ReactNode} from 'react';\nimport './toast.css';\nimport {cn} from './cn';\nimport {\n type ToastActionProps,\n type ToastCloseProps,\n type ToastContentProps,\n type ToastDescriptionProps,\n type ToasterProps,\n type ToastIconProps,\n type ToastManager,\n type ToastOptions,\n type ToastPromiseOptions,\n type ToastProps,\n type ToastShortcutOptions,\n type ToastTitleProps,\n ToastType,\n type ToastUpdateOptions,\n type ToastViewportProps,\n} from './types';\n\n/*\n * shadcn's Toast on Base UI, part for part: the same manager, the same stack\n * that fans out under the pointer, the same swipe to dismiss. The utility\n * classes are a stylesheet on @propellerads/tokens instead, the action and\n * the close button wear @propellerads/button, and the status icons are the\n * product's own from @propellerads/icon.\n */\n\n/* Base UI's own options, as the provider takes them. */\ntype PrimitiveOptions = ToastManagerAddOptions<object>;\n\n/** `persistent` in Base UI's words: no timeout, and announced at once. */\nconst toPrimitive = <Data extends object>({persistent, ...options}: ToastUpdateOptions<Data>) => {\n const primitive = {...options} as ToastUpdateOptions<Data> & {timeout?: number};\n // A call written against Base UI's own API keeps no number of seconds either.\n delete primitive.timeout;\n if (persistent === true) {\n primitive.timeout = 0;\n primitive.priority = options.priority ?? 'high';\n }\n return primitive as PrimitiveOptions;\n};\n\n/** A loading toast's promise, settled by the `update` that ends the loading. */\ntype Pending = {resolve: (options: PrimitiveOptions) => void; reject: (options: PrimitiveOptions) => void};\n\n/**\n * Base UI's manager, with what the cabinets did through react-toastify. A\n * toast stops being active as it starts to close, so an `add` with its id\n * while it slides out is a new toast rather than an update of a leaving one.\n *\n * A loading toast is Base UI's `promise` with a promise this manager holds:\n * Base UI starts a toast's seconds only when it is added or when its promise\n * settles, never on an update. The `update` that turns it into anything else\n * settles that promise, so the result goes away by itself as one from\n * `toast.promise` does.\n */\nconst createToastManager = (): ToastManager => {\n const manager = ToastPrimitive.createToastManager();\n\n /* One showing of a toast. The id the caller knows can be shown again while\n the last showing still slides out, and Base UI tells toasts apart by id\n alone — removing the one that left would take the new one with it. So\n each showing has an id of its own for Base UI, and keeps its own\n callbacks: an update merges into the toast, and one that names no\n callback must not take away those it was added with. */\n type Showing = {\n internal: string;\n active: boolean;\n pending?: Pending;\n onClose?: () => void;\n onRemove?: () => void;\n };\n\n /** The latest showing of each id the caller knows. */\n const showings = new Map<string, Showing>();\n let count = 0;\n\n /* Base UI hands an event only to a provider already listening, and the\n Toaster listens from its first effect on. A toast called before that — an\n interceptor on the app's first request — would be lost, and its id would\n stay active with nothing on screen. So until a provider listens, the calls\n wait here and play when it does. */\n let listeners = 0;\n const waiting: Array<() => void> = [];\n const send = (call: () => void): void => {\n if (listeners > 0) {\n call();\n } else {\n waiting.push(call);\n }\n };\n const subscribe: ToastManager[' subscribe'] = (listener) => {\n const unsubscribe = manager[' subscribe'](listener);\n listeners += 1;\n for (const call of waiting.splice(0)) {\n call();\n }\n return () => {\n unsubscribe();\n listeners -= 1;\n // The last Toaster gone takes its toasts with it: they will neither close\n // nor be removed, so their ids are forgotten and the next add shows anew.\n // Checked a step later — React in development unsubscribes and subscribes\n // straight back, and the toasts of that one Toaster stay on screen. Only\n // the showings it had are forgotten: one added in between is waiting for\n // the next Toaster and keeps its id.\n const gone = new Map(showings);\n queueMicrotask(() => {\n if (listeners > 0) {\n return;\n }\n for (const [id, showing] of gone) {\n if (showings.get(id) === showing) {\n showings.delete(id);\n }\n }\n });\n };\n };\n\n /**\n * The showing an id names: the id the caller knows, or the one Base UI has —\n * which `useToasts` hands out, so a toast drawn by hand can be closed by it.\n */\n const find = (id: string): Showing | undefined =>\n showings.get(id) ?? [...showings.values()].find((showing) => showing.internal === id);\n\n /** Keeps the callbacks an add or an update names, and those it leaves out. */\n const remember = (showing: Showing, {onClose, onRemove}: ToastUpdateOptions): void => {\n showing.onClose = onClose ?? showing.onClose;\n showing.onRemove = onRemove ?? showing.onRemove;\n };\n\n /** The options in Base UI's words, without the caller's callbacks: those live on the showing. */\n const bare = <Data extends object>({onClose, onRemove, id, ...options}: ToastUpdateOptions<Data>): PrimitiveOptions =>\n toPrimitive(options);\n\n /* The showing's own callbacks, set once as it is added: they mark it gone\n and call whatever the caller has kept on it by then. The id the caller\n knows forgets the showing only if no newer one has taken it. */\n const tracked = <Data extends object>(id: string, showing: Showing, options: ToastUpdateOptions<Data>) => ({\n ...bare(options),\n id: showing.internal,\n onClose: () => {\n showing.active = false;\n showing.pending = undefined;\n showing.onClose?.();\n },\n onRemove: () => {\n if (showings.get(id) === showing) {\n showings.delete(id);\n }\n showing.onRemove?.();\n },\n });\n\n const update = <Data extends object>(id: string, updates: ToastUpdateOptions<Data>): void => {\n const showing = find(id);\n if (!showing) {\n return;\n }\n remember(showing, updates);\n const loading = showing.pending;\n if (!loading || updates.type === undefined || updates.type === ToastType.Loading) {\n send(() => manager.update(showing.internal, bare(updates)));\n return;\n }\n\n showing.pending = undefined;\n // Base UI writes `success` on a resolve and `error` on a reject; any other\n // type is written back right after it.\n const {type} = updates;\n if (type === ToastType.Error) {\n loading.reject(bare(updates));\n } else {\n loading.resolve(bare(updates));\n }\n if (type !== ToastType.Success && type !== ToastType.Error) {\n send(() =>\n queueMicrotask(() => manager.update(showing.internal, {type: type === ToastType.Default ? undefined : type})),\n );\n }\n };\n\n const add = <Data extends object>(options: ToastOptions<Data>): string => {\n if (options.id !== undefined && showings.get(options.id)?.active) {\n update(options.id, options);\n return options.id;\n }\n\n count += 1;\n // A tilde no caller writes keeps these apart from the ids the caller picks.\n const id = options.id ?? `~toast-${count}`;\n // An id still sliding out under its last showing takes a fresh one for Base UI.\n const internal = showings.has(id) ? `${id}~${count}` : id;\n const showing: Showing = {internal, active: true};\n remember(showing, options);\n showings.set(id, showing);\n\n if (options.type !== ToastType.Loading) {\n send(() => manager.add(tracked(id, showing, options)));\n return id;\n }\n\n const settled = new Promise<PrimitiveOptions>((resolve, reject) => {\n showing.pending = {resolve, reject};\n });\n send(() => {\n manager\n .promise(settled, {\n loading: tracked(id, showing, options),\n success: (result: PrimitiveOptions) => result,\n error: (result: PrimitiveOptions) => result,\n })\n // The rejection is how a loading toast turns into an error; nobody awaits it.\n .catch(() => undefined);\n });\n return id;\n };\n\n const close = (id: string): void => {\n const showing = find(id);\n if (!showing) {\n return;\n }\n showing.pending = undefined;\n send(() => manager.close(showing.internal));\n };\n\n /* A stage of `toast.promise` as options: text alone is the title, as in the shortcuts. */\n const stage = <Input, Data extends object>(\n value: string | ToastUpdateOptions<Data> | ((input: Input) => string | ToastUpdateOptions<Data>),\n input?: Input,\n ): ToastUpdateOptions<Data> => {\n const resolved = typeof value === 'function' ? value(input as Input) : value;\n return typeof resolved === 'string' ? {title: resolved} : resolved;\n };\n\n /**\n * A loading toast that the promise ends. It is this manager's loading and\n * update rather than Base UI's own `promise`, which writes `success` over\n * whatever the stage says: here a stage may end in a warning — partly done —\n * or in any other type it names.\n */\n const promise = <Value, Data extends object>(\n work: Promise<Value>,\n options: ToastPromiseOptions<Value, Data>,\n ): Promise<Value> => {\n const id = add({...stage(options.loading), type: ToastType.Loading});\n return work.then(\n (result) => {\n update(id, {type: ToastType.Success, ...stage(options.success, result)});\n return result;\n },\n (error: unknown) => {\n if (options.error === undefined) {\n close(id);\n } else {\n update(id, {type: ToastType.Error, ...stage(options.error, error)});\n }\n throw error;\n },\n );\n };\n\n const shortcut =\n (type: ToastType) =>\n <Data extends object>(title: ReactNode, options?: ToastShortcutOptions<Data>) =>\n add({...options, type, title});\n\n return {\n ...manager,\n ' subscribe': subscribe,\n add,\n update,\n close,\n promise,\n isActive: (id) => find(id)?.active === true,\n success: shortcut(ToastType.Success),\n info: shortcut(ToastType.Info),\n warning: shortcut(ToastType.Warning),\n error: shortcut(ToastType.Error),\n loading: shortcut(ToastType.Loading),\n };\n};\n\n/**\n * The manager the app calls from anywhere, components or not — an axios\n * interceptor, a saga, a jQuery widget: `toast.error('Could not save')`,\n * `toast.add({type: 'success', title: 'Saved'})`. `<Toaster />` renders what\n * it holds.\n */\nconst toast = createToastManager();\n\nconst ToastProvider = (props: ToastPrimitive.Provider.Props) => <ToastPrimitive.Provider {...props} />;\n\nconst ToastPortal = (props: ToastPrimitive.Portal.Props) => (\n <ToastPrimitive.Portal data-slot=\"toast-portal\" {...props} />\n);\n\n/** The corner the toasts stack in: the bottom right, and the full width on a phone. */\nconst ToastViewport = ({className, ...props}: ToastViewportProps) => (\n <ToastPrimitive.Viewport data-slot=\"toast-viewport\" className={cn('toast-viewport', className)} {...props} />\n);\n\n/** One toast in the stack. The stylesheet moves it by the custom properties Base UI writes on it. */\nconst Toast = ({className, ...props}: ToastProps) => (\n <ToastPrimitive.Root data-slot=\"toast\" className={cn('toast', className)} {...props} />\n);\n\n/** The row inside: the icon, the text, the action and the close button. It fades out behind the front toast. */\nconst ToastContent = ({className, ...props}: ToastContentProps) => (\n <ToastPrimitive.Content data-slot=\"toast-content\" className={cn('toast__content', className)} {...props} />\n);\n\nconst ToastTitle = ({className, ...props}: ToastTitleProps) => (\n <ToastPrimitive.Title data-slot=\"toast-title\" className={cn('toast__title', className)} {...props} />\n);\n\nconst ToastDescription = ({className, ...props}: ToastDescriptionProps) => (\n <ToastPrimitive.Description\n data-slot=\"toast-description\"\n className={cn('toast__description', className)}\n {...props}\n />\n);\n\n/** The one button a toast may carry — undo, retry, open. It takes its label and handler from `actionProps`. */\nconst ToastAction = ({className, ...props}: ToastActionProps) => (\n <ToastPrimitive.Action\n data-slot=\"toast-action\"\n className={cn(buttonVariants({variant: 'secondary'}), 'toast__action', className)}\n {...props}\n />\n);\n\n/* The icons are the paths of @propellerads/icon. That package draws through\n styled-components; a toast has no other use for it, so it carries the\n paths themselves. */\nconst Svg = ({children}: {children: ReactNode}) => (\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\" focusable=\"false\">\n {children}\n </svg>\n);\n\n/* Close */\nconst CloseIcon = () => (\n <Svg>\n <path d=\"M18.3 5.71c-.39-.39-1.02-.39-1.41 0L12 10.59 7.11 5.7c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41L10.59 12 5.7 16.89c-.39.39-.39 1.02 0 1.41.39.39 1.02.39 1.41 0L12 13.41l4.89 4.89c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41L13.41 12l4.89-4.89c.38-.38.38-1.02 0-1.4z\" />\n </Svg>\n);\n\n/* CheckCircle, InfoOutline, WarningOutline and Error, as Alert's stories pair them with the statuses. */\nconst STATUS_ICONS: Partial<Record<string, ReactNode>> = {\n [ToastType.Success]: (\n <Svg>\n <path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\" />\n </Svg>\n ),\n [ToastType.Info]: (\n <Svg>\n <path d=\"M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z\" />\n </Svg>\n ),\n [ToastType.Warning]: (\n <Svg>\n <path d=\"M12 5.98999L19.53 19H4.47L12 5.98999ZM2.74 18C1.97 19.33 2.93 21 4.47 21H19.53C21.07 21 22.03 19.33 21.26 18L13.73 4.98999C12.96 3.65999 11.04 3.65999 10.27 4.98999L2.74 18ZM11 11V13C11 13.55 11.45 14 12 14C12.55 14 13 13.55 13 13V11C13 10.45 12.55 9.99999 12 9.99999C11.45 9.99999 11 10.45 11 11ZM11 16H13V18H11V16Z\" />\n </Svg>\n ),\n [ToastType.Error]: (\n <Svg>\n <path d=\"M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1zm-.01-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm1-3h-2v-2h2v2z\" />\n </Svg>\n ),\n // The ring is drawn by the stylesheet, the way the Spinner draws its own.\n [ToastType.Loading]: <span className=\"toast__ring\" />,\n};\n\n/** The close button at the end of the row, a ghost square with a hit area wider than itself. */\nconst ToastClose = ({className, children, ...props}: ToastCloseProps) => (\n <ToastPrimitive.Close\n data-slot=\"toast-close\"\n aria-label=\"Close\"\n className={cn(buttonVariants({variant: 'ghost', iconOnly: true, quiet: true}), 'toast__close', className)}\n {...props}\n >\n {children ?? <CloseIcon />}\n </ToastPrimitive.Close>\n);\n\n/** The status icon, in the status colour. A toast of no known type has none. The title says what it shows. */\nconst ToastIcon = ({type}: ToastIconProps) => {\n const icon = type === undefined ? undefined : STATUS_ICONS[type];\n\n return icon ? (\n <span data-slot=\"toast-icon\" className=\"toast__icon\" aria-hidden>\n {icon}\n </span>\n ) : null;\n};\n\n/**\n * One toast as the Toaster draws it: the icon, the title and the description,\n * the action, and the cross. A page that shows a toast outside the\n * corner — a reference, a preview — draws it with this too.\n */\nconst ToastItem = ({toast: item, ...props}: ToastProps) => (\n <Toast toast={item} {...props}>\n <ToastContent>\n <ToastIcon type={item.type} />\n <div className=\"toast__body\">\n <div className=\"toast__text\">\n <ToastTitle />\n <ToastDescription />\n </div>\n <ToastAction />\n </div>\n <ToastClose />\n </ToastContent>\n </Toast>\n);\n\n/** Every toast the manager holds, drawn the one way. */\nconst ToastList = () => {\n const {toasts} = ToastPrimitive.useToastManager();\n\n return toasts.map((item) => <ToastItem key={item.id} toast={item} />);\n};\n\n/**\n * Put once at the root of the app, around it or beside it. It renders the\n * toasts of `toast`, or of the manager passed in — a second Toaster with a\n * manager of its own is a second stack.\n */\n/** The most toasts a stack holds, whatever a call from plain JS asks for. */\nconst MAX_LIMIT = 5;\n\nconst Toaster = ({children, toastManager = toast, limit = 3, ...props}: ToasterProps) => (\n <ToastProvider toastManager={toastManager} limit={Math.min(Math.max(limit, 1), MAX_LIMIT)} {...props}>\n {children}\n <ToastPortal>\n <ToastViewport>\n <ToastList />\n </ToastViewport>\n </ToastPortal>\n </ToastProvider>\n);\n\n/**\n * The toasts of the nearest Toaster or ToastProvider, to draw them — as\n * ToastItem does in a reference page. It reads and does not add: Base UI's own\n * hook would add past this package's manager, without `persistent`, the id\n * check or `isActive`. Toasts are added with `toast` or a manager from\n * `createToastManager`.\n */\nconst useToasts = () => ToastPrimitive.useToastManager().toasts;\n\nexport default Toaster;\n\nexport type {\n ToastActionProps,\n ToastCloseProps,\n ToastContentProps,\n ToastDescriptionProps,\n ToasterProps,\n ToastIconProps,\n ToastLimit,\n ToastManager,\n ToastOptions,\n ToastProps,\n ToastShortcutOptions,\n ToastTitleProps,\n ToastViewportProps,\n} from './types';\nexport {\n createToastManager,\n Toast,\n ToastAction,\n ToastClose,\n ToastContent,\n ToastDescription,\n Toaster,\n ToastIcon,\n ToastItem,\n ToastPortal,\n ToastProvider,\n ToastTitle,\n ToastType,\n ToastViewport,\n toast,\n useToasts,\n};\n"],"mappings":";;;;;AAOA,IAAM,KAAM,GAAG,MAAiC,EAAK,EAAO,ECO/C,IAAY;CAEvB,SAAS;CAET,SAAS;CAET,MAAM;CAEN,SAAS;CAET,OAAO;CAEP,SAAS;CACV,ECQK,KAAoC,EAAC,eAAY,GAAG,QAAuC;CAC/F,IAAM,IAAY,EAAC,GAAG,GAAQ;CAO9B,OALA,OAAO,EAAU,SACb,MAAe,OACjB,EAAU,UAAU,GACpB,EAAU,WAAW,EAAQ,YAAY,SAEpC;GAiBH,UAAyC;CAC7C,IAAM,IAAU,EAAe,oBAAoB,EAiB7C,oBAAW,IAAI,KAAsB,EACvC,IAAQ,GAOR,IAAY,GACV,IAA6B,EAAE,EAC/B,KAAQ,MAA2B;EACvC,AAAI,IAAY,IACd,GAAM,GAEN,EAAQ,KAAK,EAAK;IAGhB,KAAyC,MAAa;EAC1D,IAAM,IAAc,EAAQ,cAAc,EAAS;EACnD,KAAa;EACb,KAAK,IAAM,KAAQ,EAAQ,OAAO,EAAE,EAClC,GAAM;EAER,aAAa;GAEX,AADA,GAAa,EACb;GAOA,IAAM,IAAO,IAAI,IAAI,EAAS;GAC9B,qBAAqB;IACf,UAAY,IAGhB,KAAK,IAAM,CAAC,GAAI,MAAY,GA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AC,GAAD;CAAO,OAAO;CAAM,GAAI;WACtB,kBAAC,GAAD,EAAA,UAAA;EACE,kBAAC,GAAD,EAAW,MAAM,EAAK,MAAQ,CAAA;EAC9B,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,GAAD,EAAc,CAAA,EACd,kBAAC,GAAD,EAAoB,CAAA,CAChB;OACN,kBAAC,GAAD,EAAe,CAAA,CACX;;EACN,kBAAC,GAAD,EAAc,CAAA;EACD,EAAA,CAAA;CACT,CAAA,EAIJ,UAAkB;CACtB,IAAM,EAAC,cAAU,EAAe,iBAAiB;CAEjD,OAAO,EAAO,KAAK,MAAS,kBAAC,GAAD,EAAyB,OAAO,GAAQ,EAAxB,EAAK,GAAmB,CAAC;GASjE,IAAY,GAEZ,KAAW,EAAC,aAAU,kBAAe,GAAO,WAAQ,GAAG,GAAG,QAC9D,kBAAC,GAAD;CAA6B;CAAc,OAAO,KAAK,IAAI,KAAK,IAAI,GAAO,EAAE,EAAE,EAAU;CAAE,GAAI;WAA/F,CACG,GACD,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAa,CAAA,EACC,CAAA,EACJ,CAAA,CACA;IAUZ,UAAkB,EAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/cn.ts","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the toast\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {\n ToastManagerAddOptions,\n Toast as ToastPrimitive,\n ToastManager as ToastPrimitiveManager,\n} from '@base-ui-components/react/toast';\nimport type {ReactNode} from 'react';\n\n/**\n * What the toast is about: the icon in front of the title and its colour. These\n * are the types shadcn's renderer recognises. The danger one is `error` rather\n * than the `danger` of Alert and the tokens, because `toast.promise` writes\n * `loading`, `success` and `error` itself, and a toast it settles has to look\n * like one added by hand.\n */\nexport const ToastType = {\n /** No status, no icon: the plain message. */\n Default: 'default',\n /** A scenario that worked: the --color-success icon. */\n Success: 'success',\n /** Something to know: the --color-action icon. */\n Info: 'info',\n /** Nothing is broken yet: the --color-warning icon. */\n Warning: 'warning',\n /** Something failed: the --color-danger icon. */\n Error: 'error',\n /** A task still running: a turning ring. It stays until it is updated or closed. */\n Loading: 'loading',\n} as const;\nexport type ToastType = (typeof ToastType)[keyof typeof ToastType];\n\n/**\n * The corner the stack stands in, the top right by default. On a phone the\n * stack takes the full width at the top or the bottom.\n */\nexport const ToastPosition = {\n TopLeft: 'top-left',\n TopCenter: 'top-center',\n TopRight: 'top-right',\n BottomLeft: 'bottom-left',\n BottomCenter: 'bottom-center',\n BottomRight: 'bottom-right',\n} as const;\nexport type ToastPosition = (typeof ToastPosition)[keyof typeof ToastPosition];\n\n/**\n * What `toast.add` takes: Base UI's options without `timeout`. A toast either\n * goes away by itself after five seconds, or stays until the user closes it or\n * acts on it — `persistent`. No call site picks its own number of seconds.\n * `data` is anything of your own the toast carries.\n */\nexport type ToastOptions<Data extends object = {}> = Omit<ToastManagerAddOptions<Data>, 'timeout'> & {\n /**\n * Stays until the user closes it or presses its action: a new build to\n * reload for, a session that expired, cookie consent. It is announced at\n * once, as `priority: 'high'`, unless `priority` says otherwise.\n */\n persistent?: boolean;\n};\n\n/** What `toast.update` takes: any of the options, the rest stay as they were. */\nexport type ToastUpdateOptions<Data extends object = {}> = Partial<ToastOptions<Data>>;\n\n/** What the shortcuts take after the text: everything but the type and the title. */\nexport type ToastShortcutOptions<Data extends object = {}> = Omit<ToastOptions<Data>, 'type' | 'title'>;\n\n/** One stage of `toast.promise`: a title, the options, or a function of the result or the error. */\ntype ToastPromiseStage<Input, Data extends object> =\n | string\n | ToastUpdateOptions<Data>\n | ((input: Input) => string | ToastUpdateOptions<Data>);\n\nexport type ToastPromiseOptions<Value, Data extends object = {}> = {\n loading: string | ToastUpdateOptions<Data>;\n success: ToastPromiseStage<Value, Data>;\n /**\n * Left out, a failure closes the loading toast and says nothing: for a\n * request whose errors the app's own handler already shows, so that one\n * failure is one toast.\n */\n error?: ToastPromiseStage<any, Data>;\n};\n\n/** A shortcut for one type: the text is the title. Returns the toast's id. */\ntype Shortcut = <Data extends object>(title: ReactNode, options?: ToastShortcutOptions<Data>) => string;\n\n/**\n * Base UI's manager with what the cabinets lean on.\n *\n * - `add` with the `id` of a toast still on screen updates that toast instead\n * of stacking a second one, as react-toastify's `toastId` did.\n * - `update` of a loading toast to any other type starts its five seconds,\n * as `toast.promise` does when the promise settles.\n * - `isActive` says whether a toast is still on screen.\n * - One shortcut per type: `toast.error('Could not save')`.\n */\nexport type ToastManager = Omit<ToastPrimitiveManager, 'add' | 'update' | 'promise'> & {\n add: <Data extends object>(options: ToastOptions<Data>) => string;\n update: <Data extends object>(id: string, updates: ToastUpdateOptions<Data>) => void;\n promise: <Value, Data extends object>(\n promise: Promise<Value>,\n options: ToastPromiseOptions<Value, Data>,\n ) => Promise<Value>;\n isActive: (id: string) => boolean;\n success: Shortcut;\n info: Shortcut;\n warning: Shortcut;\n error: Shortcut;\n loading: Shortcut;\n};\n\n/**\n * A part's own props, with `className` as a string. Base UI also takes a\n * function of the part's state there; the parts here join the string with\n * their own class names, and a function cannot be joined.\n */\ntype WithClassName<Props> = Omit<Props, 'className'> & {className?: string};\n\n/** How many toasts stand in the stack at once: up to five, so a fanned-out stack fits a laptop's screen. */\nexport type ToastLimit = 1 | 2 | 3 | 4 | 5;\n\n/** Base UI's provider props without `timeout`: every toast that goes away by itself takes five seconds. */\nexport type ToasterProps = Omit<ToastPrimitive.Provider.Props, 'timeout' | 'limit'> & {\n /**\n * How many toasts stand at once. One over the limit is not dropped: it waits\n * unseen and comes forward when one in front closes. The stack does not\n * scroll, so it stops at five. @default 3\n */\n limit?: ToastLimit;\n /**\n * The corner the stack stands in. Its distance from the edges is the\n * `--toast-offset-top`, `-right`, `-bottom` and `-left` custom properties,\n * 16px each by default. @default 'top-right'\n */\n position?: ToastPosition;\n};\nexport type ToastViewportProps = WithClassName<ToastPrimitive.Viewport.Props> & {\n /** The corner the stack stands in. @default 'top-right' */\n position?: ToastPosition;\n};\nexport type ToastProps = WithClassName<ToastPrimitive.Root.Props>;\nexport type ToastContentProps = WithClassName<ToastPrimitive.Content.Props>;\nexport type ToastTitleProps = WithClassName<ToastPrimitive.Title.Props>;\nexport type ToastDescriptionProps = WithClassName<ToastPrimitive.Description.Props>;\nexport type ToastActionProps = WithClassName<ToastPrimitive.Action.Props>;\nexport type ToastCloseProps = WithClassName<ToastPrimitive.Close.Props>;\nexport type ToastIconProps = {type: string | undefined};\n","import {type ToastManagerAddOptions, Toast as ToastPrimitive} from '@base-ui-components/react/toast';\nimport {buttonVariants} from '@propellerads/button';\nimport {createContext, type ReactNode, useContext} from 'react';\nimport './toast.css';\nimport {cn} from './cn';\nimport {\n type ToastActionProps,\n type ToastCloseProps,\n type ToastContentProps,\n type ToastDescriptionProps,\n type ToasterProps,\n type ToastIconProps,\n type ToastManager,\n type ToastOptions,\n ToastPosition,\n type ToastPromiseOptions,\n type ToastProps,\n type ToastShortcutOptions,\n type ToastTitleProps,\n ToastType,\n type ToastUpdateOptions,\n type ToastViewportProps,\n} from './types';\n\n/*\n * shadcn's Toast on Base UI, part for part: the same manager, the same stack\n * that fans out under the pointer, the same swipe to dismiss. The utility\n * classes are a stylesheet on @propellerads/tokens instead, the action and\n * the close button wear @propellerads/button, and the status icons are the\n * product's own from @propellerads/icon.\n */\n\n/* Base UI's own options, as the provider takes them. */\ntype PrimitiveOptions = ToastManagerAddOptions<object>;\n\n/** `persistent` in Base UI's words: no timeout, and announced at once. */\nconst toPrimitive = <Data extends object>({persistent, ...options}: ToastUpdateOptions<Data>) => {\n const primitive = {...options} as ToastUpdateOptions<Data> & {timeout?: number};\n // A call written against Base UI's own API keeps no number of seconds either.\n delete primitive.timeout;\n if (persistent === true) {\n primitive.timeout = 0;\n primitive.priority = options.priority ?? 'high';\n }\n return primitive as PrimitiveOptions;\n};\n\n/** A loading toast's promise, settled by the `update` that ends the loading. */\ntype Pending = {resolve: (options: PrimitiveOptions) => void; reject: (options: PrimitiveOptions) => void};\n\n/**\n * Base UI's manager, with what the cabinets did through react-toastify. A\n * toast stops being active as it starts to close, so an `add` with its id\n * while it slides out is a new toast rather than an update of a leaving one.\n *\n * A loading toast is Base UI's `promise` with a promise this manager holds:\n * Base UI starts a toast's seconds only when it is added or when its promise\n * settles, never on an update. The `update` that turns it into anything else\n * settles that promise, so the result goes away by itself as one from\n * `toast.promise` does.\n */\nconst createToastManager = (): ToastManager => {\n const manager = ToastPrimitive.createToastManager();\n\n /* One showing of a toast. The id the caller knows can be shown again while\n the last showing still slides out, and Base UI tells toasts apart by id\n alone — removing the one that left would take the new one with it. So\n each showing has an id of its own for Base UI, and keeps its own\n callbacks: an update merges into the toast, and one that names no\n callback must not take away those it was added with. */\n type Showing = {\n internal: string;\n active: boolean;\n pending?: Pending;\n onClose?: () => void;\n onRemove?: () => void;\n };\n\n /** The latest showing of each id the caller knows. */\n const showings = new Map<string, Showing>();\n let count = 0;\n\n /* Base UI hands an event only to a provider already listening, and the\n Toaster listens from its first effect on. A toast called before that — an\n interceptor on the app's first request — would be lost, and its id would\n stay active with nothing on screen. So until a provider listens, the calls\n wait here and play when it does. */\n let listeners = 0;\n const waiting: Array<() => void> = [];\n const send = (call: () => void): void => {\n if (listeners > 0) {\n call();\n } else {\n waiting.push(call);\n }\n };\n const subscribe: ToastManager[' subscribe'] = (listener) => {\n const unsubscribe = manager[' subscribe'](listener);\n listeners += 1;\n for (const call of waiting.splice(0)) {\n call();\n }\n return () => {\n unsubscribe();\n listeners -= 1;\n // The last Toaster gone takes its toasts with it: they will neither close\n // nor be removed, so their ids are forgotten and the next add shows anew.\n // Checked a step later — React in development unsubscribes and subscribes\n // straight back, and the toasts of that one Toaster stay on screen. Only\n // the showings it had are forgotten: one added in between is waiting for\n // the next Toaster and keeps its id.\n const gone = new Map(showings);\n queueMicrotask(() => {\n if (listeners > 0) {\n return;\n }\n for (const [id, showing] of gone) {\n if (showings.get(id) === showing) {\n showings.delete(id);\n }\n }\n });\n };\n };\n\n /**\n * The showing an id names: the id the caller knows, or the one Base UI has —\n * which `useToasts` hands out, so a toast drawn by hand can be closed by it.\n */\n const find = (id: string): Showing | undefined =>\n showings.get(id) ?? [...showings.values()].find((showing) => showing.internal === id);\n\n /** Keeps the callbacks an add or an update names, and those it leaves out. */\n const remember = (showing: Showing, {onClose, onRemove}: ToastUpdateOptions): void => {\n showing.onClose = onClose ?? showing.onClose;\n showing.onRemove = onRemove ?? showing.onRemove;\n };\n\n /** The options in Base UI's words, without the caller's callbacks: those live on the showing. */\n const bare = <Data extends object>({onClose, onRemove, id, ...options}: ToastUpdateOptions<Data>): PrimitiveOptions =>\n toPrimitive(options);\n\n /* The showing's own callbacks, set once as it is added: they mark it gone\n and call whatever the caller has kept on it by then. The id the caller\n knows forgets the showing only if no newer one has taken it. */\n const tracked = <Data extends object>(id: string, showing: Showing, options: ToastUpdateOptions<Data>) => ({\n ...bare(options),\n id: showing.internal,\n onClose: () => {\n showing.active = false;\n showing.pending = undefined;\n showing.onClose?.();\n },\n onRemove: () => {\n if (showings.get(id) === showing) {\n showings.delete(id);\n }\n showing.onRemove?.();\n },\n });\n\n const update = <Data extends object>(id: string, updates: ToastUpdateOptions<Data>): void => {\n const showing = find(id);\n if (!showing) {\n return;\n }\n remember(showing, updates);\n const loading = showing.pending;\n if (!loading || updates.type === undefined || updates.type === ToastType.Loading) {\n send(() => manager.update(showing.internal, bare(updates)));\n return;\n }\n\n showing.pending = undefined;\n // Base UI writes `success` on a resolve and `error` on a reject; any other\n // type is written back right after it.\n const {type} = updates;\n if (type === ToastType.Error) {\n loading.reject(bare(updates));\n } else {\n loading.resolve(bare(updates));\n }\n if (type !== ToastType.Success && type !== ToastType.Error) {\n send(() =>\n queueMicrotask(() => manager.update(showing.internal, {type: type === ToastType.Default ? undefined : type})),\n );\n }\n };\n\n const add = <Data extends object>(options: ToastOptions<Data>): string => {\n if (options.id !== undefined && showings.get(options.id)?.active) {\n update(options.id, options);\n return options.id;\n }\n\n count += 1;\n // A tilde no caller writes keeps these apart from the ids the caller picks.\n const id = options.id ?? `~toast-${count}`;\n // An id still sliding out under its last showing takes a fresh one for Base UI.\n const internal = showings.has(id) ? `${id}~${count}` : id;\n const showing: Showing = {internal, active: true};\n remember(showing, options);\n showings.set(id, showing);\n\n if (options.type !== ToastType.Loading) {\n send(() => manager.add(tracked(id, showing, options)));\n return id;\n }\n\n const settled = new Promise<PrimitiveOptions>((resolve, reject) => {\n showing.pending = {resolve, reject};\n });\n send(() => {\n manager\n .promise(settled, {\n loading: tracked(id, showing, options),\n success: (result: PrimitiveOptions) => result,\n error: (result: PrimitiveOptions) => result,\n })\n // The rejection is how a loading toast turns into an error; nobody awaits it.\n .catch(() => undefined);\n });\n return id;\n };\n\n const close = (id: string): void => {\n const showing = find(id);\n if (!showing) {\n return;\n }\n showing.pending = undefined;\n send(() => manager.close(showing.internal));\n };\n\n /* A stage of `toast.promise` as options: text alone is the title, as in the shortcuts. */\n const stage = <Input, Data extends object>(\n value: string | ToastUpdateOptions<Data> | ((input: Input) => string | ToastUpdateOptions<Data>),\n input?: Input,\n ): ToastUpdateOptions<Data> => {\n const resolved = typeof value === 'function' ? value(input as Input) : value;\n return typeof resolved === 'string' ? {title: resolved} : resolved;\n };\n\n /**\n * A loading toast that the promise ends. It is this manager's loading and\n * update rather than Base UI's own `promise`, which writes `success` over\n * whatever the stage says: here a stage may end in a warning — partly done —\n * or in any other type it names.\n */\n const promise = <Value, Data extends object>(\n work: Promise<Value>,\n options: ToastPromiseOptions<Value, Data>,\n ): Promise<Value> => {\n const id = add({...stage(options.loading), type: ToastType.Loading});\n return work.then(\n (result) => {\n update(id, {type: ToastType.Success, ...stage(options.success, result)});\n return result;\n },\n (error: unknown) => {\n if (options.error === undefined) {\n close(id);\n } else {\n update(id, {type: ToastType.Error, ...stage(options.error, error)});\n }\n throw error;\n },\n );\n };\n\n const shortcut =\n (type: ToastType) =>\n <Data extends object>(title: ReactNode, options?: ToastShortcutOptions<Data>) =>\n add({...options, type, title});\n\n return {\n ...manager,\n ' subscribe': subscribe,\n add,\n update,\n close,\n promise,\n isActive: (id) => find(id)?.active === true,\n success: shortcut(ToastType.Success),\n info: shortcut(ToastType.Info),\n warning: shortcut(ToastType.Warning),\n error: shortcut(ToastType.Error),\n loading: shortcut(ToastType.Loading),\n };\n};\n\n/**\n * The manager the app calls from anywhere, components or not — an axios\n * interceptor, a saga, a jQuery widget: `toast.error('Could not save')`,\n * `toast.add({type: 'success', title: 'Saved'})`. `<Toaster />` renders what\n * it holds.\n */\nconst toast = createToastManager();\n\nconst ToastProvider = (props: ToastPrimitive.Provider.Props) => <ToastPrimitive.Provider {...props} />;\n\nconst ToastPortal = (props: ToastPrimitive.Portal.Props) => (\n <ToastPrimitive.Portal data-slot=\"toast-portal\" {...props} />\n);\n\nconst POSITIONS: readonly string[] = Object.values(ToastPosition);\n\n/** A value from plain JS that names no corner falls back to the top right. */\nconst splitPosition = (position: ToastPosition) => {\n const known = POSITIONS.includes(position) ? position : ToastPosition.TopRight;\n const [y, x] = known.split('-') as ['top' | 'bottom', 'left' | 'center' | 'right'];\n return {x, y};\n};\n\nconst swipeDirectionOf = (position: ToastPosition): ToastProps['swipeDirection'] => {\n const {x, y} = splitPosition(position);\n const vertical = y === 'top' ? 'up' : 'down';\n return x === 'center' ? [vertical] : [vertical, x];\n};\n\n/* Lets a Toast composed by hand swipe towards the corner of its viewport. */\nconst ToastPositionContext = createContext<ToastPosition>(ToastPosition.TopRight);\n\n/** The corner the toasts stack in; the full width at its edge on a phone. */\nconst ToastViewport = ({className, position = ToastPosition.TopRight, ...props}: ToastViewportProps) => {\n const {x, y} = splitPosition(position);\n\n return (\n <ToastPositionContext.Provider value={position}>\n <ToastPrimitive.Viewport\n data-slot=\"toast-viewport\"\n data-x-position={x}\n data-y-position={y}\n className={cn('toast-viewport', className)}\n {...props}\n />\n </ToastPositionContext.Provider>\n );\n};\n\n/** One toast in the stack. The stylesheet moves it by the custom properties Base UI writes on it. */\nconst Toast = ({className, swipeDirection, ...props}: ToastProps) => {\n const position = useContext(ToastPositionContext);\n\n return (\n <ToastPrimitive.Root\n data-slot=\"toast\"\n className={cn('toast', className)}\n swipeDirection={swipeDirection ?? swipeDirectionOf(position)}\n {...props}\n />\n );\n};\n\n/** The row inside: the icon, the text, the action and the close button. It fades out behind the front toast. */\nconst ToastContent = ({className, ...props}: ToastContentProps) => (\n <ToastPrimitive.Content data-slot=\"toast-content\" className={cn('toast__content', className)} {...props} />\n);\n\nconst ToastTitle = ({className, ...props}: ToastTitleProps) => (\n <ToastPrimitive.Title data-slot=\"toast-title\" className={cn('toast__title', className)} {...props} />\n);\n\nconst ToastDescription = ({className, ...props}: ToastDescriptionProps) => (\n <ToastPrimitive.Description\n data-slot=\"toast-description\"\n className={cn('toast__description', className)}\n {...props}\n />\n);\n\n/** The one button a toast may carry — undo, retry, open. It takes its label and handler from `actionProps`. */\nconst ToastAction = ({className, ...props}: ToastActionProps) => (\n <ToastPrimitive.Action\n data-slot=\"toast-action\"\n className={cn(buttonVariants({variant: 'secondary'}), 'toast__action', className)}\n {...props}\n />\n);\n\n/* The icons are the paths of @propellerads/icon. That package draws through\n styled-components; a toast has no other use for it, so it carries the\n paths themselves. */\nconst Svg = ({children}: {children: ReactNode}) => (\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\" focusable=\"false\">\n {children}\n </svg>\n);\n\n/* Close */\nconst CloseIcon = () => (\n <Svg>\n <path d=\"M18.3 5.71c-.39-.39-1.02-.39-1.41 0L12 10.59 7.11 5.7c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41L10.59 12 5.7 16.89c-.39.39-.39 1.02 0 1.41.39.39 1.02.39 1.41 0L12 13.41l4.89 4.89c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41L13.41 12l4.89-4.89c.38-.38.38-1.02 0-1.4z\" />\n </Svg>\n);\n\n/* CheckCircle, InfoOutline, WarningOutline and Error, as Alert's stories pair them with the statuses. */\nconst STATUS_ICONS: Partial<Record<string, ReactNode>> = {\n [ToastType.Success]: (\n <Svg>\n <path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\" />\n </Svg>\n ),\n [ToastType.Info]: (\n <Svg>\n <path d=\"M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z\" />\n </Svg>\n ),\n [ToastType.Warning]: (\n <Svg>\n <path d=\"M12 5.98999L19.53 19H4.47L12 5.98999ZM2.74 18C1.97 19.33 2.93 21 4.47 21H19.53C21.07 21 22.03 19.33 21.26 18L13.73 4.98999C12.96 3.65999 11.04 3.65999 10.27 4.98999L2.74 18ZM11 11V13C11 13.55 11.45 14 12 14C12.55 14 13 13.55 13 13V11C13 10.45 12.55 9.99999 12 9.99999C11.45 9.99999 11 10.45 11 11ZM11 16H13V18H11V16Z\" />\n </Svg>\n ),\n [ToastType.Error]: (\n <Svg>\n <path d=\"M12 7c.55 0 1 .45 1 1v4c0 .55-.45 1-1 1s-1-.45-1-1V8c0-.55.45-1 1-1zm-.01-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm1-3h-2v-2h2v2z\" />\n </Svg>\n ),\n // The ring is drawn by the stylesheet, the way the Spinner draws its own.\n [ToastType.Loading]: <span className=\"toast__ring\" />,\n};\n\n/** The close button at the end of the row, a ghost square with a hit area wider than itself. */\nconst ToastClose = ({className, children, ...props}: ToastCloseProps) => (\n <ToastPrimitive.Close\n data-slot=\"toast-close\"\n aria-label=\"Close\"\n className={cn(buttonVariants({variant: 'ghost', iconOnly: true, quiet: true}), 'toast__close', className)}\n {...props}\n >\n {children ?? <CloseIcon />}\n </ToastPrimitive.Close>\n);\n\n/** The status icon, in the status colour. A toast of no known type has none. The title says what it shows. */\nconst ToastIcon = ({type}: ToastIconProps) => {\n const icon = type === undefined ? undefined : STATUS_ICONS[type];\n\n return icon ? (\n <span data-slot=\"toast-icon\" className=\"toast__icon\" aria-hidden>\n {icon}\n </span>\n ) : null;\n};\n\n/**\n * One toast as the Toaster draws it: the icon, the title and the description,\n * the action, and the cross. A page that shows a toast outside the\n * corner — a reference, a preview — draws it with this too.\n */\nconst ToastItem = ({toast: item, ...props}: ToastProps) => (\n <Toast toast={item} {...props}>\n <ToastContent>\n <ToastIcon type={item.type} />\n <div className=\"toast__body\">\n <div className=\"toast__text\">\n <ToastTitle />\n <ToastDescription />\n </div>\n <ToastAction />\n </div>\n <ToastClose />\n </ToastContent>\n </Toast>\n);\n\n/** Every toast the manager holds, drawn the one way. */\nconst ToastList = () => {\n const {toasts} = ToastPrimitive.useToastManager();\n\n return toasts.map((item) => <ToastItem key={item.id} toast={item} />);\n};\n\n/**\n * Put once at the root of the app, around it or beside it. It renders the\n * toasts of `toast`, or of the manager passed in — a second Toaster with a\n * manager of its own is a second stack.\n */\n/** The most toasts a stack holds, whatever a call from plain JS asks for. */\nconst MAX_LIMIT = 5;\n\nconst Toaster = ({\n children,\n toastManager = toast,\n limit = 3,\n position = ToastPosition.TopRight,\n ...props\n}: ToasterProps) => (\n <ToastProvider toastManager={toastManager} limit={Math.min(Math.max(limit, 1), MAX_LIMIT)} {...props}>\n {children}\n <ToastPortal>\n <ToastViewport position={position}>\n <ToastList />\n </ToastViewport>\n </ToastPortal>\n </ToastProvider>\n);\n\n/**\n * The toasts of the nearest Toaster or ToastProvider, to draw them — as\n * ToastItem does in a reference page. It reads and does not add: Base UI's own\n * hook would add past this package's manager, without `persistent`, the id\n * check or `isActive`. Toasts are added with `toast` or a manager from\n * `createToastManager`.\n */\nconst useToasts = () => ToastPrimitive.useToastManager().toasts;\n\nexport default Toaster;\n\nexport type {\n ToastActionProps,\n ToastCloseProps,\n ToastContentProps,\n ToastDescriptionProps,\n ToasterProps,\n ToastIconProps,\n ToastLimit,\n ToastManager,\n ToastOptions,\n ToastProps,\n ToastShortcutOptions,\n ToastTitleProps,\n ToastViewportProps,\n} from './types';\nexport {\n createToastManager,\n Toast,\n ToastAction,\n ToastClose,\n ToastContent,\n ToastDescription,\n Toaster,\n ToastIcon,\n ToastItem,\n ToastPortal,\n ToastPosition,\n ToastProvider,\n ToastTitle,\n ToastType,\n ToastViewport,\n toast,\n useToasts,\n};\n"],"mappings":";;;;;;AAOA,IAAM,KAAM,GAAG,MAAiC,EAAK,EAAO,ECO/C,IAAY;CAEvB,SAAS;CAET,SAAS;CAET,MAAM;CAEN,SAAS;CAET,OAAO;CAEP,SAAS;CACV,EAOY,IAAgB;CAC3B,SAAS;CACT,WAAW;CACX,UAAU;CACV,YAAY;CACZ,cAAc;CACd,aAAa;CACd,ECLK,KAAoC,EAAC,eAAY,GAAG,QAAuC;CAC/F,IAAM,IAAY,EAAC,GAAG,GAAQ;CAO9B,OALA,OAAO,EAAU,SACb,MAAe,OACjB,EAAU,UAAU,GACpB,EAAU,WAAW,EAAQ,YAAY,SAEpC;GAiBH,UAAyC;CAC7C,IAAM,IAAU,EAAe,oBAAoB,EAiB7C,oBAAW,IAAI,KAAsB,EACvC,IAAQ,GAOR,IAAY,GACV,IAA6B,EAAE,EAC/B,KAAQ,MAA2B;EACvC,AAAI,IAAY,IACd,GAAM,GAEN,EAAQ,KAAK,EAAK;IAGhB,KAAyC,MAAa;EAC1D,IAAM,IAAc,EAAQ,cAAc,EAAS;EACnD,KAAa;EACb,KAAK,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,GAAQ,EAAxB,EAAK,GAAmB,CAAC;GASjE,IAAY,GAEZ,KAAW,EACf,aACA,kBAAe,GACf,WAAQ,GACR,cAAW,EAAc,UACzB,GAAG,QAEH,kBAAC,GAAD;CAA6B;CAAc,OAAO,KAAK,IAAI,KAAK,IAAI,GAAO,EAAE,EAAE,EAAU;CAAE,GAAI;WAA/F,CACG,GACD,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAAyB;YACvB,kBAAC,GAAD,EAAa,CAAA;EACC,CAAA,EACJ,CAAA,CACA;IAUZ,UAAkB,EAAe,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@propellerads/toast",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/index.css",