@zyncat/ui 0.8.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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/alert.css +132 -0
- package/dist/alert.d.ts +46 -0
- package/dist/alert.js +80 -0
- package/dist/alert.js.map +1 -0
- package/dist/avatar-group.d.ts +24 -0
- package/dist/avatar-group.js +23 -0
- package/dist/avatar-group.js.map +1 -0
- package/dist/avatar.css +200 -0
- package/dist/avatar.d.ts +35 -0
- package/dist/avatar.js +67 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.css +182 -0
- package/dist/badge.d.ts +34 -0
- package/dist/badge.js +4 -0
- package/dist/badge.js.map +1 -0
- package/dist/button.css +269 -0
- package/dist/button.d.ts +44 -0
- package/dist/button.js +4 -0
- package/dist/button.js.map +1 -0
- package/dist/checkbox.css +177 -0
- package/dist/checkbox.d.ts +35 -0
- package/dist/checkbox.js +5 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/chunk-2ERBBFZS.js +12 -0
- package/dist/chunk-2ERBBFZS.js.map +1 -0
- package/dist/chunk-2HORSLXJ.js +191 -0
- package/dist/chunk-2HORSLXJ.js.map +1 -0
- package/dist/chunk-36WVAQKL.js +40 -0
- package/dist/chunk-36WVAQKL.js.map +1 -0
- package/dist/chunk-3SBCBYB7.js +575 -0
- package/dist/chunk-3SBCBYB7.js.map +1 -0
- package/dist/chunk-4R2GQO43.js +125 -0
- package/dist/chunk-4R2GQO43.js.map +1 -0
- package/dist/chunk-64UU4LGU.js +258 -0
- package/dist/chunk-64UU4LGU.js.map +1 -0
- package/dist/chunk-7SZCJ7WI.js +35 -0
- package/dist/chunk-7SZCJ7WI.js.map +1 -0
- package/dist/chunk-BIDVNLJO.js +38 -0
- package/dist/chunk-BIDVNLJO.js.map +1 -0
- package/dist/chunk-CONSWNIV.js +17 -0
- package/dist/chunk-CONSWNIV.js.map +1 -0
- package/dist/chunk-EQ32F2QJ.js +75 -0
- package/dist/chunk-EQ32F2QJ.js.map +1 -0
- package/dist/chunk-GY7JOPUQ.js +111 -0
- package/dist/chunk-GY7JOPUQ.js.map +1 -0
- package/dist/chunk-I4XQ4PV2.js +30 -0
- package/dist/chunk-I4XQ4PV2.js.map +1 -0
- package/dist/chunk-JSKXZMLH.js +67 -0
- package/dist/chunk-JSKXZMLH.js.map +1 -0
- package/dist/chunk-L3Q3VDIW.js +295 -0
- package/dist/chunk-L3Q3VDIW.js.map +1 -0
- package/dist/chunk-LDC3RIYA.js +62 -0
- package/dist/chunk-LDC3RIYA.js.map +1 -0
- package/dist/chunk-MKIQFK7S.js +43 -0
- package/dist/chunk-MKIQFK7S.js.map +1 -0
- package/dist/chunk-MMRIQNEN.js +20 -0
- package/dist/chunk-MMRIQNEN.js.map +1 -0
- package/dist/chunk-MXOPCFWR.js +59 -0
- package/dist/chunk-MXOPCFWR.js.map +1 -0
- package/dist/chunk-NEF5XAHG.js +17 -0
- package/dist/chunk-NEF5XAHG.js.map +1 -0
- package/dist/chunk-NNXJCLTV.js +22 -0
- package/dist/chunk-NNXJCLTV.js.map +1 -0
- package/dist/chunk-O4N2OBTR.js +94 -0
- package/dist/chunk-O4N2OBTR.js.map +1 -0
- package/dist/chunk-PMECHR3A.js +38 -0
- package/dist/chunk-PMECHR3A.js.map +1 -0
- package/dist/chunk-QDK66S4G.js +44 -0
- package/dist/chunk-QDK66S4G.js.map +1 -0
- package/dist/chunk-QGNC7LH5.js +8 -0
- package/dist/chunk-QGNC7LH5.js.map +1 -0
- package/dist/chunk-QMSJZCK3.js +398 -0
- package/dist/chunk-QMSJZCK3.js.map +1 -0
- package/dist/chunk-S5ZTZANS.js +57 -0
- package/dist/chunk-S5ZTZANS.js.map +1 -0
- package/dist/chunk-S7B34VGN.js +14 -0
- package/dist/chunk-S7B34VGN.js.map +1 -0
- package/dist/chunk-TCUCYFT7.js +25 -0
- package/dist/chunk-TCUCYFT7.js.map +1 -0
- package/dist/chunk-TYHR4VNM.js +193 -0
- package/dist/chunk-TYHR4VNM.js.map +1 -0
- package/dist/chunk-U5QQZC3U.js +56 -0
- package/dist/chunk-U5QQZC3U.js.map +1 -0
- package/dist/chunk-UE63OOVG.js +13 -0
- package/dist/chunk-UE63OOVG.js.map +1 -0
- package/dist/chunk-VTJTGVZZ.js +22 -0
- package/dist/chunk-VTJTGVZZ.js.map +1 -0
- package/dist/chunk-W3SHPKSB.js +49 -0
- package/dist/chunk-W3SHPKSB.js.map +1 -0
- package/dist/chunk-XZAEIQDR.js +188 -0
- package/dist/chunk-XZAEIQDR.js.map +1 -0
- package/dist/chunk-YGGCQNNU.js +92 -0
- package/dist/chunk-YGGCQNNU.js.map +1 -0
- package/dist/collapse.css +88 -0
- package/dist/collapse.d.ts +46 -0
- package/dist/collapse.js +5 -0
- package/dist/collapse.js.map +1 -0
- package/dist/count-badge.d.ts +13 -0
- package/dist/count-badge.js +13 -0
- package/dist/count-badge.js.map +1 -0
- package/dist/date-field.d.ts +25 -0
- package/dist/date-field.js +87 -0
- package/dist/date-field.js.map +1 -0
- package/dist/date-picker.css +595 -0
- package/dist/date-range-field.d.ts +33 -0
- package/dist/date-range-field.js +404 -0
- package/dist/date-range-field.js.map +1 -0
- package/dist/datetime-field.d.ts +29 -0
- package/dist/datetime-field.js +155 -0
- package/dist/datetime-field.js.map +1 -0
- package/dist/dialog.css +180 -0
- package/dist/dialog.d.ts +42 -0
- package/dist/dialog.js +128 -0
- package/dist/dialog.js.map +1 -0
- package/dist/dom-props-C0jrllBw.d.ts +5 -0
- package/dist/field-chrome-CMPOQSLs.d.ts +28 -0
- package/dist/field-shell-Cuda-feL.d.ts +24 -0
- package/dist/glide.d.ts +15 -0
- package/dist/glide.js +5 -0
- package/dist/glide.js.map +1 -0
- package/dist/icon.css +33 -0
- package/dist/input.css +333 -0
- package/dist/mcp.js +359 -0
- package/dist/motion-devtools.css +265 -0
- package/dist/motion-devtools.d.ts +51 -0
- package/dist/motion-devtools.js +354 -0
- package/dist/motion-devtools.js.map +1 -0
- package/dist/motion-scale-Canq4stZ.d.ts +18 -0
- package/dist/motion-tokens.d.ts +28 -0
- package/dist/motion-tokens.js +3 -0
- package/dist/motion-tokens.js.map +1 -0
- package/dist/multi-select.d.ts +44 -0
- package/dist/multi-select.js +109 -0
- package/dist/multi-select.js.map +1 -0
- package/dist/number-field.d.ts +36 -0
- package/dist/number-field.js +112 -0
- package/dist/number-field.js.map +1 -0
- package/dist/odometer.css +62 -0
- package/dist/otp-field.d.ts +31 -0
- package/dist/otp-field.js +98 -0
- package/dist/otp-field.js.map +1 -0
- package/dist/overlay.css +23 -0
- package/dist/pagination.css +43 -0
- package/dist/pagination.d.ts +29 -0
- package/dist/pagination.js +107 -0
- package/dist/pagination.js.map +1 -0
- package/dist/popover.css +69 -0
- package/dist/popover.d.ts +35 -0
- package/dist/popover.js +15 -0
- package/dist/popover.js.map +1 -0
- package/dist/radio-group.css +300 -0
- package/dist/radio-group.d.ts +52 -0
- package/dist/radio-group.js +115 -0
- package/dist/radio-group.js.map +1 -0
- package/dist/select.css +416 -0
- package/dist/select.d.ts +49 -0
- package/dist/select.js +99 -0
- package/dist/select.js.map +1 -0
- package/dist/sheet.css +26 -0
- package/dist/sheet.d.ts +31 -0
- package/dist/sheet.js +14 -0
- package/dist/sheet.js.map +1 -0
- package/dist/status-badge.d.ts +19 -0
- package/dist/status-badge.js +72 -0
- package/dist/status-badge.js.map +1 -0
- package/dist/table.css +348 -0
- package/dist/table.d.ts +75 -0
- package/dist/table.js +262 -0
- package/dist/table.js.map +1 -0
- package/dist/tabs.css +208 -0
- package/dist/tabs.d.ts +71 -0
- package/dist/tabs.js +181 -0
- package/dist/tabs.js.map +1 -0
- package/dist/tag.css +248 -0
- package/dist/tag.d.ts +52 -0
- package/dist/tag.js +72 -0
- package/dist/tag.js.map +1 -0
- package/dist/text-field.d.ts +28 -0
- package/dist/text-field.js +69 -0
- package/dist/text-field.js.map +1 -0
- package/dist/textarea.css +219 -0
- package/dist/textarea.d.ts +38 -0
- package/dist/textarea.js +144 -0
- package/dist/textarea.js.map +1 -0
- package/dist/time-field.d.ts +28 -0
- package/dist/time-field.js +66 -0
- package/dist/time-field.js.map +1 -0
- package/dist/timing-7JA_zQHP.d.ts +27 -0
- package/dist/toast-store.d.ts +86 -0
- package/dist/toast-store.js +3 -0
- package/dist/toast-store.js.map +1 -0
- package/dist/toast.css +257 -0
- package/dist/toast.d.ts +12 -0
- package/dist/toast.js +310 -0
- package/dist/toast.js.map +1 -0
- package/dist/toggle-tag.d.ts +34 -0
- package/dist/toggle-tag.js +57 -0
- package/dist/toggle-tag.js.map +1 -0
- package/dist/toggle.css +152 -0
- package/dist/toggle.d.ts +31 -0
- package/dist/toggle.js +75 -0
- package/dist/toggle.js.map +1 -0
- package/dist/tooltip.css +86 -0
- package/dist/tooltip.d.ts +30 -0
- package/dist/tooltip.js +268 -0
- package/dist/tooltip.js.map +1 -0
- package/dist/types-SGMShK7R.d.ts +22 -0
- package/llms.txt +196 -0
- package/next.d.mts +7 -0
- package/next.mjs +59 -0
- package/package.json +257 -0
- package/src/components/composites/alert/Alert.tsx +141 -0
- package/src/components/composites/alert/alert.css +132 -0
- package/src/components/composites/date-picker/DateField.tsx +80 -0
- package/src/components/composites/date-picker/DateRangeField.tsx +110 -0
- package/src/components/composites/date-picker/DateTimeField.tsx +162 -0
- package/src/components/composites/date-picker/TimeField.tsx +78 -0
- package/src/components/composites/date-picker/calendar-panel.tsx +216 -0
- package/src/components/composites/date-picker/date-picker.css +595 -0
- package/src/components/composites/date-picker/date-utils.ts +56 -0
- package/src/components/composites/date-picker/field-shell.tsx +85 -0
- package/src/components/composites/date-picker/range-panel.tsx +363 -0
- package/src/components/composites/date-picker/time-core.tsx +290 -0
- package/src/components/composites/date-picker/use-day-focus.ts +35 -0
- package/src/components/composites/dialog/Dialog.tsx +198 -0
- package/src/components/composites/dialog/dialog.css +180 -0
- package/src/components/composites/pagination/Pagination.tsx +131 -0
- package/src/components/composites/pagination/pagination.css +43 -0
- package/src/components/composites/popover/Popover.tsx +141 -0
- package/src/components/composites/popover/popover.css +69 -0
- package/src/components/composites/select/MultiSelect.tsx +133 -0
- package/src/components/composites/select/Select.tsx +122 -0
- package/src/components/composites/select/core/index.ts +4 -0
- package/src/components/composites/select/core/menu.tsx +100 -0
- package/src/components/composites/select/core/panel.tsx +154 -0
- package/src/components/composites/select/core/trigger.tsx +74 -0
- package/src/components/composites/select/core/types.ts +39 -0
- package/src/components/composites/select/core/use-listbox.ts +182 -0
- package/src/components/composites/select/select.css +416 -0
- package/src/components/composites/sheet/Sheet.tsx +135 -0
- package/src/components/composites/sheet/sheet.css +26 -0
- package/src/components/composites/sheet/use-sheet-drag.ts +126 -0
- package/src/components/composites/table/Table.tsx +377 -0
- package/src/components/composites/table/table.css +348 -0
- package/src/components/composites/tabs/Tabs.tsx +278 -0
- package/src/components/composites/tabs/tabs.css +208 -0
- package/src/components/composites/toast/Toast.tsx +380 -0
- package/src/components/composites/toast/toast-store.ts +295 -0
- package/src/components/composites/toast/toast.css +257 -0
- package/src/components/composites/tooltip/Tooltip.tsx +110 -0
- package/src/components/composites/tooltip/tooltip-host.tsx +184 -0
- package/src/components/composites/tooltip/tooltip-store.ts +81 -0
- package/src/components/composites/tooltip/tooltip.css +86 -0
- package/src/components/dev/MotionDevtools.tsx +200 -0
- package/src/components/dev/motion-devtools.css +265 -0
- package/src/components/dev/slowmo-engine.ts +230 -0
- package/src/components/internal/glass/glass.css +100 -0
- package/src/components/internal/glass/glint.ts +9 -0
- package/src/components/internal/hooks/use-controllable.ts +21 -0
- package/src/components/internal/hooks/use-scroll-edges.ts +46 -0
- package/src/components/internal/icon/Icon.tsx +66 -0
- package/src/components/internal/icon/IconSlot.tsx +10 -0
- package/src/components/internal/icon/icon.css +33 -0
- package/src/components/internal/overlay/focus.ts +68 -0
- package/src/components/internal/overlay/layer.tsx +149 -0
- package/src/components/internal/overlay/modal.tsx +141 -0
- package/src/components/internal/overlay/overlay.css +23 -0
- package/src/components/internal/overlay/position.ts +103 -0
- package/src/components/internal/utils/cx.ts +3 -0
- package/src/components/internal/utils/token-px.ts +8 -0
- package/src/components/primitives/avatar/Avatar.tsx +120 -0
- package/src/components/primitives/avatar/AvatarGroup.tsx +56 -0
- package/src/components/primitives/avatar/avatar.css +200 -0
- package/src/components/primitives/badge/Badge.tsx +75 -0
- package/src/components/primitives/badge/CountBadge.tsx +20 -0
- package/src/components/primitives/badge/StatusBadge.tsx +111 -0
- package/src/components/primitives/badge/badge.css +182 -0
- package/src/components/primitives/badge/odometer.css +62 -0
- package/src/components/primitives/badge/odometer.tsx +36 -0
- package/src/components/primitives/button/Button.tsx +102 -0
- package/src/components/primitives/button/button.css +269 -0
- package/src/components/primitives/checkbox/Checkbox.tsx +76 -0
- package/src/components/primitives/checkbox/check-glyph.tsx +28 -0
- package/src/components/primitives/checkbox/checkbox.css +177 -0
- package/src/components/primitives/collapse/Collapse.tsx +86 -0
- package/src/components/primitives/collapse/collapse.css +88 -0
- package/src/components/primitives/collapse/collapse.typecheck.tsx +29 -0
- package/src/components/primitives/input/NumberField.tsx +139 -0
- package/src/components/primitives/input/OtpField.tsx +134 -0
- package/src/components/primitives/input/TextField.tsx +110 -0
- package/src/components/primitives/input/field-chrome.tsx +83 -0
- package/src/components/primitives/input/input.css +333 -0
- package/src/components/primitives/radio-group/RadioGroup.tsx +183 -0
- package/src/components/primitives/radio-group/radio-group.css +300 -0
- package/src/components/primitives/tag/Tag.tsx +143 -0
- package/src/components/primitives/tag/ToggleTag.tsx +97 -0
- package/src/components/primitives/tag/tag.css +248 -0
- package/src/components/primitives/textarea/Textarea.tsx +190 -0
- package/src/components/primitives/textarea/textarea.css +219 -0
- package/src/components/primitives/toggle/Toggle.tsx +105 -0
- package/src/components/primitives/toggle/toggle.css +152 -0
- package/src/css.d.ts +1 -0
- package/src/dom-props.ts +1 -0
- package/src/engine/animate.ts +141 -0
- package/src/engine/drag.ts +53 -0
- package/src/engine/ease.ts +155 -0
- package/src/engine/flip.ts +59 -0
- package/src/engine/index.ts +13 -0
- package/src/mcp/server.ts +420 -0
- package/src/motion/element.tsx +53 -0
- package/src/motion/flip.tsx +87 -0
- package/src/motion/glide.tsx +47 -0
- package/src/motion/motion-timing.ts +33 -0
- package/src/motion/presence-context.ts +18 -0
- package/src/motion/presence.tsx +91 -0
- package/src/motion/timing.ts +49 -0
- package/src/motion/use-motion.ts +64 -0
- package/src/styles.css +26 -0
- package/src/tokens/avatar.css +20 -0
- package/src/tokens/color.css +58 -0
- package/src/tokens/elevation.css +22 -0
- package/src/tokens/fonts.css +3 -0
- package/src/tokens/glass.css +20 -0
- package/src/tokens/icons.css +7 -0
- package/src/tokens/layers.css +6 -0
- package/src/tokens/motion-scale.ts +17 -0
- package/src/tokens/motion-tokens.ts +92 -0
- package/src/tokens/motion.css +49 -0
- package/src/tokens/radius.css +11 -0
- package/src/tokens/semantic.css +65 -0
- package/src/tokens/spacing.css +26 -0
- package/src/tokens/typography.css +52 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
type ToastTone = 'default' | 'success' | 'danger' | 'warning' | 'info' | 'loading' | 'custom';
|
|
2
|
+
interface ToastAction {
|
|
3
|
+
label: string;
|
|
4
|
+
onClick: () => void;
|
|
5
|
+
}
|
|
6
|
+
interface ToastOptions {
|
|
7
|
+
id?: string | number;
|
|
8
|
+
duration?: number;
|
|
9
|
+
description?: string | null;
|
|
10
|
+
action?: ToastAction | null;
|
|
11
|
+
}
|
|
12
|
+
interface ToastRecord {
|
|
13
|
+
id: string;
|
|
14
|
+
tone: ToastTone;
|
|
15
|
+
message: string | null;
|
|
16
|
+
description: string | null;
|
|
17
|
+
action: ToastAction | null;
|
|
18
|
+
duration: number;
|
|
19
|
+
remaining: number;
|
|
20
|
+
count: number;
|
|
21
|
+
timerKey: number;
|
|
22
|
+
node: unknown;
|
|
23
|
+
dismissible: boolean;
|
|
24
|
+
expiresAt?: number;
|
|
25
|
+
}
|
|
26
|
+
interface ToastSnapshot {
|
|
27
|
+
toasts: ToastRecord[];
|
|
28
|
+
paused: boolean;
|
|
29
|
+
expanded: boolean;
|
|
30
|
+
}
|
|
31
|
+
type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
32
|
+
interface ToasterConfig {
|
|
33
|
+
position: ToastPosition;
|
|
34
|
+
duration: number;
|
|
35
|
+
visibleToasts: number;
|
|
36
|
+
gap: number;
|
|
37
|
+
offset: number;
|
|
38
|
+
expand: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare const DEFAULT_TOASTER_CONFIG: ToasterConfig;
|
|
41
|
+
interface ToastStore {
|
|
42
|
+
toasts: ToastRecord[];
|
|
43
|
+
paused: boolean;
|
|
44
|
+
expanded: boolean;
|
|
45
|
+
mounted: boolean;
|
|
46
|
+
config: ToasterConfig;
|
|
47
|
+
snap: ToastSnapshot;
|
|
48
|
+
listeners: Set<() => void>;
|
|
49
|
+
subscribe(l: () => void): () => void;
|
|
50
|
+
get(): ToastSnapshot;
|
|
51
|
+
emit(): void;
|
|
52
|
+
add(t: ToastRecord): string;
|
|
53
|
+
update(id: string, patch: Partial<ToastRecord>): string;
|
|
54
|
+
dismiss(id?: string | null): void;
|
|
55
|
+
schedule(t: ToastRecord): void;
|
|
56
|
+
pause(): void;
|
|
57
|
+
resume(): void;
|
|
58
|
+
setExpanded(v: boolean): void;
|
|
59
|
+
}
|
|
60
|
+
type PromiseMsg<V> = string | ((v: V) => string);
|
|
61
|
+
interface ToastPromiseMsgs<T> {
|
|
62
|
+
loading?: string;
|
|
63
|
+
success?: PromiseMsg<T>;
|
|
64
|
+
error?: PromiseMsg<unknown>;
|
|
65
|
+
}
|
|
66
|
+
interface ToastApi {
|
|
67
|
+
(message: string, opts?: ToastOptions): string;
|
|
68
|
+
success(m: string, o?: ToastOptions): string;
|
|
69
|
+
error(m: string, o?: ToastOptions): string;
|
|
70
|
+
warning(m: string, o?: ToastOptions): string;
|
|
71
|
+
info(m: string, o?: ToastOptions): string;
|
|
72
|
+
loading(m: string, o?: ToastOptions): string;
|
|
73
|
+
dismiss(id?: string | null): void;
|
|
74
|
+
update(id: string, patch?: Partial<ToastRecord>): string;
|
|
75
|
+
promise<T>(promise: Promise<T>, msgs?: ToastPromiseMsgs<T>): Promise<T>;
|
|
76
|
+
custom(node: unknown, opts?: {
|
|
77
|
+
id?: string | number;
|
|
78
|
+
duration?: number;
|
|
79
|
+
dismissible?: boolean;
|
|
80
|
+
}): string;
|
|
81
|
+
}
|
|
82
|
+
declare const toast: ToastApi;
|
|
83
|
+
|
|
84
|
+
declare const UIToast: ToastStore;
|
|
85
|
+
|
|
86
|
+
export { DEFAULT_TOASTER_CONFIG, type ToastAction, type ToastApi, type ToastOptions, type ToastPosition, type ToastPromiseMsgs, type ToastRecord, type ToastSnapshot, type ToastTone, type ToasterConfig, UIToast, toast };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"toast-store.js"}
|
package/dist/toast.css
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/* toast.css - the glass notification card, tinted per tone (a draining timer ring). */
|
|
2
|
+
|
|
3
|
+
.toast-viewport {
|
|
4
|
+
position: fixed;
|
|
5
|
+
width: min(22.5rem, calc(100vw - 2 * var(--toast-offset, var(--space-6))));
|
|
6
|
+
z-index: var(--layer-toast);
|
|
7
|
+
margin: 0;
|
|
8
|
+
padding: 0;
|
|
9
|
+
list-style: none;
|
|
10
|
+
pointer-events: none; /* only the cards themselves are live */
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* Anchored by [data-position]; --toast-offset (set by <Toaster offset>) overrides the edge inset. */
|
|
14
|
+
.toast-viewport[data-position^='top'] {
|
|
15
|
+
top: var(--toast-offset, var(--space-6));
|
|
16
|
+
}
|
|
17
|
+
.toast-viewport[data-position^='bottom'] {
|
|
18
|
+
bottom: var(--toast-offset, var(--space-6));
|
|
19
|
+
}
|
|
20
|
+
.toast-viewport[data-position$='right'] {
|
|
21
|
+
right: var(--toast-offset, var(--space-6));
|
|
22
|
+
}
|
|
23
|
+
.toast-viewport[data-position$='left'] {
|
|
24
|
+
left: var(--toast-offset, var(--space-6));
|
|
25
|
+
}
|
|
26
|
+
.toast-viewport[data-position$='center'] {
|
|
27
|
+
left: 50%;
|
|
28
|
+
transform: translateX(-50%);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* The card - a glass consumer (.glass is set in JSX). */
|
|
32
|
+
.toast {
|
|
33
|
+
/* tone hooks - set by [data-tone] below */
|
|
34
|
+
--toast-hue: var(--text-subtle);
|
|
35
|
+
--glass-fg: var(--text-strong);
|
|
36
|
+
--glass-tint: color-mix(in oklab, var(--glass-tint-neutral) 75%, transparent);
|
|
37
|
+
--glass-sheen-rest: 0.45;
|
|
38
|
+
|
|
39
|
+
position: absolute;
|
|
40
|
+
left: 0;
|
|
41
|
+
width: 100%;
|
|
42
|
+
box-sizing: border-box;
|
|
43
|
+
overflow: hidden; /* custom content stays in the pane */
|
|
44
|
+
pointer-events: auto;
|
|
45
|
+
border-radius: var(--radius-lg);
|
|
46
|
+
|
|
47
|
+
/* Motion owns transform - keep only the color/shadow transitions (never smooth Motion's writes) */
|
|
48
|
+
transition:
|
|
49
|
+
background-color var(--duration-base) var(--ease-standard),
|
|
50
|
+
box-shadow var(--duration-base) var(--ease-standard);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Cards pin to the stack's edge; Motion offsets each one away from it (up from bottom, down from top). */
|
|
54
|
+
.toast-viewport[data-position^='bottom'] .toast {
|
|
55
|
+
bottom: 0;
|
|
56
|
+
transform-origin: center bottom;
|
|
57
|
+
}
|
|
58
|
+
.toast-viewport[data-position^='top'] .toast {
|
|
59
|
+
top: 0;
|
|
60
|
+
transform-origin: center top;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* rich panes for genuine status, diluted to stay glass; neutral otherwise */
|
|
64
|
+
.toast[data-tone='success'] {
|
|
65
|
+
--toast-hue: var(--success);
|
|
66
|
+
--glass-fg: var(--success-text);
|
|
67
|
+
--glass-tint: color-mix(in oklab, var(--glass-tint-success) 70%, transparent);
|
|
68
|
+
}
|
|
69
|
+
.toast[data-tone='danger'] {
|
|
70
|
+
--toast-hue: var(--danger);
|
|
71
|
+
--glass-fg: var(--danger-text);
|
|
72
|
+
--glass-tint: color-mix(in oklab, var(--glass-tint-danger) 70%, transparent);
|
|
73
|
+
}
|
|
74
|
+
.toast[data-tone='warning'] {
|
|
75
|
+
--toast-hue: var(--warning);
|
|
76
|
+
--glass-fg: var(--warning-text);
|
|
77
|
+
--glass-tint: color-mix(in oklab, var(--glass-tint-warning) 70%, transparent);
|
|
78
|
+
}
|
|
79
|
+
.toast[data-tone='info'] {
|
|
80
|
+
--toast-hue: var(--info);
|
|
81
|
+
--glass-fg: var(--info-text);
|
|
82
|
+
--glass-tint: color-mix(in oklab, var(--glass-tint-info) 70%, transparent);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* receding cards fall quiet: tone drains out, sheen dims, content fades */
|
|
86
|
+
.toast[data-behind] {
|
|
87
|
+
--glass-tint: color-mix(in oklab, var(--glass-tint-neutral) 75%, transparent);
|
|
88
|
+
--glass-sheen-rest: 0.3;
|
|
89
|
+
}
|
|
90
|
+
.toast[data-behind] .toast__inner,
|
|
91
|
+
.toast[data-behind] .toast__custom {
|
|
92
|
+
opacity: 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.toast__inner {
|
|
96
|
+
display: flex;
|
|
97
|
+
align-items: center;
|
|
98
|
+
gap: var(--space-3);
|
|
99
|
+
padding: var(--space-3) var(--space-4);
|
|
100
|
+
transition: var(--transition-opacity);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* the dial - glyph centered in the timer ring; one instrument, not two */
|
|
104
|
+
.toast__icon {
|
|
105
|
+
position: relative;
|
|
106
|
+
flex: none;
|
|
107
|
+
display: grid;
|
|
108
|
+
place-items: center;
|
|
109
|
+
width: calc(var(--icon-md) + 2 * var(--space-2));
|
|
110
|
+
height: calc(var(--icon-md) + 2 * var(--space-2));
|
|
111
|
+
color: var(--toast-hue);
|
|
112
|
+
}
|
|
113
|
+
.toast__icon-glyph {
|
|
114
|
+
display: grid;
|
|
115
|
+
place-items: center;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* the ring - a draining arc; linear by design, animation-duration set at runtime to the toast's lifetime */
|
|
119
|
+
.toast__ring {
|
|
120
|
+
position: absolute;
|
|
121
|
+
inset: 0;
|
|
122
|
+
width: 100%;
|
|
123
|
+
height: 100%;
|
|
124
|
+
transform: rotate(-90deg); /* arc starts at 12 o'clock */
|
|
125
|
+
pointer-events: none;
|
|
126
|
+
}
|
|
127
|
+
.toast__ring circle {
|
|
128
|
+
fill: none;
|
|
129
|
+
stroke-width: var(--border-emphasis);
|
|
130
|
+
}
|
|
131
|
+
.toast__ring-track {
|
|
132
|
+
stroke: color-mix(in oklab, var(--toast-hue) 16%, transparent);
|
|
133
|
+
}
|
|
134
|
+
.toast__ring-arc {
|
|
135
|
+
stroke: var(--toast-hue);
|
|
136
|
+
stroke-linecap: round;
|
|
137
|
+
stroke-dasharray: 1; /* pathLength=1 - offset is a fraction */
|
|
138
|
+
animation-name: toast-ring;
|
|
139
|
+
animation-timing-function: linear;
|
|
140
|
+
animation-fill-mode: both;
|
|
141
|
+
}
|
|
142
|
+
.toast-viewport.is-paused .toast__ring-arc {
|
|
143
|
+
animation-play-state: paused;
|
|
144
|
+
}
|
|
145
|
+
@keyframes toast-ring {
|
|
146
|
+
from {
|
|
147
|
+
stroke-dashoffset: 0;
|
|
148
|
+
}
|
|
149
|
+
to {
|
|
150
|
+
stroke-dashoffset: 1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.toast__text {
|
|
155
|
+
flex: 1 1 auto;
|
|
156
|
+
min-width: 0;
|
|
157
|
+
}
|
|
158
|
+
.toast__message {
|
|
159
|
+
margin: 0;
|
|
160
|
+
font: var(--type-label);
|
|
161
|
+
color: var(--glass-fg);
|
|
162
|
+
text-wrap: pretty;
|
|
163
|
+
}
|
|
164
|
+
.toast__desc {
|
|
165
|
+
margin: var(--space-1) 0 0;
|
|
166
|
+
font: var(--type-caption);
|
|
167
|
+
color: color-mix(in oklab, var(--glass-fg) 76%, transparent);
|
|
168
|
+
text-wrap: pretty;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* coalesce counter - same toast refired becomes a xN counter (mono) */
|
|
172
|
+
.toast__count {
|
|
173
|
+
flex: none;
|
|
174
|
+
font-family: var(--font-mono);
|
|
175
|
+
font-size: var(--size-micro);
|
|
176
|
+
line-height: var(--leading-micro);
|
|
177
|
+
font-variant-numeric: tabular-nums;
|
|
178
|
+
color: var(--glass-fg);
|
|
179
|
+
background: color-mix(in oklab, var(--glass-fg) 9%, transparent);
|
|
180
|
+
border-radius: var(--radius-sm);
|
|
181
|
+
padding: 0 var(--space-1);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.toast__action {
|
|
185
|
+
flex: none;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* dismiss - appears only while the card is hovered or holds focus */
|
|
189
|
+
.toast__close {
|
|
190
|
+
flex: none;
|
|
191
|
+
appearance: none;
|
|
192
|
+
display: grid;
|
|
193
|
+
place-items: center;
|
|
194
|
+
width: var(--space-6);
|
|
195
|
+
height: var(--space-6);
|
|
196
|
+
margin: 0;
|
|
197
|
+
padding: 0;
|
|
198
|
+
border: none;
|
|
199
|
+
border-radius: var(--radius-sm);
|
|
200
|
+
background: transparent;
|
|
201
|
+
color: color-mix(in oklab, var(--glass-fg) 64%, transparent);
|
|
202
|
+
cursor: pointer;
|
|
203
|
+
opacity: 0;
|
|
204
|
+
transition:
|
|
205
|
+
var(--transition-control),
|
|
206
|
+
opacity var(--duration-fast) var(--ease-standard);
|
|
207
|
+
}
|
|
208
|
+
.toast:hover .toast__close,
|
|
209
|
+
.toast:focus-within .toast__close {
|
|
210
|
+
opacity: 1;
|
|
211
|
+
}
|
|
212
|
+
.toast__close:hover {
|
|
213
|
+
background: color-mix(in oklab, var(--glass-fg) 9%, transparent);
|
|
214
|
+
color: var(--glass-fg);
|
|
215
|
+
}
|
|
216
|
+
.toast__close:active {
|
|
217
|
+
background: color-mix(in oklab, var(--glass-fg) 14%, transparent);
|
|
218
|
+
}
|
|
219
|
+
.toast__close:focus-visible {
|
|
220
|
+
outline: none;
|
|
221
|
+
box-shadow: var(--focus-ring);
|
|
222
|
+
opacity: 1;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* Loading spinner - continuous --duration-spin (linear is allowed for loops; reduced motion slows, never freezes) */
|
|
226
|
+
.toast__spinner {
|
|
227
|
+
display: block;
|
|
228
|
+
box-sizing: border-box;
|
|
229
|
+
width: var(--icon-sm);
|
|
230
|
+
height: var(--icon-sm);
|
|
231
|
+
border-radius: var(--radius-full);
|
|
232
|
+
border: var(--border-emphasis) solid currentColor;
|
|
233
|
+
border-right-color: transparent;
|
|
234
|
+
color: var(--text-muted);
|
|
235
|
+
animation: toast-spin var(--duration-spin) linear infinite;
|
|
236
|
+
}
|
|
237
|
+
@keyframes toast-spin {
|
|
238
|
+
to {
|
|
239
|
+
transform: rotate(1turn);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* Custom slot - bare neutral glass; the consumer owns the interior. */
|
|
244
|
+
.toast__custom {
|
|
245
|
+
padding: var(--space-3) var(--space-4);
|
|
246
|
+
transition: var(--transition-opacity);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
@media (prefers-reduced-motion: reduce) {
|
|
250
|
+
/* travel/gestures collapse via the tokens; the ring is data, so it keeps running */
|
|
251
|
+
.toast,
|
|
252
|
+
.toast__close,
|
|
253
|
+
.toast__inner,
|
|
254
|
+
.toast__custom {
|
|
255
|
+
transition: none;
|
|
256
|
+
}
|
|
257
|
+
}
|
package/dist/toast.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactElement } from 'react';
|
|
2
|
+
import { ToasterConfig } from './toast-store.js';
|
|
3
|
+
export { toast } from './toast-store.js';
|
|
4
|
+
import { D as DataAttributes } from './dom-props-C0jrllBw.js';
|
|
5
|
+
|
|
6
|
+
interface ToasterProps extends Partial<ToasterConfig> {
|
|
7
|
+
/** Standard <ol> attributes (className, style, data-*, ...) forwarded to the toast viewport. */
|
|
8
|
+
htmlProps?: HTMLAttributes<HTMLOListElement> & DataAttributes;
|
|
9
|
+
}
|
|
10
|
+
declare function Toaster({ htmlProps, ...props }: ToasterProps): ReactElement;
|
|
11
|
+
|
|
12
|
+
export { Toaster, type ToasterProps };
|
package/dist/toast.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
'use client';import { DEFAULT_TOASTER_CONFIG, UIToast } from './chunk-TYHR4VNM.js';
|
|
2
|
+
export { toast } from './chunk-TYHR4VNM.js';
|
|
3
|
+
import { tokenPx } from './chunk-UE63OOVG.js';
|
|
4
|
+
import { Motion } from './chunk-36WVAQKL.js';
|
|
5
|
+
import { Presence } from './chunk-MXOPCFWR.js';
|
|
6
|
+
import './chunk-W3SHPKSB.js';
|
|
7
|
+
import './chunk-JSKXZMLH.js';
|
|
8
|
+
import { animate, startDrag } from './chunk-L3Q3VDIW.js';
|
|
9
|
+
import { Icon } from './chunk-3SBCBYB7.js';
|
|
10
|
+
import { fireGlint } from './chunk-S7B34VGN.js';
|
|
11
|
+
import { UIMotion } from './chunk-S5ZTZANS.js';
|
|
12
|
+
import { Button } from './chunk-U5QQZC3U.js';
|
|
13
|
+
import { cx } from './chunk-QGNC7LH5.js';
|
|
14
|
+
import './toast.css';
|
|
15
|
+
import { useEffect, useSyncExternalStore, useState, useRef, useLayoutEffect } from 'react';
|
|
16
|
+
import { createPortal } from 'react-dom';
|
|
17
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
18
|
+
|
|
19
|
+
var SM = UIMotion;
|
|
20
|
+
var store = UIToast;
|
|
21
|
+
var COLLAPSE_GRACE = 140;
|
|
22
|
+
var SWIPE_X = 64;
|
|
23
|
+
var SWIPE_V = 480;
|
|
24
|
+
var GAP = 0;
|
|
25
|
+
function stackGap() {
|
|
26
|
+
if (!GAP) GAP = tokenPx("--space-3") || 12;
|
|
27
|
+
return GAP;
|
|
28
|
+
}
|
|
29
|
+
var TONE_ICON = {
|
|
30
|
+
success: "check-circle",
|
|
31
|
+
danger: "warning-circle",
|
|
32
|
+
warning: "warning",
|
|
33
|
+
info: "info"
|
|
34
|
+
};
|
|
35
|
+
function useToneGesture(tone, ref) {
|
|
36
|
+
const prevTone = useRef(null);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const prev = prevTone.current;
|
|
39
|
+
prevTone.current = tone;
|
|
40
|
+
if (tone === prev) return;
|
|
41
|
+
if (tone === "success") return fireGlint(ref.current);
|
|
42
|
+
if (tone === "danger" && ref.current) {
|
|
43
|
+
const shake = ref.current.firstElementChild;
|
|
44
|
+
if (!shake) return;
|
|
45
|
+
const fall = animate(shake, {
|
|
46
|
+
x: [0, -7, 5, -2, 0],
|
|
47
|
+
timing: { duration: SM.dur.slow, ease: SM.ease.standard, delay: SM.dur.base }
|
|
48
|
+
});
|
|
49
|
+
fall.finished.then(() => fall.stop());
|
|
50
|
+
return () => fall.stop();
|
|
51
|
+
}
|
|
52
|
+
}, [tone]);
|
|
53
|
+
}
|
|
54
|
+
function useReplay(token, build) {
|
|
55
|
+
const ref = useRef(null);
|
|
56
|
+
const latest = useRef(build);
|
|
57
|
+
latest.current = build;
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
if (ref.current) animate(ref.current, ...latest.current());
|
|
60
|
+
}, [token]);
|
|
61
|
+
return ref;
|
|
62
|
+
}
|
|
63
|
+
function ToastItem({
|
|
64
|
+
t,
|
|
65
|
+
depth,
|
|
66
|
+
offset,
|
|
67
|
+
hidden,
|
|
68
|
+
behind,
|
|
69
|
+
frameHeight,
|
|
70
|
+
isTop,
|
|
71
|
+
onHeight
|
|
72
|
+
}) {
|
|
73
|
+
const ref = useRef(null);
|
|
74
|
+
const settled = useRef(false);
|
|
75
|
+
const swipeBack = useRef(null);
|
|
76
|
+
useToneGesture(t.tone, ref);
|
|
77
|
+
useLayoutEffect(() => {
|
|
78
|
+
if (ref.current && ref.current.firstElementChild)
|
|
79
|
+
onHeight(t.id, ref.current.firstElementChild.offsetHeight);
|
|
80
|
+
});
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
const el = ref.current;
|
|
83
|
+
if (!el) return;
|
|
84
|
+
el.style.pointerEvents = hidden ? "none" : "auto";
|
|
85
|
+
const y = isTop ? offset : -offset;
|
|
86
|
+
const scale = 1 - depth * 0.05;
|
|
87
|
+
if (settled.current) {
|
|
88
|
+
animate(
|
|
89
|
+
el,
|
|
90
|
+
{ y: [y], scale: [scale], height: [frameHeight ?? "auto"], timing: SM.t.settle },
|
|
91
|
+
{ opacity: [hidden ? 0 : 1], timing: SM.t.enter }
|
|
92
|
+
);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
settled.current = true;
|
|
96
|
+
animate(
|
|
97
|
+
el,
|
|
98
|
+
{ y: [isTop ? -24 : 24, y], scale: [0.97, scale], timing: SM.t.settle },
|
|
99
|
+
{ opacity: [0, hidden ? 0 : 1], timing: SM.t.enter }
|
|
100
|
+
);
|
|
101
|
+
}, [offset, depth, hidden, frameHeight, isTop]);
|
|
102
|
+
const onPointerDown = (e) => {
|
|
103
|
+
const inner = ref.current?.firstElementChild;
|
|
104
|
+
if (!t.dismissible || e.button !== 0 || !inner) return;
|
|
105
|
+
swipeBack.current?.stop();
|
|
106
|
+
startDrag(e, {
|
|
107
|
+
onMove: (info) => {
|
|
108
|
+
const dx = info.offset.x;
|
|
109
|
+
inner.style.translate = `${dx > 0 ? dx * 0.9 : dx * 0.04}px 0px`;
|
|
110
|
+
},
|
|
111
|
+
onEnd: (info) => {
|
|
112
|
+
if (info.offset.x > SWIPE_X || info.velocity.x > SWIPE_V) {
|
|
113
|
+
animate(inner, { x: [420], timing: SM.t.exit }).finished.then(() => store.dismiss(t.id));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const back = animate(inner, { x: [0], timing: SM.t.settle });
|
|
117
|
+
swipeBack.current = back;
|
|
118
|
+
back.finished.then(() => back.stop());
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
return /* @__PURE__ */ jsx(
|
|
123
|
+
Motion,
|
|
124
|
+
{
|
|
125
|
+
as: "li",
|
|
126
|
+
ref,
|
|
127
|
+
exit: { opacity: [0], scale: [0.96], timing: SM.t.exit },
|
|
128
|
+
className: "toast glass",
|
|
129
|
+
"data-tone": t.tone,
|
|
130
|
+
"data-behind": behind ? "" : void 0,
|
|
131
|
+
role: t.tone === "danger" ? "alert" : "status",
|
|
132
|
+
"aria-atomic": "true",
|
|
133
|
+
onPointerDown,
|
|
134
|
+
onKeyDown: (e) => {
|
|
135
|
+
if (e.key === "Escape" && t.dismissible) store.dismiss(t.id);
|
|
136
|
+
},
|
|
137
|
+
children: t.node ? /* @__PURE__ */ jsx("div", { className: "toast__custom", children: t.node }) : /* @__PURE__ */ jsx(ToastBody, { t })
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function ToastBody({ t }) {
|
|
142
|
+
const glyphRef = useReplay(t.tone, () => [
|
|
143
|
+
{ scale: [0.5, 1], timing: SM.t.settle },
|
|
144
|
+
{ opacity: [0, 1], timing: SM.t.enter }
|
|
145
|
+
]);
|
|
146
|
+
const textRef = useReplay(String(t.message) + "-" + String(t.description), () => [
|
|
147
|
+
{ opacity: [0, 1], timing: SM.t.enter }
|
|
148
|
+
]);
|
|
149
|
+
const countRef = useReplay(t.count, () => [{ scale: [0.6, 1], timing: SM.t.settle }]);
|
|
150
|
+
return /* @__PURE__ */ jsxs("div", { className: "toast__inner", children: [
|
|
151
|
+
(t.tone !== "default" || isFinite(t.duration)) && /* @__PURE__ */ jsxs("span", { className: "toast__icon", children: [
|
|
152
|
+
t.tone !== "default" && /* @__PURE__ */ jsx("span", { ref: glyphRef, className: "toast__icon-glyph", children: t.tone === "loading" ? /* @__PURE__ */ jsx("span", { className: "toast__spinner", "aria-hidden": "true" }) : /* @__PURE__ */ jsx(Icon, { name: TONE_ICON[t.tone] || "info", weight: "fill" }) }),
|
|
153
|
+
isFinite(t.duration) && /* @__PURE__ */ jsxs("svg", { className: "toast__ring", viewBox: "0 0 36 36", "aria-hidden": "true", children: [
|
|
154
|
+
/* @__PURE__ */ jsx("circle", { className: "toast__ring-track", cx: "18", cy: "18", r: "16.5" }),
|
|
155
|
+
/* @__PURE__ */ jsx(
|
|
156
|
+
"circle",
|
|
157
|
+
{
|
|
158
|
+
className: "toast__ring-arc",
|
|
159
|
+
cx: "18",
|
|
160
|
+
cy: "18",
|
|
161
|
+
r: "16.5",
|
|
162
|
+
pathLength: 1,
|
|
163
|
+
style: { animationDuration: t.duration + "ms" }
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
] }, "ring-" + t.timerKey)
|
|
167
|
+
] }),
|
|
168
|
+
/* @__PURE__ */ jsxs("div", { ref: textRef, className: "toast__text", children: [
|
|
169
|
+
/* @__PURE__ */ jsx("p", { className: "toast__message", children: t.message }),
|
|
170
|
+
t.description != null && /* @__PURE__ */ jsx("p", { className: "toast__desc", children: t.description })
|
|
171
|
+
] }),
|
|
172
|
+
t.count > 1 && /* @__PURE__ */ jsxs("span", { ref: countRef, className: "toast__count", children: [
|
|
173
|
+
"\xD7",
|
|
174
|
+
t.count
|
|
175
|
+
] }),
|
|
176
|
+
t.action && /* @__PURE__ */ jsx(
|
|
177
|
+
Button,
|
|
178
|
+
{
|
|
179
|
+
variant: "secondary",
|
|
180
|
+
size: "sm",
|
|
181
|
+
className: "toast__action",
|
|
182
|
+
onClick: () => {
|
|
183
|
+
if (t.action.onClick) t.action.onClick();
|
|
184
|
+
store.dismiss(t.id);
|
|
185
|
+
},
|
|
186
|
+
children: t.action.label
|
|
187
|
+
}
|
|
188
|
+
),
|
|
189
|
+
t.dismissible && /* @__PURE__ */ jsx("button", { type: "button", className: "toast__close", "aria-label": "Dismiss", onClick: () => store.dismiss(t.id), children: /* @__PURE__ */ jsx(Icon, { name: "close", size: "sm" }) })
|
|
190
|
+
] });
|
|
191
|
+
}
|
|
192
|
+
function ToastHost({ config, htmlProps }) {
|
|
193
|
+
const { toasts, paused, expanded: hoverExpanded } = useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
194
|
+
const [heights, setHeights] = useState({});
|
|
195
|
+
const [ready, setReady] = useState(false);
|
|
196
|
+
const collapseTimer = useRef(0);
|
|
197
|
+
const hovering = useRef(false);
|
|
198
|
+
useEffect(() => setReady(true), []);
|
|
199
|
+
const onHeight = (id, h) => setHeights((prev) => prev[id] === h ? prev : { ...prev, [id]: h });
|
|
200
|
+
const onHold = () => {
|
|
201
|
+
hovering.current = true;
|
|
202
|
+
clearTimeout(collapseTimer.current);
|
|
203
|
+
store.setExpanded(true);
|
|
204
|
+
store.pause();
|
|
205
|
+
};
|
|
206
|
+
const onRelease = (graced) => {
|
|
207
|
+
hovering.current = false;
|
|
208
|
+
clearTimeout(collapseTimer.current);
|
|
209
|
+
collapseTimer.current = setTimeout(
|
|
210
|
+
() => {
|
|
211
|
+
store.setExpanded(false);
|
|
212
|
+
store.resume();
|
|
213
|
+
},
|
|
214
|
+
graced ? COLLAPSE_GRACE : 0
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
const onVis = () => {
|
|
219
|
+
if (document.hidden) store.pause();
|
|
220
|
+
else if (!hovering.current) store.resume();
|
|
221
|
+
};
|
|
222
|
+
document.addEventListener("visibilitychange", onVis);
|
|
223
|
+
return () => document.removeEventListener("visibilitychange", onVis);
|
|
224
|
+
}, []);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (toasts.length === 0) {
|
|
227
|
+
hovering.current = false;
|
|
228
|
+
clearTimeout(collapseTimer.current);
|
|
229
|
+
store.setExpanded(false);
|
|
230
|
+
store.resume();
|
|
231
|
+
}
|
|
232
|
+
}, [toasts.length]);
|
|
233
|
+
if (!ready) return null;
|
|
234
|
+
const isTop = config.position.startsWith("top");
|
|
235
|
+
const visible = config.visibleToasts;
|
|
236
|
+
const rendered = visible * 2;
|
|
237
|
+
const gap = config.gap || stackGap();
|
|
238
|
+
const expanded = config.expand || hoverExpanded;
|
|
239
|
+
const slice = toasts.slice(-rendered);
|
|
240
|
+
const n = slice.length;
|
|
241
|
+
const frontH = n ? heights[slice[n - 1].id] || 0 : 0;
|
|
242
|
+
return createPortal(
|
|
243
|
+
/* @__PURE__ */ jsx(
|
|
244
|
+
"ol",
|
|
245
|
+
{
|
|
246
|
+
...htmlProps,
|
|
247
|
+
className: cx("toast-viewport", paused && "is-paused", htmlProps?.className),
|
|
248
|
+
"data-position": config.position,
|
|
249
|
+
style: config.offset ? { ...htmlProps?.style, "--toast-offset": `${config.offset}px` } : htmlProps?.style,
|
|
250
|
+
"aria-label": "Notifications",
|
|
251
|
+
onPointerOver: (e) => {
|
|
252
|
+
if (e.pointerType !== "touch") onHold();
|
|
253
|
+
},
|
|
254
|
+
onPointerOut: (e) => {
|
|
255
|
+
if (!e.relatedTarget || !e.currentTarget.contains(e.relatedTarget)) onRelease(true);
|
|
256
|
+
},
|
|
257
|
+
onFocus: onHold,
|
|
258
|
+
onBlur: (e) => {
|
|
259
|
+
if (!e.relatedTarget || !e.currentTarget.contains(e.relatedTarget)) onRelease(false);
|
|
260
|
+
},
|
|
261
|
+
children: /* @__PURE__ */ jsx(Presence, { children: slice.map((t, i) => {
|
|
262
|
+
const depth = n - 1 - i;
|
|
263
|
+
let offset = depth * gap;
|
|
264
|
+
if (expanded) {
|
|
265
|
+
offset = 0;
|
|
266
|
+
for (let j = i + 1; j < n; j++) offset += (heights[slice[j].id] || 0) + gap;
|
|
267
|
+
}
|
|
268
|
+
return /* @__PURE__ */ jsx(
|
|
269
|
+
ToastItem,
|
|
270
|
+
{
|
|
271
|
+
t,
|
|
272
|
+
depth: expanded ? 0 : depth,
|
|
273
|
+
offset,
|
|
274
|
+
hidden: !expanded && depth >= visible,
|
|
275
|
+
behind: !expanded && depth > 0,
|
|
276
|
+
frameHeight: !expanded && depth > 0 && frontH ? frontH : null,
|
|
277
|
+
isTop,
|
|
278
|
+
onHeight
|
|
279
|
+
},
|
|
280
|
+
t.id
|
|
281
|
+
);
|
|
282
|
+
}) })
|
|
283
|
+
}
|
|
284
|
+
),
|
|
285
|
+
document.body
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
function stripUndefined(o) {
|
|
289
|
+
const out = {};
|
|
290
|
+
Object.keys(o).forEach((k) => {
|
|
291
|
+
if (o[k] !== void 0) out[k] = o[k];
|
|
292
|
+
});
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
function Toaster({ htmlProps, ...props }) {
|
|
296
|
+
const config = { ...DEFAULT_TOASTER_CONFIG, ...stripUndefined(props) };
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
store.config = config;
|
|
299
|
+
store.mounted = true;
|
|
300
|
+
if (config.expand) store.setExpanded(true);
|
|
301
|
+
return () => {
|
|
302
|
+
store.mounted = false;
|
|
303
|
+
};
|
|
304
|
+
}, [config.position, config.duration, config.visibleToasts, config.gap, config.offset, config.expand]);
|
|
305
|
+
return /* @__PURE__ */ jsx(ToastHost, { config, htmlProps });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export { Toaster };
|
|
309
|
+
//# sourceMappingURL=toast.js.map
|
|
310
|
+
//# sourceMappingURL=toast.js.map
|