@panneau/ui 5.0.0-alpha.21 → 5.0.0-alpha.23
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/dist/toast/Toast.d.ts +10 -2
- package/dist/toast/Toast.d.ts.map +1 -1
- package/dist/toast/Toast.js +32 -5
- package/dist/toast/Toast.js.map +1 -1
- package/package.json +3 -3
package/dist/toast/Toast.d.ts
CHANGED
|
@@ -55,10 +55,18 @@ export declare const MAX_VISIBLE_TOASTS = 3;
|
|
|
55
55
|
export declare function getToastTimeout(content: ToastContent): number | null;
|
|
56
56
|
/** Shows toasts in the closest `PanneauRoot`. */
|
|
57
57
|
export declare function useToast(): Toasts;
|
|
58
|
+
/**
|
|
59
|
+
* How far the toasts rise above an element: from its top to the bottom of the viewport, when it
|
|
60
|
+
* covers the bottom of the viewport, as a sticky footer does once the page scrolls. `0` when it
|
|
61
|
+
* shows higher, as the footer of a short form does, after its last field: toasts then stay at the
|
|
62
|
+
* bottom, rather than floating where nothing is.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getToastOffset(rect: Pick<DOMRect, 'top' | 'bottom' | 'height'>, viewport: number): number;
|
|
58
65
|
/**
|
|
59
66
|
* 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
|
|
61
|
-
*
|
|
67
|
+
* a form, while it is mounted and `active` and it covers the bottom of the viewport: the space it
|
|
68
|
+
* takes there becomes the `--panneau-bottom-offset` of the region. Measured again when the page
|
|
69
|
+
* scrolls or resizes. Toasts at the top ignore it.
|
|
62
70
|
*/
|
|
63
71
|
export declare function useToastOffset(ref: RefObject<HTMLElement | null>, active?: boolean): void;
|
|
64
72
|
export interface ToastProviderProps {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../../src/toast/Toast.tsx"],"names":[],"mappings":"AACA,OAAO,EAGH,KAAK,SAAS,EACd,KAAK,SAAS,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wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,MAAM,UAAO,GAAG,IAAI,CAuCtF;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"}
|
package/dist/toast/Toast.js
CHANGED
|
@@ -48,10 +48,22 @@ function useToast() {
|
|
|
48
48
|
if (toasts === null) throw new Error("useToast() must be used inside <PanneauRoot>.");
|
|
49
49
|
return toasts;
|
|
50
50
|
}
|
|
51
|
+
/** How far from the bottom of the viewport an element can end and still stick to it (the frame's gutter). */
|
|
52
|
+
var STUCK_SLACK = 32;
|
|
53
|
+
/**
|
|
54
|
+
* How far the toasts rise above an element: from its top to the bottom of the viewport, when it
|
|
55
|
+
* covers the bottom of the viewport, as a sticky footer does once the page scrolls. `0` when it
|
|
56
|
+
* shows higher, as the footer of a short form does, after its last field: toasts then stay at the
|
|
57
|
+
* bottom, rather than floating where nothing is.
|
|
58
|
+
*/
|
|
59
|
+
function getToastOffset(rect, viewport) {
|
|
60
|
+
return rect.height > 0 && rect.top < viewport && rect.bottom >= viewport - STUCK_SLACK ? Math.ceil(viewport - rect.top) : 0;
|
|
61
|
+
}
|
|
51
62
|
/**
|
|
52
63
|
* 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
|
|
54
|
-
*
|
|
64
|
+
* a form, while it is mounted and `active` and it covers the bottom of the viewport: the space it
|
|
65
|
+
* takes there becomes the `--panneau-bottom-offset` of the region. Measured again when the page
|
|
66
|
+
* scrolls or resizes. Toasts at the top ignore it.
|
|
55
67
|
*/
|
|
56
68
|
function useToastOffset(ref, t0) {
|
|
57
69
|
const $ = c(5);
|
|
@@ -64,12 +76,27 @@ function useToastOffset(ref, t0) {
|
|
|
64
76
|
const element = ref.current;
|
|
65
77
|
if (toasts === null || element === null || !active) return;
|
|
66
78
|
const id = {};
|
|
67
|
-
|
|
79
|
+
let frame = null;
|
|
80
|
+
const measure = () => {
|
|
81
|
+
frame = null;
|
|
82
|
+
toasts.setOffset(id, getToastOffset(element.getBoundingClientRect(), window.innerHeight));
|
|
83
|
+
};
|
|
84
|
+
const schedule = () => {
|
|
85
|
+
if (frame === null) frame = requestAnimationFrame(measure);
|
|
86
|
+
};
|
|
68
87
|
measure();
|
|
69
|
-
const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(
|
|
88
|
+
const observer = typeof ResizeObserver !== "undefined" ? new ResizeObserver(schedule) : null;
|
|
70
89
|
observer?.observe(element);
|
|
90
|
+
window.addEventListener("scroll", schedule, {
|
|
91
|
+
capture: true,
|
|
92
|
+
passive: true
|
|
93
|
+
});
|
|
94
|
+
window.addEventListener("resize", schedule, { passive: true });
|
|
71
95
|
return () => {
|
|
72
96
|
observer?.disconnect();
|
|
97
|
+
window.removeEventListener("scroll", schedule, { capture: true });
|
|
98
|
+
window.removeEventListener("resize", schedule);
|
|
99
|
+
if (frame !== null) cancelAnimationFrame(frame);
|
|
73
100
|
toasts.setOffset(id, null);
|
|
74
101
|
};
|
|
75
102
|
};
|
|
@@ -273,6 +300,6 @@ function _temp() {
|
|
|
273
300
|
return new UNSTABLE_ToastQueue({ maxVisibleToasts: 3 });
|
|
274
301
|
}
|
|
275
302
|
//#endregion
|
|
276
|
-
export { MAX_VISIBLE_TOASTS, ToastProvider, getToastTimeout, useToast, useToastOffset };
|
|
303
|
+
export { MAX_VISIBLE_TOASTS, ToastProvider, getToastOffset, getToastTimeout, useToast, useToastOffset };
|
|
277
304
|
|
|
278
305
|
//# sourceMappingURL=Toast.js.map
|
package/dist/toast/Toast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,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AAA,MAAA+B;EAAA/B,EAAA,MAAAoD;EAAApD,EAAA,MAAAL;EAAAK,EAAA,MAAA0D;CAAA,OAAAA,MAAA1D,EAAA;CAAA,OA7Df0D;AA6De;AA3EhB,SAAAnB,SAAA;CAAA,uBAUuE,IAAIrB,IAAI;AAAC;AAVhF,SAAAmB,QAAA;CAAA,OAQO,IAAI3G,oBAA6B,EAAAiI,kBAAAA,EAAuC,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","STUCK_SLACK","getToastOffset","rect","Pick","DOMRect","viewport","stuck","top","bottom","ceil","useToastOffset","ref","t0","$","_c","active","t1","t2","element","current","frame","measure","getBoundingClientRect","window","innerHeight","schedule","requestAnimationFrame","observer","ResizeObserver","observe","addEventListener","capture","passive","disconnect","removeEventListener","cancelAnimationFrame","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/** How far from the bottom of the viewport an element can end and still stick to it (the frame's gutter). */\nconst STUCK_SLACK = 32;\n\n/**\n * How far the toasts rise above an element: from its top to the bottom of the viewport, when it\n * covers the bottom of the viewport, as a sticky footer does once the page scrolls. `0` when it\n * shows higher, as the footer of a short form does, after its last field: toasts then stay at the\n * bottom, rather than floating where nothing is.\n */\nexport function getToastOffset(rect: Pick<DOMRect, 'top' | 'bottom' | 'height'>, viewport: number) {\n const stuck = rect.height > 0 && rect.top < viewport && rect.bottom >= viewport - STUCK_SLACK;\n return stuck ? Math.ceil(viewport - rect.top) : 0;\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` and it covers the bottom of the viewport: the space it\n * takes there becomes the `--panneau-bottom-offset` of the region. Measured again when the page\n * scrolls or resizes. 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 let frame: number | null = null;\n const measure = () => {\n frame = null;\n toasts.setOffset(\n id,\n getToastOffset(element.getBoundingClientRect(), window.innerHeight),\n );\n };\n // Once per frame, however many scroll events\n const schedule = () => {\n if (frame === null) {\n frame = requestAnimationFrame(measure);\n }\n };\n measure();\n const observer =\n typeof ResizeObserver !== 'undefined' ? new ResizeObserver(schedule) : null;\n observer?.observe(element);\n // Any scroll: the page may scroll in an element of the frame rather than the window\n window.addEventListener('scroll', schedule, { capture: true, passive: true });\n window.addEventListener('resize', schedule, { passive: true });\n return () => {\n observer?.disconnect();\n window.removeEventListener('scroll', schedule, { capture: true });\n window.removeEventListener('resize', schedule);\n if (frame !== null) {\n cancelAnimationFrame(frame);\n }\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,S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AA;EARW,CAAA;EA0DE7D,EAAA,MAAA0C;EAAA1C,EAAA,MAAAwB;EAAAxB,EAAA,MAAA4C;EAAA5C,EAAA,MAAAqD;EAAArD,EAAA,MAAAwD;EAAAxD,EAAA,MAAA4D;EAAA5D,EAAA,MAAA6D;EAAA7D,EAAA,MAAA8D;CAAA,OAAAA,MAAA9D,EAAA;CAAA,IAAAoE;CAAA,IAAApE,EAAA,QAAAyC,YAAAzC,EAAA,QAAA8D,OAAA9D,EAAA,QAAAf,QAAA;EA5DtBmF,MAAA,qBAAC,cAAD;GAAqBnF,OAAAA;GAArB,UAAA,CACKwD,UACDqB,GAFS;;EA6DE9D,EAAA,MAAAyC;EAAAzC,EAAA,MAAA8D;EAAA9D,EAAA,MAAAf;EAAAe,EAAA,MAAAoE;CAAA,OAAAA,MAAApE,EAAA;CAAA,OA7DfoE;AA6De;AA3EhB,SAAAnB,SAAA;CAAA,uBAUuE,IAAIrB,IAAI;AAAC;AAVhF,SAAAmB,QAAA;CAAA,OAQO,IAAI/H,oBAA6B,EAAAqJ,kBAAAA,EAAuC,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/ui",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.23",
|
|
4
4
|
"description": "Design tokens, themes and accessible primitives of Panneau, built on React Aria Components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"react-intl": "^12.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@panneau/intl": "5.0.0-alpha.
|
|
60
|
+
"@panneau/intl": "5.0.0-alpha.23",
|
|
61
61
|
"lucide-react": "^1.57.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@panneau/protocol": "5.0.0-alpha.
|
|
64
|
+
"@panneau/protocol": "5.0.0-alpha.23"
|
|
65
65
|
}
|
|
66
66
|
}
|