@panneau/ui 5.0.0-alpha.17 → 5.0.0-alpha.19

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.
Files changed (68) hide show
  1. package/README.md +31 -1
  2. package/dist/button/Button.d.ts +5 -2
  3. package/dist/button/Button.d.ts.map +1 -1
  4. package/dist/button/Button.js +76 -54
  5. package/dist/button/Button.js.map +1 -1
  6. package/dist/index.d.ts +3 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +6 -4
  9. package/dist/line-chart/LineChart.css +84 -0
  10. package/dist/line-chart/LineChart.d.ts +26 -0
  11. package/dist/line-chart/LineChart.d.ts.map +1 -0
  12. package/dist/line-chart/LineChart.js +327 -0
  13. package/dist/line-chart/LineChart.js.map +1 -0
  14. package/dist/line-chart/LineChart.module.js +28 -0
  15. package/dist/line-chart/LineChart.module.js.map +1 -0
  16. package/dist/line-chart/tokens.d.ts +3 -0
  17. package/dist/line-chart/tokens.d.ts.map +1 -0
  18. package/dist/line-chart/tokens.js +19 -0
  19. package/dist/line-chart/tokens.js.map +1 -0
  20. package/dist/root/PanneauRoot.css +24 -0
  21. package/dist/root/PanneauRoot.d.ts +8 -1
  22. package/dist/root/PanneauRoot.d.ts.map +1 -1
  23. package/dist/root/PanneauRoot.js +98 -92
  24. package/dist/root/PanneauRoot.js.map +1 -1
  25. package/dist/root/PanneauRoot.module.js.map +1 -1
  26. package/dist/stat/Stat.css +45 -0
  27. package/dist/stat/Stat.d.ts +27 -0
  28. package/dist/stat/Stat.d.ts.map +1 -0
  29. package/dist/stat/Stat.js +87 -0
  30. package/dist/stat/Stat.js.map +1 -0
  31. package/dist/stat/Stat.module.js +18 -0
  32. package/dist/stat/Stat.module.js.map +1 -0
  33. package/dist/stat/tokens.d.ts +3 -0
  34. package/dist/stat/tokens.d.ts.map +1 -0
  35. package/dist/stat/tokens.js +21 -0
  36. package/dist/stat/tokens.js.map +1 -0
  37. package/dist/theme/Tone.css +14 -0
  38. package/dist/theme/Tone.module.js +4 -2
  39. package/dist/theme/Tone.module.js.map +1 -1
  40. package/dist/theme/bootstrap.d.ts.map +1 -1
  41. package/dist/theme/bootstrap.js +6 -0
  42. package/dist/theme/bootstrap.js.map +1 -1
  43. package/dist/theme/checkTheme.d.ts.map +1 -1
  44. package/dist/theme/checkTheme.js +24 -0
  45. package/dist/theme/checkTheme.js.map +1 -1
  46. package/dist/theme/components.d.ts +2 -0
  47. package/dist/theme/components.d.ts.map +1 -1
  48. package/dist/theme/components.js +4 -0
  49. package/dist/theme/components.js.map +1 -1
  50. package/dist/theme/index.js +1 -1
  51. package/dist/theme/semanticTokens.d.ts +1 -1
  52. package/dist/theme/semanticTokens.d.ts.map +1 -1
  53. package/dist/theme/semanticTokens.js +6 -0
  54. package/dist/theme/semanticTokens.js.map +1 -1
  55. package/dist/theme/tones.d.ts +14 -2
  56. package/dist/theme/tones.d.ts.map +1 -1
  57. package/dist/theme/tones.js +14 -2
  58. package/dist/theme/tones.js.map +1 -1
  59. package/dist/toast/Toast.css +131 -15
  60. package/dist/toast/Toast.d.ts +46 -9
  61. package/dist/toast/Toast.d.ts.map +1 -1
  62. package/dist/toast/Toast.js +190 -65
  63. package/dist/toast/Toast.js.map +1 -1
  64. package/dist/toast/Toast.module.js +5 -3
  65. package/dist/toast/Toast.module.js.map +1 -1
  66. package/dist/toast/tokens.js +1 -1
  67. package/dist/toast/tokens.js.map +1 -1
  68. package/package.json +3 -3
@@ -1,32 +1,59 @@
1
- /* The region carries the root's class (tokens), since React Aria renders it in the body. */
1
+ /*
2
+ * The region carries the root's class (tokens), since React Aria renders it in the body. Toasts show
3
+ * at the bottom, centered, above what sticks to the bottom of the page (--panneau-bottom-offset,
4
+ * set by useToastOffset()), or at the bottom or top of the end side (data-placement). React Aria
5
+ * renders them newest first, each in a list item with `display: contents`.
6
+ */
2
7
  .panneau-toast-region.panneau-toast-region {
3
8
  position: fixed;
4
- inset-block-start: var(--panneau-space-4);
5
- inset-inline-end: var(--panneau-space-4);
9
+ inset-block-end: calc(var(--panneau-bottom-offset, 0px) + var(--panneau-space-4));
10
+ inset-inline: 0;
6
11
  z-index: var(--panneau-z-toast);
7
- display: flex;
8
- flex-direction: column;
9
- gap: var(--panneau-space-2);
12
+ display: grid;
13
+ grid-template-columns: minmax(0, 1fr);
14
+ align-items: end;
10
15
  width: min(var(--panneau-toast-width, 24rem), calc(100vw - 2 * var(--panneau-space-4)));
16
+ margin-inline: auto;
11
17
  background: transparent;
12
18
  outline: none;
13
19
  }
14
20
 
21
+ .panneau-toast-region[data-placement='bottom-end'] {
22
+ inset-inline: auto var(--panneau-space-4);
23
+ margin-inline: 0;
24
+ }
25
+
26
+ .panneau-toast-region[data-placement='top-end'] {
27
+ inset-block: var(--panneau-space-4) auto;
28
+ inset-inline: auto var(--panneau-space-4);
29
+ align-items: start;
30
+ margin-inline: 0;
31
+ }
32
+
15
33
  .panneau-toast-region[data-focus-visible] {
16
34
  outline: var(--panneau-focus-width) solid var(--panneau-color-focus);
17
35
  outline-offset: 4px;
18
36
  }
19
37
 
38
+ /* On a phone, the whole width at the bottom (or the top). */
20
39
  @media (max-width: 30rem) {
21
- .panneau-toast-region.panneau-toast-region {
40
+ .panneau-toast-region.panneau-toast-region,
41
+ .panneau-toast-region.panneau-toast-region[data-placement] {
22
42
  inset-inline: var(--panneau-space-2);
23
- inset-block-start: var(--panneau-space-2);
24
43
  width: auto;
44
+ margin-inline: 0;
45
+ }
46
+
47
+ .panneau-toast-region.panneau-toast-region:not([data-placement='top-end']) {
48
+ inset-block: auto calc(var(--panneau-bottom-offset, 0px) + var(--panneau-space-2));
25
49
  }
26
50
  }
27
51
 
28
52
  .panneau-toast {
53
+ --toast-rise: 1rem;
54
+
29
55
  display: flex;
56
+ grid-area: 1 / 1;
30
57
  align-items: flex-start;
31
58
  gap: var(--panneau-space-3);
32
59
  padding: var(--panneau-space-3) var(--panneau-space-3) var(--panneau-space-3)
@@ -35,10 +62,100 @@
35
62
  background-color: var(--panneau-toast-bg, var(--panneau-color-surface-raised));
36
63
  border: var(--panneau-border-width) solid
37
64
  var(--panneau-toast-border-color, var(--panneau-color-border));
38
- border-inline-start-width: var(--panneau-toast-tone-width, 4px);
39
65
  border-radius: var(--panneau-toast-radius, var(--panneau-radius-lg));
40
66
  box-shadow: var(--panneau-toast-shadow, var(--panneau-shadow-lg));
41
67
  outline: none;
68
+ transition:
69
+ transform var(--panneau-duration) ease-out,
70
+ opacity var(--panneau-duration) ease-out;
71
+ animation: panneau-toast-rise calc(2 * var(--panneau-duration)) ease-out;
72
+ }
73
+
74
+ .panneau-toast-region[data-placement='top-end'] .panneau-toast {
75
+ --toast-rise: -1rem;
76
+ }
77
+
78
+ @keyframes panneau-toast-rise {
79
+ from {
80
+ opacity: 0;
81
+ transform: translateY(var(--toast-rise));
82
+ }
83
+ }
84
+
85
+ /*
86
+ * Folded: the newest in front, the older ones behind it, peeking out a little. Hovered or focused,
87
+ * the region unfolds them in a column, the newest closest to the edge of the screen.
88
+ */
89
+ .panneau-toast-region li:nth-child(1) > .panneau-toast {
90
+ z-index: 3;
91
+ }
92
+
93
+ .panneau-toast-region li:nth-child(2) > .panneau-toast {
94
+ z-index: 2;
95
+ transform: translateY(calc(-1 * var(--panneau-space-2))) scale(0.95);
96
+ }
97
+
98
+ .panneau-toast-region li:nth-child(3) > .panneau-toast {
99
+ z-index: 1;
100
+ transform: translateY(calc(-2 * var(--panneau-space-2))) scale(0.9);
101
+ }
102
+
103
+ .panneau-toast-region[data-placement='top-end'] li:nth-child(2) > .panneau-toast {
104
+ transform: translateY(var(--panneau-space-2)) scale(0.95);
105
+ }
106
+
107
+ .panneau-toast-region[data-placement='top-end'] li:nth-child(3) > .panneau-toast {
108
+ transform: translateY(calc(2 * var(--panneau-space-2))) scale(0.9);
109
+ }
110
+
111
+ .panneau-toast-region li:nth-child(n + 2) > .panneau-toast > * {
112
+ opacity: 0;
113
+ transition: opacity var(--panneau-duration) ease-out;
114
+ }
115
+
116
+ .panneau-toast-region:is(:hover, :focus-within, [data-hovered], [data-focused]) {
117
+ gap: var(--panneau-space-2);
118
+ }
119
+
120
+ .panneau-toast-region:is(:hover, :focus-within, [data-hovered], [data-focused]) li > .panneau-toast {
121
+ transform: none;
122
+ }
123
+
124
+ .panneau-toast-region:is(:hover, :focus-within, [data-hovered], [data-focused]) li > .panneau-toast > * {
125
+ opacity: 1;
126
+ }
127
+
128
+ .panneau-toast-region:not([data-placement='top-end']):is(:hover, :focus-within, [data-hovered], [data-focused])
129
+ li:nth-child(1)
130
+ > .panneau-toast {
131
+ grid-area: 3 / 1;
132
+ }
133
+
134
+ .panneau-toast-region:not([data-placement='top-end']):is(:hover, :focus-within, [data-hovered], [data-focused])
135
+ li:nth-child(2)
136
+ > .panneau-toast {
137
+ grid-area: 2 / 1;
138
+ }
139
+
140
+ .panneau-toast-region:not([data-placement='top-end']):is(:hover, :focus-within, [data-hovered], [data-focused])
141
+ li:nth-child(3)
142
+ > .panneau-toast {
143
+ grid-area: 1 / 1;
144
+ }
145
+
146
+ .panneau-toast-region[data-placement='top-end']:is(:hover, :focus-within, [data-hovered], [data-focused])
147
+ li
148
+ > .panneau-toast {
149
+ grid-area: auto;
150
+ }
151
+
152
+ /* Without motion when the system asks for less. */
153
+ @media (prefers-reduced-motion: reduce) {
154
+ .panneau-toast,
155
+ .panneau-toast-region li > .panneau-toast > * {
156
+ transition: none;
157
+ animation: none;
158
+ }
42
159
  }
43
160
 
44
161
  .panneau-toast[data-focus-visible] {
@@ -46,17 +163,16 @@
46
163
  outline-offset: 2px;
47
164
  }
48
165
 
166
+ /* A success or an info keeps the neutral look, with its icon in the color of its tone. */
49
167
  .panneau-toast-icon {
50
168
  margin-top: 0.125rem;
169
+ color: var(--panneau-tone-text);
51
170
  }
52
171
 
53
- /* A toast with a tone other than neutral: a colored edge and icon, from its tone class. */
54
- .panneau-toast-toned {
172
+ /* Only what needs a look, a warning or an error, colors the edge. */
173
+ .panneau-toast-edge {
55
174
  border-inline-start-color: var(--panneau-tone-text);
56
- }
57
-
58
- .panneau-toast-toned .panneau-toast-icon {
59
- color: var(--panneau-tone-text);
175
+ border-inline-start-width: var(--panneau-toast-tone-width, 4px);
60
176
  }
61
177
 
62
178
  .panneau-toast-content {
@@ -1,14 +1,23 @@
1
- import { type ReactNode } from 'react';
1
+ import { type ReactNode, type RefObject } from 'react';
2
2
  import type { Tone } from '../theme/tones.js';
3
3
  /** @deprecated Use `Tone`. */
4
4
  export type ToastTone = Tone;
5
- /** What a toast says. */
5
+ /**
6
+ * What a toast says: what was done to what ("“Spring contest” saved", "3 entries archived"), and
7
+ * the next step when there is one.
8
+ */
6
9
  export interface ToastContent {
7
10
  title: string;
8
11
  description?: string;
9
- /** Defaults to `neutral`. Any tone other than neutral colors the edge and the icon. */
12
+ /**
13
+ * Defaults to `neutral`. A success keeps the neutral look with its icon; only `warning` and
14
+ * `danger` color the edge.
15
+ */
10
16
  tone?: Tone;
11
- /** A button in the toast, such as "Retry" or "Undo". The toast closes when it is pressed. */
17
+ /**
18
+ * A button in the toast that leads to the result ("Open", "Show", "Download") or undoes what was
19
+ * done ("Undo"). The toast closes when it is pressed.
20
+ */
12
21
  action?: {
13
22
  label: string;
14
23
  onAction: () => void;
@@ -16,26 +25,54 @@ export interface ToastContent {
16
25
  }
17
26
  export interface ToastOptions {
18
27
  /**
19
- * Milliseconds before the toast closes by itself. Defaults to 5000, and to no timeout for
20
- * toasts with an action, which users must have time to reach.
28
+ * A toast with the key of one already shown replaces it instead of adding another: "Saved"
29
+ * once, however many saves. `show()` returns it.
30
+ */
31
+ key?: string;
32
+ /**
33
+ * Milliseconds before the toast closes by itself, or `null` to keep it until it is closed.
34
+ * Defaults to what the toast holds (`getToastTimeout()`): about 5 seconds, longer for a longer
35
+ * text, about 10 seconds with an action, and none for an error.
21
36
  */
22
37
  timeout?: number | null;
23
38
  onClose?: () => void;
24
39
  }
25
40
  export interface Toasts {
26
- /** Shows a toast. Returns its key. */
41
+ /** Shows a toast. Returns its key: the one given in its options, or a new one. */
27
42
  show(content: ToastContent, options?: ToastOptions): string;
28
43
  /** Closes a toast by key. */
29
44
  close(key: string): void;
30
45
  }
46
+ /** Where toasts show: `bottom` (centered, the default), `bottom-end` or `top-end`. */
47
+ export type ToastPlacement = 'bottom' | 'bottom-end' | 'top-end';
48
+ /** At most this many toasts show at once: older ones wait for a place. */
49
+ export declare const MAX_VISIBLE_TOASTS = 3;
50
+ /**
51
+ * How long a toast stays, from what it holds: about 5 seconds, longer for a longer text; about 10
52
+ * seconds with an action, which must be reached in that time (an action to reach later belongs in
53
+ * the page, not in a toast that stays); and `null`, no timeout, for an error the user must read.
54
+ */
55
+ export declare function getToastTimeout(content: ToastContent): number | null;
31
56
  /** Shows toasts in the closest `PanneauRoot`. */
32
57
  export declare function useToast(): Toasts;
58
+ /**
59
+ * Raises the toasts above an element that sticks to the bottom of the page, such as the footer of
60
+ * a form, while it is mounted and `active`: its height becomes the `--panneau-bottom-offset` of the
61
+ * region. Toasts at the top ignore it.
62
+ */
63
+ export declare function useToastOffset(ref: RefObject<HTMLElement | null>, active?: boolean): void;
33
64
  export interface ToastProviderProps {
34
65
  children?: ReactNode;
66
+ /** Where the toasts show. Defaults to `bottom`. */
67
+ placement?: ToastPlacement;
35
68
  /** Class names that give the region its tokens, since it renders in the body. */
36
69
  regionClassName?: string;
37
70
  regionProps?: Record<`data-${string}`, string | undefined>;
38
71
  }
39
- /** Holds the toasts of a `PanneauRoot` and renders them in an accessible region. */
40
- export declare function ToastProvider({ children, regionClassName, regionProps }: ToastProviderProps): import("react").JSX.Element;
72
+ /**
73
+ * Holds the toasts of a `PanneauRoot` and renders them in an accessible region (decision 0062): at
74
+ * the bottom by default, one per key, at most three, the older ones folded behind the newest until
75
+ * the region is hovered or focused, where their timers pause.
76
+ */
77
+ export declare function ToastProvider({ children, placement, regionClassName, regionProps, }: ToastProviderProps): import("react").JSX.Element;
41
78
  //# sourceMappingURL=Toast.d.ts.map
@@ -1 +1 @@
1
- {"version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AAC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,MAAM,UAAO,GAAG,IAAI,CAiBtF;AA4DD,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,mDAAmD;IACnD,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC,QAAQ,MAAM,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAC1B,QAAQ,EACR,SAAoB,EACpB,eAAe,EACf,WAAW,GACd,EAAE,kBAAkB,+BAwEpB"}
@@ -10,8 +10,28 @@ import { c } from "react/compiler-runtime";
10
10
  import { CircleAlert, CircleCheck, Info, TriangleAlert, X } from "lucide-react";
11
11
  import { Text, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion } from "react-aria-components";
12
12
  import { jsx, jsxs } from "react/jsx-runtime";
13
- import { createContext, use, useState } from "react";
13
+ import { createContext, use, useEffect, useState } from "react";
14
14
  //#region src/toast/Toast.tsx
15
+ /** At most this many toasts show at once: older ones wait for a place. */
16
+ var MAX_VISIBLE_TOASTS = 3;
17
+ /** Reading time of a toast without an action: at least 5 seconds, at most 10. */
18
+ var MIN_TIMEOUT = 5e3;
19
+ /** A toast with an action stays about 10 seconds, longer for a longer text. */
20
+ var ACTION_TIMEOUT = 1e4;
21
+ var MAX_TIMEOUT = 15e3;
22
+ /** About 200 words a minute, plus the time to notice the toast. */
23
+ var PER_WORD = 300;
24
+ var NOTICE = 2e3;
25
+ /**
26
+ * How long a toast stays, from what it holds: about 5 seconds, longer for a longer text; about 10
27
+ * seconds with an action, which must be reached in that time (an action to reach later belongs in
28
+ * the page, not in a toast that stays); and `null`, no timeout, for an error the user must read.
29
+ */
30
+ function getToastTimeout(content) {
31
+ if (content.tone === "danger") return null;
32
+ const reading = NOTICE + `${content.title} ${content.description ?? ""} ${content.action?.label ?? ""}`.split(/\s+/).filter((word) => word !== "").length * PER_WORD;
33
+ return content.action !== void 0 ? Math.min(Math.max(ACTION_TIMEOUT, reading), MAX_TIMEOUT) : Math.min(Math.max(MIN_TIMEOUT, reading), ACTION_TIMEOUT);
34
+ }
15
35
  var TONE_ICONS = {
16
36
  neutral: null,
17
37
  success: CircleCheck,
@@ -19,6 +39,8 @@ var TONE_ICONS = {
19
39
  warning: TriangleAlert,
20
40
  info: Info
21
41
  };
42
+ /** Tones that color the edge of a toast: what needs a look. */
43
+ var EDGE_TONES = /* @__PURE__ */ new Set(["warning", "danger"]);
22
44
  var ToastContext = createContext(null);
23
45
  /** Shows toasts in the closest `PanneauRoot`. */
24
46
  function useToast() {
@@ -26,53 +48,149 @@ function useToast() {
26
48
  if (toasts === null) throw new Error("useToast() must be used inside <PanneauRoot>.");
27
49
  return toasts;
28
50
  }
29
- /** Holds the toasts of a `PanneauRoot` and renders them in an accessible region. */
51
+ /**
52
+ * Raises the toasts above an element that sticks to the bottom of the page, such as the footer of
53
+ * a form, while it is mounted and `active`: its height becomes the `--panneau-bottom-offset` of the
54
+ * region. Toasts at the top ignore it.
55
+ */
56
+ function useToastOffset(ref, t0) {
57
+ const $ = c(5);
58
+ const active = t0 === void 0 ? true : t0;
59
+ const toasts = use(ToastContext);
60
+ let t1;
61
+ let t2;
62
+ if ($[0] !== active || $[1] !== ref || $[2] !== toasts) {
63
+ t1 = () => {
64
+ const element = ref.current;
65
+ if (toasts === null || element === null || !active) return;
66
+ const id = {};
67
+ const measure = () => toasts.setOffset(id, element.getBoundingClientRect().height);
68
+ measure();
69
+ const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null;
70
+ observer?.observe(element);
71
+ return () => {
72
+ observer?.disconnect();
73
+ toasts.setOffset(id, null);
74
+ };
75
+ };
76
+ t2 = [
77
+ ref,
78
+ toasts,
79
+ active
80
+ ];
81
+ $[0] = active;
82
+ $[1] = ref;
83
+ $[2] = toasts;
84
+ $[3] = t1;
85
+ $[4] = t2;
86
+ } else {
87
+ t1 = $[3];
88
+ t2 = $[4];
89
+ }
90
+ useEffect(t1, t2);
91
+ }
92
+ /**
93
+ * The toasts of a region: `show()` with keys over React Aria's queue, and the offsets of what
94
+ * sticks to the bottom of the page.
95
+ */
96
+ function createToasts(queue, setOffsets) {
97
+ const shown = /* @__PURE__ */ new Map();
98
+ const keys = /* @__PURE__ */ new Map();
99
+ const forget = (added) => {
100
+ const own = keys.get(added);
101
+ if (own !== void 0 && shown.get(own) === added) shown.delete(own);
102
+ keys.delete(added);
103
+ };
104
+ return {
105
+ show(content, { key, timeout, onClose } = {}) {
106
+ const delay = timeout === void 0 ? getToastTimeout(content) : timeout;
107
+ const previous = key !== void 0 ? shown.get(key) : void 0;
108
+ if (previous !== void 0) {
109
+ keys.delete(previous);
110
+ queue.close(previous);
111
+ }
112
+ let added = "";
113
+ added = queue.add(content, {
114
+ ...delay !== null ? { timeout: delay } : {},
115
+ onClose: () => {
116
+ forget(added);
117
+ onClose?.();
118
+ }
119
+ });
120
+ if (key === void 0) return added;
121
+ shown.set(key, added);
122
+ keys.set(added, key);
123
+ return key;
124
+ },
125
+ close(key) {
126
+ queue.close(shown.get(key) ?? key);
127
+ },
128
+ setOffset(id, height) {
129
+ setOffsets((current) => {
130
+ const next = new Map(current);
131
+ if (height === null) next.delete(id);
132
+ else next.set(id, height);
133
+ return next;
134
+ });
135
+ }
136
+ };
137
+ }
138
+ /**
139
+ * Holds the toasts of a `PanneauRoot` and renders them in an accessible region (decision 0062): at
140
+ * the bottom by default, one per key, at most three, the older ones folded behind the newest until
141
+ * the region is hovered or focused, where their timers pause.
142
+ */
30
143
  function ToastProvider(t0) {
31
- const $ = c(19);
32
- const { children, regionClassName, regionProps } = t0;
144
+ const $ = c(25);
145
+ const { children, placement: t1, regionClassName, regionProps } = t0;
146
+ const placement = t1 === void 0 ? "bottom" : t1;
33
147
  const intl = usePanneauIntl();
34
148
  const [queue] = useState(_temp);
35
- let t1;
149
+ const [offsets, setOffsets] = useState(_temp2);
150
+ let t2;
36
151
  if ($[0] !== queue) {
37
- t1 = () => ({
38
- show(content, t2) {
39
- const { timeout, onClose } = t2 === void 0 ? {} : t2;
40
- const delay = timeout === void 0 ? content.action ? null : 5e3 : timeout;
41
- return queue.add(content, {
42
- ...delay !== null ? { timeout: delay } : {},
43
- ...onClose !== void 0 ? { onClose } : {}
44
- });
45
- },
46
- close(key) {
47
- queue.close(key);
48
- }
49
- });
152
+ t2 = () => createToasts(queue, setOffsets);
50
153
  $[0] = queue;
51
- $[1] = t1;
52
- } else t1 = $[1];
53
- const [toasts] = useState(t1);
54
- let t2;
55
- if ($[2] !== intl) {
56
- t2 = intl.formatMessage(messages.notifications);
57
- $[2] = intl;
58
- $[3] = t2;
59
- } else t2 = $[3];
154
+ $[1] = t2;
155
+ } else t2 = $[1];
156
+ const [toasts] = useState(t2);
60
157
  let t3;
61
- if ($[4] !== regionClassName) {
62
- t3 = cx("panneau-toast-region", regionClassName, Toast_module_default.region);
63
- $[4] = regionClassName;
64
- $[5] = t3;
65
- } else t3 = $[5];
158
+ if ($[2] !== offsets) {
159
+ t3 = Math.max(0, ...offsets.values());
160
+ $[2] = offsets;
161
+ $[3] = t3;
162
+ } else t3 = $[3];
163
+ const offset = t3;
66
164
  let t4;
67
- if ($[6] !== intl || $[7] !== queue) {
68
- t4 = (t5) => {
69
- const { toast } = t5;
165
+ if ($[4] !== intl) {
166
+ t4 = intl.formatMessage(messages.notifications);
167
+ $[4] = intl;
168
+ $[5] = t4;
169
+ } else t4 = $[5];
170
+ let t5;
171
+ if ($[6] !== regionClassName) {
172
+ t5 = cx("panneau-toast-region", regionClassName, Toast_module_default.region);
173
+ $[6] = regionClassName;
174
+ $[7] = t5;
175
+ } else t5 = $[7];
176
+ const t6 = `${offset}px`;
177
+ let t7;
178
+ if ($[8] !== t6) {
179
+ t7 = { "--panneau-bottom-offset": t6 };
180
+ $[8] = t6;
181
+ $[9] = t7;
182
+ } else t7 = $[9];
183
+ const t8 = t7;
184
+ let t9;
185
+ if ($[10] !== intl || $[11] !== queue) {
186
+ t9 = (t10) => {
187
+ const { toast } = t10;
70
188
  const tone = toast.content.tone ?? "neutral";
71
189
  const icon = TONE_ICONS[tone] ?? null;
72
190
  const { action } = toast.content;
73
191
  return /* @__PURE__ */ jsxs(UNSTABLE_Toast, {
74
192
  toast,
75
- className: cx("panneau-toast", Toast_module_default.toast, toneClass(tone), tone !== "neutral" && Toast_module_default.toned),
193
+ className: cx("panneau-toast", Toast_module_default.toast, toneClass(tone), EDGE_TONES.has(tone) && Toast_module_default.edge),
76
194
  children: [
77
195
  icon !== null ? /* @__PURE__ */ jsx(Icon, {
78
196
  icon,
@@ -111,43 +229,50 @@ function ToastProvider(t0) {
111
229
  ]
112
230
  });
113
231
  };
114
- $[6] = intl;
115
- $[7] = queue;
116
- $[8] = t4;
117
- } else t4 = $[8];
118
- let t5;
119
- if ($[9] !== queue || $[10] !== regionProps || $[11] !== t2 || $[12] !== t3 || $[13] !== t4) {
120
- t5 = /* @__PURE__ */ jsx(UNSTABLE_ToastRegion, {
232
+ $[10] = intl;
233
+ $[11] = queue;
234
+ $[12] = t9;
235
+ } else t9 = $[12];
236
+ let t10;
237
+ if ($[13] !== placement || $[14] !== queue || $[15] !== regionProps || $[16] !== t4 || $[17] !== t5 || $[18] !== t8 || $[19] !== t9) {
238
+ t10 = /* @__PURE__ */ jsx(UNSTABLE_ToastRegion, {
121
239
  queue,
122
- "aria-label": t2,
123
- className: t3,
240
+ "aria-label": t4,
241
+ className: t5,
242
+ "data-placement": placement,
243
+ style: t8,
124
244
  ...regionProps,
125
- children: t4
245
+ children: t9
126
246
  });
127
- $[9] = queue;
128
- $[10] = regionProps;
129
- $[11] = t2;
130
- $[12] = t3;
131
- $[13] = t4;
132
- $[14] = t5;
133
- } else t5 = $[14];
134
- let t6;
135
- if ($[15] !== children || $[16] !== t5 || $[17] !== toasts) {
136
- t6 = /* @__PURE__ */ jsxs(ToastContext, {
247
+ $[13] = placement;
248
+ $[14] = queue;
249
+ $[15] = regionProps;
250
+ $[16] = t4;
251
+ $[17] = t5;
252
+ $[18] = t8;
253
+ $[19] = t9;
254
+ $[20] = t10;
255
+ } else t10 = $[20];
256
+ let t11;
257
+ if ($[21] !== children || $[22] !== t10 || $[23] !== toasts) {
258
+ t11 = /* @__PURE__ */ jsxs(ToastContext, {
137
259
  value: toasts,
138
- children: [children, t5]
260
+ children: [children, t10]
139
261
  });
140
- $[15] = children;
141
- $[16] = t5;
142
- $[17] = toasts;
143
- $[18] = t6;
144
- } else t6 = $[18];
145
- return t6;
262
+ $[21] = children;
263
+ $[22] = t10;
264
+ $[23] = toasts;
265
+ $[24] = t11;
266
+ } else t11 = $[24];
267
+ return t11;
268
+ }
269
+ function _temp2() {
270
+ return /* @__PURE__ */ new Map();
146
271
  }
147
272
  function _temp() {
148
- return new UNSTABLE_ToastQueue({ maxVisibleToasts: 5 });
273
+ return new UNSTABLE_ToastQueue({ maxVisibleToasts: 3 });
149
274
  }
150
275
  //#endregion
151
- export { ToastProvider, useToast };
276
+ export { MAX_VISIBLE_TOASTS, ToastProvider, getToastTimeout, useToast, useToastOffset };
152
277
 
153
278
  //# sourceMappingURL=Toast.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Toast.js","names":["CircleAlert","CircleCheck","Info","TriangleAlert","X","ReactNode","createContext","use","useState","UNSTABLE_Toast","AriaToast","UNSTABLE_ToastContent","AriaToastContent","UNSTABLE_ToastQueue","AriaToastQueue","UNSTABLE_ToastRegion","AriaToastRegion","Text","Button","IconButton","Icon","IconComponent","messages","usePanneauIntl","toneClass","Tone","cx","styles","ToastTone","ToastContent","title","description","tone","action","label","onAction","ToastOptions","timeout","onClose","Toasts","show","content","options","close","key","TONE_ICONS","Partial","Record","neutral","success","danger","warning","info","ToastContext","useToast","toasts","Error","ToastProviderProps","children","regionClassName","regionProps","ToastProvider","t0","$","_c","intl","queue","_temp","t1","t2","undefined","delay","add","formatMessage","notifications","t3","region","t4","t5","toast","icon","toned","actions","t6","maxVisibleToasts","_c","styles","AriaToast","AriaToastContent","Button","AriaToastRegion","AriaToastQueue"],"sources":["../../src/toast/Toast.tsx"],"sourcesContent":["import { CircleAlert, CircleCheck, Info, TriangleAlert, X } from 'lucide-react';\nimport { type ReactNode, createContext, use, useState } from 'react';\nimport {\n UNSTABLE_Toast as AriaToast,\n UNSTABLE_ToastContent as AriaToastContent,\n UNSTABLE_ToastQueue as AriaToastQueue,\n UNSTABLE_ToastRegion as AriaToastRegion,\n Text,\n} from 'react-aria-components';\n\nimport { Button } from '../button/Button';\nimport { IconButton } from '../icon-button/IconButton';\nimport { Icon, type IconComponent } from '../icon/Icon';\nimport { messages } from '../intl/messages';\nimport { usePanneauIntl } from '../intl/usePanneauIntl';\nimport { toneClass } from '../theme/toneClass';\nimport type { Tone } from '../theme/tones';\nimport { cx } from '../utils/cx';\nimport styles from './Toast.module.css';\n\n/** @deprecated Use `Tone`. */\nexport type ToastTone = Tone;\n\n/** What a toast says. */\nexport interface ToastContent {\n title: string;\n description?: string;\n /** Defaults to `neutral`. Any tone other than neutral colors the edge and the icon. */\n tone?: Tone;\n /** A button in the toast, such as \"Retry\" or \"Undo\". The toast closes when it is pressed. */\n action?: { label: string; onAction: () => void };\n}\n\nexport interface ToastOptions {\n /**\n * Milliseconds before the toast closes by itself. Defaults to 5000, and to no timeout for\n * toasts with an action, which users must have time to reach.\n */\n timeout?: number | null;\n onClose?: () => void;\n}\n\nexport interface Toasts {\n /** Shows a toast. Returns its key. */\n show(content: ToastContent, options?: ToastOptions): string;\n /** Closes a toast by key. */\n close(key: string): void;\n}\n\nconst TONE_ICONS: Partial<Record<Tone, IconComponent | null>> = {\n neutral: null,\n success: CircleCheck,\n danger: CircleAlert,\n warning: TriangleAlert,\n info: Info,\n};\n\nconst ToastContext = createContext<Toasts | null>(null);\n\n/** Shows toasts in the closest `PanneauRoot`. */\nexport function useToast(): Toasts {\n const toasts = use(ToastContext);\n if (toasts === null) {\n throw new Error('useToast() must be used inside <PanneauRoot>.');\n }\n return toasts;\n}\n\nexport interface ToastProviderProps {\n children?: ReactNode;\n /** Class names that give the region its tokens, since it renders in the body. */\n regionClassName?: string;\n regionProps?: Record<`data-${string}`, string | undefined>;\n}\n\n/** Holds the toasts of a `PanneauRoot` and renders them in an accessible region. */\nexport function ToastProvider({ children, regionClassName, regionProps }: ToastProviderProps) {\n const intl = usePanneauIntl();\n const [queue] = useState(() => new AriaToastQueue<ToastContent>({ maxVisibleToasts: 5 }));\n const [toasts] = useState<Toasts>(() => ({\n show(content, { timeout, onClose } = {}) {\n const delay = timeout === undefined ? (content.action ? null : 5000) : timeout;\n return queue.add(content, {\n ...(delay !== null ? { timeout: delay } : {}),\n ...(onClose !== undefined ? { onClose } : {}),\n });\n },\n close(key) {\n queue.close(key);\n },\n }));\n return (\n <ToastContext value={toasts}>\n {children}\n <AriaToastRegion\n queue={queue}\n aria-label={intl.formatMessage(messages.notifications)}\n className={cx('panneau-toast-region', regionClassName, styles.region)}\n {...regionProps}\n >\n {({ toast }) => {\n const tone = toast.content.tone ?? 'neutral';\n const icon = TONE_ICONS[tone] ?? null;\n const { action } = toast.content;\n return (\n <AriaToast\n toast={toast}\n className={cx(\n 'panneau-toast',\n styles.toast,\n toneClass(tone),\n tone !== 'neutral' && styles.toned,\n )}\n >\n {icon !== null ? (\n <Icon icon={icon} size=\"lg\" className={styles.icon} />\n ) : null}\n <AriaToastContent className={styles.content}>\n <Text slot=\"title\" className={styles.title}>\n {toast.content.title}\n </Text>\n {toast.content.description !== undefined ? (\n <Text slot=\"description\" className={styles.description}>\n {toast.content.description}\n </Text>\n ) : null}\n </AriaToastContent>\n <div className={styles.actions}>\n {action !== undefined ? (\n <Button\n size=\"sm\"\n onPress={() => {\n action.onAction();\n queue.close(toast.key);\n }}\n >\n {action.label}\n </Button>\n ) : null}\n <IconButton\n slot=\"close\"\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.close)}\n showTooltip={false}\n />\n </div>\n </AriaToast>\n );\n }}\n </AriaToastRegion>\n </ToastContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAiDA,IAAM6C,aAA0D;CAC5DG,SAAS;CACTC,SAAShD;CACTiD,QAAQlD;CACRmD,SAAShD;CACTiD,MAAMlD;AACV;AAEA,IAAMmD,eAAe/C,cAA6B,IAAI;;AAGtD,SAAgBgD,WAAmB;CAC/B,MAAMC,SAAShD,IAAI8C,YAAY;CAC/B,IAAIE,WAAW,MACX,MAAM,IAAIC,MAAM,+CAA+C;CAEnE,OAAOD;AACX;;AAUA,SAAOM,cAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAuB,MAAA,EAAAN,UAAAC,iBAAAC,gBAAAE;CAC1B,MAAAG,OAAa1C,eAAe;CAC5B,MAAA,CAAA2C,SAAgB1D,SAAS2D,KAA+D;CAAE,IAAAC;CAAA,IAAAL,EAAA,OAAAG,OAAA;EACxDE,YAAO;GAAA5B,KAAAC,SAAA4B,IAAA;IACvB,MAAA,EAAAhC,SAAAC,YAAA+B,OAAAC,KAAAA,IAAA,CAAwB,IAAxBD;IACV,MAAAE,QAAclC,YAAYiC,KAAAA,IAAa7B,QAAOR,SAAP,OAAA,MAAzBI;IAAiE,OACxE6B,MAAKM,IAAK/B,SAAS;KAAA,GAClB8B,UAAU,OAAV,EAAAlC,SAA4BkC,MAAW,IAAvC,CAAuC;KAAC,GACxCjC,YAAYgC,KAAAA,IAAZ,EAAAhC,QAAuC,IAAvC,CAAuC;IAC/C,CAAC;GAAC;GAAAK,MAAAC,KAAA;IAGFsB,MAAKvB,MAAOC,GAAG;GAAC;EAExB;EAAEmB,EAAA,KAAAG;EAAAH,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAXF,MAAA,CAAAR,UAAiB/C,SAAiB4D,EAWhC;CAAE,IAAAC;CAAA,IAAAN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AKvB,MAAOoC,MAAKnC,GAAI;OAAC;OAGzBX,UAAAA,OAAMC;MAPJ,CAAA,IADV,MAWD,oBAAC,YAAD;OACS,MAAA;OACC9B,MAAAA;OACD,MAAA;OACE,OAAA6D,KAAIQ,cAAenD,SAAQqB,KAAM;OAC3B,aAAA;MAAK,CAAA,CAEpB;;IAzCA;;EA0CE;EAEnBoB,EAAA,KAAAE;EAAAF,EAAA,KAAAG;EAAAH,EAAA,KAAAc;CAAA,OAAAA,KAAAd,EAAA;CAAA,IAAAe;CAAA,IAAAf,EAAA,OAAAG,SAAAH,EAAA,QAAAH,eAAAG,EAAA,QAAAM,MAAAN,EAAA,QAAAY,MAAAZ,EAAA,QAAAc,IAAA;EAvDLC,KAAA,oBAACY,sBAAD;GACWxB;GACK,cAAAG;GACD,WAAAM;GAA0D,GACjEf;GAEHiB,UAAAA;EANW,CAAA;EAwDEd,EAAA,KAAAG;EAAAH,EAAA,MAAAH;EAAAG,EAAA,MAAAM;EAAAN,EAAA,MAAAY;EAAAZ,EAAA,MAAAc;EAAAd,EAAA,MAAAe;CAAA,OAAAA,KAAAf,EAAA;CAAA,IAAAoB;CAAA,IAAApB,EAAA,QAAAL,YAAAK,EAAA,QAAAe,MAAAf,EAAA,QAAAR,QAAA;EA1DtB4B,KAAA,qBAAC,cAAD;GAAqB5B,OAAAA;GAArB,UAAA,CACKG,UACDoB,EAFS;;EA2DEf,EAAA,MAAAL;EAAAK,EAAA,MAAAe;EAAAf,EAAA,MAAAR;EAAAQ,EAAA,MAAAoB;CAAA,OAAAA,KAAApB,EAAA;CAAA,OA3DfoB;AA2De;AA3EhB,SAAAhB,QAAA;CAAA,OAE4B,IAAIrD,oBAA6B,EAAAsE,kBAAoB,EAAE,CAAC;AAAC"}
1
+ {"version":3,"file":"Toast.js","names":["CircleAlert","CircleCheck","Info","TriangleAlert","X","CSSProperties","Dispatch","ReactNode","RefObject","SetStateAction","createContext","use","useEffect","useState","UNSTABLE_Toast","AriaToast","UNSTABLE_ToastContent","AriaToastContent","UNSTABLE_ToastQueue","AriaToastQueue","UNSTABLE_ToastRegion","AriaToastRegion","Text","Button","IconButton","Icon","IconComponent","messages","usePanneauIntl","toneClass","Tone","cx","styles","ToastTone","ToastContent","title","description","tone","action","label","onAction","ToastOptions","key","timeout","onClose","Toasts","show","content","options","close","ToastPlacement","MAX_VISIBLE_TOASTS","MIN_TIMEOUT","ACTION_TIMEOUT","MAX_TIMEOUT","PER_WORD","NOTICE","getToastTimeout","words","split","filter","word","length","reading","undefined","Math","min","max","TONE_ICONS","Partial","Record","neutral","success","danger","warning","info","EDGE_TONES","Set","ToastContextValue","setOffset","id","height","ToastContext","useToast","toasts","Error","useToastOffset","ref","t0","$","_c","active","t1","t2","element","current","measure","getBoundingClientRect","observer","ResizeObserver","observe","disconnect","createToasts","queue","setOffsets","ReadonlyMap","shown","Map","keys","forget","added","own","get","delete","delay","previous","add","set","next","ToastProviderProps","children","placement","regionClassName","regionProps","ToastProvider","intl","_temp","offsets","_temp2","t3","values","offset","t4","formatMessage","notifications","t5","region","t6","t7","t8","t9","t10","toast","icon","has","edge","actions","t11","maxVisibleToasts","_c","styles","AriaToast","AriaToastContent","Button","AriaToastRegion","AriaToastQueue"],"sources":["../../src/toast/Toast.tsx"],"sourcesContent":["import { CircleAlert, CircleCheck, Info, TriangleAlert, X } from 'lucide-react';\nimport {\n type CSSProperties,\n type Dispatch,\n type ReactNode,\n type RefObject,\n type SetStateAction,\n createContext,\n use,\n useEffect,\n useState,\n} from 'react';\nimport {\n UNSTABLE_Toast as AriaToast,\n UNSTABLE_ToastContent as AriaToastContent,\n UNSTABLE_ToastQueue as AriaToastQueue,\n UNSTABLE_ToastRegion as AriaToastRegion,\n Text,\n} from 'react-aria-components';\n\nimport { Button } from '../button/Button';\nimport { IconButton } from '../icon-button/IconButton';\nimport { Icon, type IconComponent } from '../icon/Icon';\nimport { messages } from '../intl/messages';\nimport { usePanneauIntl } from '../intl/usePanneauIntl';\nimport { toneClass } from '../theme/toneClass';\nimport type { Tone } from '../theme/tones';\nimport { cx } from '../utils/cx';\nimport styles from './Toast.module.css';\n\n/** @deprecated Use `Tone`. */\nexport type ToastTone = Tone;\n\n/**\n * What a toast says: what was done to what (\"“Spring contest” saved\", \"3 entries archived\"), and\n * the next step when there is one.\n */\nexport interface ToastContent {\n title: string;\n description?: string;\n /**\n * Defaults to `neutral`. A success keeps the neutral look with its icon; only `warning` and\n * `danger` color the edge.\n */\n tone?: Tone;\n /**\n * A button in the toast that leads to the result (\"Open\", \"Show\", \"Download\") or undoes what was\n * done (\"Undo\"). The toast closes when it is pressed.\n */\n action?: { label: string; onAction: () => void };\n}\n\nexport interface ToastOptions {\n /**\n * A toast with the key of one already shown replaces it instead of adding another: \"Saved\"\n * once, however many saves. `show()` returns it.\n */\n key?: string;\n /**\n * Milliseconds before the toast closes by itself, or `null` to keep it until it is closed.\n * Defaults to what the toast holds (`getToastTimeout()`): about 5 seconds, longer for a longer\n * text, about 10 seconds with an action, and none for an error.\n */\n timeout?: number | null;\n onClose?: () => void;\n}\n\nexport interface Toasts {\n /** Shows a toast. Returns its key: the one given in its options, or a new one. */\n show(content: ToastContent, options?: ToastOptions): string;\n /** Closes a toast by key. */\n close(key: string): void;\n}\n\n/** Where toasts show: `bottom` (centered, the default), `bottom-end` or `top-end`. */\nexport type ToastPlacement = 'bottom' | 'bottom-end' | 'top-end';\n\n/** At most this many toasts show at once: older ones wait for a place. */\nexport const MAX_VISIBLE_TOASTS = 3;\n\n/** Reading time of a toast without an action: at least 5 seconds, at most 10. */\nconst MIN_TIMEOUT = 5000;\n/** A toast with an action stays about 10 seconds, longer for a longer text. */\nconst ACTION_TIMEOUT = 10000;\nconst MAX_TIMEOUT = 15000;\n/** About 200 words a minute, plus the time to notice the toast. */\nconst PER_WORD = 300;\nconst NOTICE = 2000;\n\n/**\n * How long a toast stays, from what it holds: about 5 seconds, longer for a longer text; about 10\n * seconds with an action, which must be reached in that time (an action to reach later belongs in\n * the page, not in a toast that stays); and `null`, no timeout, for an error the user must read.\n */\nexport function getToastTimeout(content: ToastContent): number | null {\n if (content.tone === 'danger') {\n return null;\n }\n const words = `${content.title} ${content.description ?? ''} ${content.action?.label ?? ''}`\n .split(/\\s+/)\n .filter((word) => word !== '').length;\n const reading = NOTICE + words * PER_WORD;\n return content.action !== undefined\n ? Math.min(Math.max(ACTION_TIMEOUT, reading), MAX_TIMEOUT)\n : Math.min(Math.max(MIN_TIMEOUT, reading), ACTION_TIMEOUT);\n}\n\nconst TONE_ICONS: Partial<Record<Tone, IconComponent | null>> = {\n neutral: null,\n success: CircleCheck,\n danger: CircleAlert,\n warning: TriangleAlert,\n info: Info,\n};\n\n/** Tones that color the edge of a toast: what needs a look. */\nconst EDGE_TONES = new Set<Tone>(['warning', 'danger']);\n\ninterface ToastContextValue extends Toasts {\n /** Sets how far toasts rise above what sticks to the bottom of the page, by who sets it. */\n setOffset(id: object, height: number | null): void;\n}\n\nconst ToastContext = createContext<ToastContextValue | null>(null);\n\n/** Shows toasts in the closest `PanneauRoot`. */\nexport function useToast(): Toasts {\n const toasts = use(ToastContext);\n if (toasts === null) {\n throw new Error('useToast() must be used inside <PanneauRoot>.');\n }\n return toasts;\n}\n\n/**\n * Raises the toasts above an element that sticks to the bottom of the page, such as the footer of\n * a form, while it is mounted and `active`: its height becomes the `--panneau-bottom-offset` of the\n * region. Toasts at the top ignore it.\n */\nexport function useToastOffset(ref: RefObject<HTMLElement | null>, active = true): void {\n const toasts = use(ToastContext);\n useEffect(() => {\n const element = ref.current;\n if (toasts === null || element === null || !active) {\n return undefined;\n }\n const id = {};\n const measure = () => toasts.setOffset(id, element.getBoundingClientRect().height);\n measure();\n const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : null;\n observer?.observe(element);\n return () => {\n observer?.disconnect();\n toasts.setOffset(id, null);\n };\n }, [ref, toasts, active]);\n}\n\n/**\n * The toasts of a region: `show()` with keys over React Aria's queue, and the offsets of what\n * sticks to the bottom of the page.\n */\nfunction createToasts(\n queue: AriaToastQueue<ToastContent>,\n setOffsets: Dispatch<SetStateAction<ReadonlyMap<object, number>>>,\n): ToastContextValue {\n // The toast shown for each key given to show(), and back.\n const shown = new Map<string, string>();\n const keys = new Map<string, string>();\n const forget = (added: string) => {\n const own = keys.get(added);\n if (own !== undefined && shown.get(own) === added) {\n shown.delete(own);\n }\n keys.delete(added);\n };\n return {\n show(content, { key, timeout, onClose } = {}) {\n const delay = timeout === undefined ? getToastTimeout(content) : timeout;\n const previous = key !== undefined ? shown.get(key) : undefined;\n if (previous !== undefined) {\n keys.delete(previous);\n queue.close(previous);\n }\n let added = '';\n added = queue.add(content, {\n ...(delay !== null ? { timeout: delay } : {}),\n onClose: () => {\n forget(added);\n onClose?.();\n },\n });\n if (key === undefined) {\n return added;\n }\n shown.set(key, added);\n keys.set(added, key);\n return key;\n },\n close(key) {\n queue.close(shown.get(key) ?? key);\n },\n setOffset(id, height) {\n setOffsets((current) => {\n const next = new Map(current);\n if (height === null) {\n next.delete(id);\n } else {\n next.set(id, height);\n }\n return next;\n });\n },\n };\n}\n\nexport interface ToastProviderProps {\n children?: ReactNode;\n /** Where the toasts show. Defaults to `bottom`. */\n placement?: ToastPlacement;\n /** Class names that give the region its tokens, since it renders in the body. */\n regionClassName?: string;\n regionProps?: Record<`data-${string}`, string | undefined>;\n}\n\n/**\n * Holds the toasts of a `PanneauRoot` and renders them in an accessible region (decision 0062): at\n * the bottom by default, one per key, at most three, the older ones folded behind the newest until\n * the region is hovered or focused, where their timers pause.\n */\nexport function ToastProvider({\n children,\n placement = 'bottom',\n regionClassName,\n regionProps,\n}: ToastProviderProps) {\n const intl = usePanneauIntl();\n const [queue] = useState(\n () => new AriaToastQueue<ToastContent>({ maxVisibleToasts: MAX_VISIBLE_TOASTS }),\n );\n const [offsets, setOffsets] = useState<ReadonlyMap<object, number>>(() => new Map());\n const [toasts] = useState(() => createToasts(queue, setOffsets));\n const offset = Math.max(0, ...offsets.values());\n return (\n <ToastContext value={toasts}>\n {children}\n <AriaToastRegion\n queue={queue}\n aria-label={intl.formatMessage(messages.notifications)}\n className={cx('panneau-toast-region', regionClassName, styles.region)}\n data-placement={placement}\n style={{ '--panneau-bottom-offset': `${offset}px` } as CSSProperties}\n {...regionProps}\n >\n {({ toast }) => {\n const tone = toast.content.tone ?? 'neutral';\n const icon = TONE_ICONS[tone] ?? null;\n const { action } = toast.content;\n return (\n <AriaToast\n toast={toast}\n className={cx(\n 'panneau-toast',\n styles.toast,\n toneClass(tone),\n EDGE_TONES.has(tone) && styles.edge,\n )}\n >\n {icon !== null ? (\n <Icon icon={icon} size=\"lg\" className={styles.icon} />\n ) : null}\n <AriaToastContent className={styles.content}>\n <Text slot=\"title\" className={styles.title}>\n {toast.content.title}\n </Text>\n {toast.content.description !== undefined ? (\n <Text slot=\"description\" className={styles.description}>\n {toast.content.description}\n </Text>\n ) : null}\n </AriaToastContent>\n <div className={styles.actions}>\n {action !== undefined ? (\n <Button\n size=\"sm\"\n onPress={() => {\n action.onAction();\n queue.close(toast.key);\n }}\n >\n {action.label}\n </Button>\n ) : null}\n <IconButton\n slot=\"close\"\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.close)}\n showTooltip={false}\n />\n </div>\n </AriaToast>\n );\n }}\n </AriaToastRegion>\n </ToastContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8EA,IAAamD,qBAAqB;;AAGlC,IAAMC,cAAc;;AAEpB,IAAMC,iBAAiB;AACvB,IAAMC,cAAc;;AAEpB,IAAMC,WAAW;AACjB,IAAMC,SAAS;;;;;;AAOf,SAAgBC,gBAAgBV,SAAsC;CAClE,IAAIA,QAAQV,SAAS,UACjB,OAAO;CAKX,MAAM0B,UAAUP,SAHF,GAAGT,QAAQZ,MAAK,GAAIY,QAAQX,eAAe,GAAE,GAAIW,QAAQT,QAAQC,SAAS,KACnFoB,MAAM,KAAK,CAAC,CACZC,QAAQC,SAASA,SAAS,EAAE,CAAC,CAACC,SACFP;CACjC,OAAO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