@yamatozhen/design_system 1.0.0 → 1.1.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 +201 -201
- package/README.md +101 -101
- package/package.json +50 -49
- package/scripts/postinstall.js +91 -105
- package/template/app/ClientNav.tsx +258 -310
- package/template/app/globals.css +2 -167
- package/template/app/layout.tsx +94 -128
- package/template/app/themes/dark-mc 2.css +51 -0
- package/template/app/themes/dark-mc.css +51 -51
- package/template/app/themes/dark.css +51 -51
- package/template/app/themes/light 2.css +51 -0
- package/template/app/themes/light-mc 2.css +51 -0
- package/template/app/themes/light-mc.css +51 -51
- package/template/app/themes/light.css +51 -51
- package/template/app/themes/theme 2.css +272 -0
- package/template/app/themes/theme.css +272 -82
- package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
- package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
- package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
- package/template/components/(buttons)/button.tsx +164 -0
- package/template/components/(controls)/slider/Slider.module.css +250 -0
- package/template/components/(controls)/slider/Slider.tsx +386 -0
- package/template/components/(controls)/switch/Switch.module.css +108 -0
- package/template/components/(controls)/switch/Switch.tsx +69 -0
- package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
- package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
- package/template/components/(date & time)/dateField/DateField.module.css +25 -0
- package/template/components/(date & time)/dateField/DateField.tsx +193 -0
- package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
- package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
- package/template/components/(date & time)/shared/dateUtils.ts +107 -0
- package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
- package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
- package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
- package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
- package/template/components/(feedback)/meter/Meter.tsx +111 -0
- package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
- package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
- package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
- package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
- package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
- package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
- package/template/components/(forms)/description/Description.tsx +34 -0
- package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
- package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
- package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
- package/template/components/(forms)/form/Form.tsx +54 -0
- package/template/components/(forms)/input/Input.tsx +50 -0
- package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
- package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
- package/template/components/(forms)/label/Label.tsx +46 -0
- package/template/components/(forms)/numberField/NumberField.tsx +292 -0
- package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
- package/template/components/(forms)/searchField/SearchField.tsx +139 -0
- package/template/components/(forms)/shared/field.module.css +75 -0
- package/template/components/(forms)/shared/fieldContext.ts +28 -0
- package/template/components/(forms)/textArea/TextArea.tsx +55 -0
- package/template/components/(forms)/textField/TextField.tsx +91 -0
- package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
- package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
- package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
- package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
- package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
- package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
- package/template/components/(layout)/accordion/Accordion.module.css +108 -0
- package/template/components/(layout)/accordion/Accordion.tsx +251 -0
- package/template/components/(layout)/card/Card.module.css +136 -0
- package/template/components/(layout)/card/Card.tsx +371 -0
- package/template/components/(layout)/list/List.module.css +83 -0
- package/template/components/(layout)/list/List.tsx +332 -0
- package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
- package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
- package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
- package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
- package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
- package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
- package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
- package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
- package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
- package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
- package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
- package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -478
- package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
- package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
- package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
- package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
- package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
- package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
- package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
- package/template/components/(layout)/separator/Separator.tsx +112 -0
- package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
- package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
- package/template/components/(overlays)/modal/Modal.tsx +654 -0
- package/template/components/(overlays)/popover/Popover.tsx +420 -0
- package/template/components/(overlays)/toast/Toast.tsx +692 -0
- package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
- package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
- package/template/components/(pickers)/select/Select.tsx +188 -0
- package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
- package/template/components/(pickers)/shared/PickerItem.ts +13 -0
- package/template/components/tools/CustomScrollbar 2.tsx +107 -0
- package/template/components/tools/CustomScrollbar.tsx +107 -0
- package/template/components/tools/Divider 2.tsx +11 -0
- package/template/components/tools/Divider.tsx +11 -11
- package/template/components/tools/ReduceMotionContext 2.tsx +5 -0
- package/template/components/tools/ReduceMotionContext.tsx +5 -5
- package/template/components/tools/Sinewave 2.tsx +206 -0
- package/template/components/tools/Sinewave.tsx +396 -199
- package/template/components/tools/SinewaveProgress 2.tsx +140 -0
- package/template/components/tools/SinewaveProgress.tsx +140 -135
- package/template/components/tools/badge/Badge 2.tsx +28 -0
- package/template/components/tools/badge/Badge.tsx +28 -28
- package/template/components/tools/dropdown/drop.module.css +196 -0
- package/template/components/tools/dropdown/drop.tsx +568 -0
- package/template/components/tools/easing.ts +118 -0
- package/template/components/tools/flubber.d 2.ts +7 -0
- package/template/components/tools/flubber.d.ts +6 -6
- package/template/components/tools/footer/Footer.tsx +20 -0
- package/template/components/tools/input/Input 2.tsx +99 -0
- package/template/components/tools/input/Input.module 2.css +45 -0
- package/template/components/tools/input/Input.module.css +45 -0
- package/template/components/tools/input/Input.tsx +99 -0
- package/template/components/tools/label/Icon 2.tsx +39 -0
- package/template/components/tools/label/Icon.tsx +39 -0
- package/template/components/tools/label/Label 2.tsx +150 -0
- package/template/components/tools/label/Label.tsx +156 -0
- package/template/components/tools/mobileViewProvider 2.tsx +53 -0
- package/template/components/tools/mobileViewProvider.tsx +53 -58
- package/template/components/tools/ripple/ripple 2.css +38 -0
- package/template/components/tools/ripple/ripple 2.tsx +78 -0
- package/template/components/tools/ripple/ripple.css +38 -41
- package/template/components/tools/ripple/ripple.tsx +78 -53
- package/template/components/tools/shape/{ShapeMorph.tsx → Shape 2.tsx } +313 -190
- package/template/components/tools/shape/Shape.module 2.css +21 -0
- package/template/components/tools/shape/Shape.module.css +25 -0
- package/template/components/tools/shape/Shape.tsx +316 -0
- package/template/components/tools/shape/ShapeLoader 2.tsx +104 -0
- package/template/components/tools/shape/ShapeLoader.tsx +104 -101
- package/template/components/tools/shape/ShapePaths 2.ts +116 -0
- package/template/components/tools/shape/ShapePaths.ts +116 -116
- package/template/components/{layout/switch/Switch.tsx → tools/switch/Switch 2.tsx } +48 -48
- package/template/components/{layout/switch/Switch.module.css → tools/switch/Switch.module 2.css } +102 -102
- package/template/components/tools/switch/Switch.module.css +102 -102
- package/template/components/tools/switch/Switch.tsx +48 -48
- package/template/components/tools/useBodyScrollLock 2.tsx +27 -0
- package/template/components/tools/useBodyScrollLock.tsx +27 -27
- package/template/components/tools/useImageColor 2.ts +47 -0
- package/template/components/tools/useImageColor.ts +47 -47
- package/template/components/tools/useNavSheetDrag 2.tsx +196 -0
- package/template/components/tools/useNavSheetDrag.tsx +196 -196
- package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght 2.woff2 +0 -0
- package/template/components/layout/accordion/Accordion.module.css +0 -149
- package/template/components/layout/accordion/Accordion.tsx +0 -114
- package/template/components/layout/button/button.tsx +0 -128
- package/template/components/layout/button/drop.module.css +0 -229
- package/template/components/layout/button/drop.tsx +0 -516
- package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
- package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
- package/template/components/layout/modals/alert/Alert.tsx +0 -188
- package/template/components/layout/navigation/MioCard.module.css +0 -88
- package/template/components/layout/navigation/MioCard.tsx +0 -266
- package/template/components/tools/ProgressiveBlur.tsx +0 -73
- package/template/components/tools/icon/SocialIcons.tsx +0 -88
- package/template/components/tools/icon/icon.module.css +0 -0
- package/template/components/tools/icon/icon.tsx +0 -125
- package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
- package/template/components/tools/react-bits/FadeContent.tsx +0 -90
- package/template/components/tools/react-bits/GlareHover.tsx +0 -73
- package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
- package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
- package/template/components/tools/react-bits/Magnet.tsx +0 -118
- package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
- package/template/components/tools/react-bits/Stepper/Stepper.tsx +0 -412
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { AnimatePresence, motion, MotionConfig } from "framer-motion";
|
|
3
|
+
import React, {
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
useSyncExternalStore,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { createPortal } from "react-dom";
|
|
11
|
+
import Button from "@/components/(buttons)/button";
|
|
12
|
+
import Icon from "@/components/tools/label/Icon";
|
|
13
|
+
import Label from "@/components/tools/label/Label";
|
|
14
|
+
import Shape from "@/components/tools/shape/Shape";
|
|
15
|
+
import type { ShapeInput } from "@/components/tools/shape/ShapePaths";
|
|
16
|
+
import { useReduceMotion } from "@/components/tools/ReduceMotionContext";
|
|
17
|
+
|
|
18
|
+
// Same color-role vocabulary as Dialog's variant — kept in sync intentionally
|
|
19
|
+
// so "error" always means the same thing across the design system.
|
|
20
|
+
export type ToastVariant =
|
|
21
|
+
| "default"
|
|
22
|
+
| "primary"
|
|
23
|
+
| "secondary"
|
|
24
|
+
| "tertiary"
|
|
25
|
+
| "success"
|
|
26
|
+
| "error";
|
|
27
|
+
|
|
28
|
+
export type ToastPlacement =
|
|
29
|
+
| "top"
|
|
30
|
+
| "top-start"
|
|
31
|
+
| "top-end"
|
|
32
|
+
| "bottom"
|
|
33
|
+
| "bottom-start"
|
|
34
|
+
| "bottom-end";
|
|
35
|
+
|
|
36
|
+
export interface ToastActionProps {
|
|
37
|
+
label: string;
|
|
38
|
+
systemName?: string;
|
|
39
|
+
onClick: () => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ToastOptions {
|
|
43
|
+
description?: React.ReactNode;
|
|
44
|
+
variant?: ToastVariant;
|
|
45
|
+
// Pass null to hide the indicator entirely; omit for the default per-variant
|
|
46
|
+
// icon+circle badge; pass a full node to replace the badge entirely (its
|
|
47
|
+
// color/background is then entirely up to you, since variant no longer
|
|
48
|
+
// applies). For lighter overrides that keep the automatic variant color:
|
|
49
|
+
indicator?: React.ReactNode | null;
|
|
50
|
+
// Swaps just the glyph, keeping the default badge and its variant color.
|
|
51
|
+
systemName?: string;
|
|
52
|
+
// If set, the badge renders via Shape (the morphing blob used for Dialog's
|
|
53
|
+
// header icon) instead of a plain circle — still colored from variant.
|
|
54
|
+
shape?: ShapeInput;
|
|
55
|
+
actionProps?: ToastActionProps;
|
|
56
|
+
// ms; 0 = persistent (no auto-dismiss). Defaults to 4000.
|
|
57
|
+
timeout?: number;
|
|
58
|
+
onClose?: () => void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface QueuedToast {
|
|
62
|
+
id: string;
|
|
63
|
+
title: React.ReactNode;
|
|
64
|
+
description?: React.ReactNode;
|
|
65
|
+
variant: ToastVariant;
|
|
66
|
+
indicator?: React.ReactNode | null;
|
|
67
|
+
systemName?: string;
|
|
68
|
+
shape?: ShapeInput;
|
|
69
|
+
actionProps?: ToastActionProps;
|
|
70
|
+
timeout: number;
|
|
71
|
+
onClose?: () => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let nextId = 0;
|
|
75
|
+
|
|
76
|
+
export interface ToastQueue {
|
|
77
|
+
add: (title: React.ReactNode, options?: ToastOptions) => string;
|
|
78
|
+
close: (id: string) => void;
|
|
79
|
+
clear: () => void;
|
|
80
|
+
subscribe: (listener: () => void) => () => void;
|
|
81
|
+
getSnapshot: () => QueuedToast[];
|
|
82
|
+
getServerSnapshot: () => QueuedToast[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// A queue lives outside React entirely (plain closures, no component state),
|
|
86
|
+
// so add()/close() can be called from anywhere — a click handler, a promise
|
|
87
|
+
// callback, outside any component — not just from inside a render.
|
|
88
|
+
// ToastProvider is just a subscriber that mirrors one queue into React state
|
|
89
|
+
// via useSyncExternalStore. Multiple independent queues can exist at once —
|
|
90
|
+
// e.g. one per placement, each with its own ToastProvider, so a toast fired
|
|
91
|
+
// at "top" never shows up in a "bottom-end" region and vice versa.
|
|
92
|
+
export function createToastQueue(): ToastQueue {
|
|
93
|
+
let toasts: QueuedToast[] = [];
|
|
94
|
+
const listeners = new Set<() => void>();
|
|
95
|
+
// Must return the same reference every call — a fresh [] here makes React
|
|
96
|
+
// think the store changes on every render (it warns about a possible
|
|
97
|
+
// infinite loop, since nothing ever compares equal).
|
|
98
|
+
const EMPTY: QueuedToast[] = [];
|
|
99
|
+
|
|
100
|
+
function emit() {
|
|
101
|
+
listeners.forEach((listener) => listener());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function add(title: React.ReactNode, options: ToastOptions = {}): string {
|
|
105
|
+
const id = `toast-${nextId++}`;
|
|
106
|
+
toasts = [
|
|
107
|
+
...toasts,
|
|
108
|
+
{
|
|
109
|
+
id,
|
|
110
|
+
title,
|
|
111
|
+
description: options.description,
|
|
112
|
+
variant: options.variant ?? "default",
|
|
113
|
+
indicator: options.indicator,
|
|
114
|
+
systemName: options.systemName,
|
|
115
|
+
shape: options.shape,
|
|
116
|
+
actionProps: options.actionProps,
|
|
117
|
+
timeout: options.timeout ?? 4000,
|
|
118
|
+
onClose: options.onClose,
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
emit();
|
|
122
|
+
return id;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function close(id: string) {
|
|
126
|
+
const closed = toasts.find((t) => t.id === id);
|
|
127
|
+
if (!closed) return;
|
|
128
|
+
toasts = toasts.filter((t) => t.id !== id);
|
|
129
|
+
emit();
|
|
130
|
+
closed.onClose?.();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function clear() {
|
|
134
|
+
const closing = toasts;
|
|
135
|
+
toasts = [];
|
|
136
|
+
emit();
|
|
137
|
+
closing.forEach((t) => t.onClose?.());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function subscribe(listener: () => void) {
|
|
141
|
+
listeners.add(listener);
|
|
142
|
+
return () => {
|
|
143
|
+
listeners.delete(listener);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function getSnapshot() {
|
|
148
|
+
return toasts;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getServerSnapshot() {
|
|
152
|
+
return EMPTY;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { add, close, clear, subscribe, getSnapshot, getServerSnapshot };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// The queue toast()/toast.success()/etc. operate on, and the one
|
|
159
|
+
// ToastProvider falls back to when no queue prop is given.
|
|
160
|
+
const defaultQueue = createToastQueue();
|
|
161
|
+
|
|
162
|
+
type ToastFn = ((title: React.ReactNode, options?: ToastOptions) => string) & {
|
|
163
|
+
success: (
|
|
164
|
+
title: React.ReactNode,
|
|
165
|
+
options?: Omit<ToastOptions, "variant">,
|
|
166
|
+
) => string;
|
|
167
|
+
error: (
|
|
168
|
+
title: React.ReactNode,
|
|
169
|
+
options?: Omit<ToastOptions, "variant">,
|
|
170
|
+
) => string;
|
|
171
|
+
close: ToastQueue["close"];
|
|
172
|
+
clear: ToastQueue["clear"];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const toastFn = ((title, options) =>
|
|
176
|
+
defaultQueue.add(title, options)) as ToastFn;
|
|
177
|
+
toastFn.success = (title, options) =>
|
|
178
|
+
defaultQueue.add(title, { ...options, variant: "success" });
|
|
179
|
+
toastFn.error = (title, options) =>
|
|
180
|
+
defaultQueue.add(title, { ...options, variant: "error" });
|
|
181
|
+
toastFn.close = defaultQueue.close;
|
|
182
|
+
toastFn.clear = defaultQueue.clear;
|
|
183
|
+
|
|
184
|
+
// import { toast } from "@/components/(overlays)/toast/Toast";
|
|
185
|
+
// toast("Saved"); toast.success("Uploaded", { description: "..." }); toast.error(...);
|
|
186
|
+
export const toast = toastFn;
|
|
187
|
+
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
// Rendering
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
|
|
192
|
+
// Material has no dedicated "warning" role, and "default" has no container
|
|
193
|
+
// token — both fall back to a neutral surface tone, same pattern as Dialog's
|
|
194
|
+
// iconColors.
|
|
195
|
+
function variantColors(variant: ToastVariant) {
|
|
196
|
+
if (variant === "default") {
|
|
197
|
+
return {
|
|
198
|
+
bg: "var(--md-sys-color-surface-container-high)",
|
|
199
|
+
fg: "var(--md-sys-color-on-surface-variant)",
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
bg: `var(--md-sys-color-${variant}-container)`,
|
|
204
|
+
fg: `var(--md-sys-color-on-${variant}-container)`,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const VARIANT_ICON: Record<ToastVariant, string> = {
|
|
209
|
+
default: "info",
|
|
210
|
+
primary: "info",
|
|
211
|
+
secondary: "info",
|
|
212
|
+
tertiary: "info",
|
|
213
|
+
success: "check_circle",
|
|
214
|
+
error: "error",
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// Matches --borderRadius-md (calc(24px) in theme.css, the same token
|
|
218
|
+
// ToastItem's own borderRadius uses below) — the default collapsed peek
|
|
219
|
+
// offset between stacked toasts, so the sliver of a toast behind the front
|
|
220
|
+
// one is calibrated to reveal exactly its own rounded corner, same idea as
|
|
221
|
+
// Drawer's nested-push amount. Hardcoded rather than read via
|
|
222
|
+
// getComputedStyle since it's just a fixed default, not something that
|
|
223
|
+
// needs to track theme changes live.
|
|
224
|
+
const TOAST_PEEK_PX = 14;
|
|
225
|
+
|
|
226
|
+
// Split in two: the anchor is the position:fixed box pinned to a viewport
|
|
227
|
+
// edge (no size of its own beyond its content); the stack is the flex
|
|
228
|
+
// column of toasts inside it. Kept separate so a glow layer can sit between
|
|
229
|
+
// them as an absolutely-positioned sibling of the stack — sized to match it
|
|
230
|
+
// via the shared anchor parent — without being an ancestor the toasts would
|
|
231
|
+
// inherit blur from.
|
|
232
|
+
function regionAnchorStyle(placement: ToastPlacement): React.CSSProperties {
|
|
233
|
+
const isTop = placement.startsWith("top");
|
|
234
|
+
const style: React.CSSProperties = {
|
|
235
|
+
position: "fixed",
|
|
236
|
+
padding: 16,
|
|
237
|
+
pointerEvents: "none",
|
|
238
|
+
};
|
|
239
|
+
style[isTop ? "top" : "bottom"] = 0;
|
|
240
|
+
if (placement.endsWith("start")) {
|
|
241
|
+
style.left = 0;
|
|
242
|
+
} else if (placement.endsWith("end")) {
|
|
243
|
+
style.right = 0;
|
|
244
|
+
} else {
|
|
245
|
+
style.left = "50%";
|
|
246
|
+
style.transform = "translateX(-50%)";
|
|
247
|
+
}
|
|
248
|
+
return style;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Toasts inside are all `position: absolute`, stacked on the same edge — so
|
|
252
|
+
// this container needs an explicit height (it can't get one from
|
|
253
|
+
// already-out-of-flow children). Collapsed, that height tracks just the
|
|
254
|
+
// frontmost toast's measured height; expanded (stack hovered), it tracks the
|
|
255
|
+
// full fanned-out height instead — see expandedHeight in ToastProvider.
|
|
256
|
+
function regionStackStyle(
|
|
257
|
+
width: number | string,
|
|
258
|
+
height: number | undefined,
|
|
259
|
+
): React.CSSProperties {
|
|
260
|
+
return {
|
|
261
|
+
position: "relative",
|
|
262
|
+
width,
|
|
263
|
+
maxWidth: "calc(100vw - 32px)",
|
|
264
|
+
height: height ?? "auto",
|
|
265
|
+
transition: "height 0.25s cubic-bezier(0.4, 0, 0.2, 1)",
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Reports this item's rendered height to the stack (which uses the
|
|
270
|
+
// frontmost item's height to size itself, since absolutely-positioned
|
|
271
|
+
// children can't do that on their own). Runs on mount and on any resize
|
|
272
|
+
// (e.g. description text wrapping differently after a width change).
|
|
273
|
+
function useReportedHeight(
|
|
274
|
+
id: string,
|
|
275
|
+
onHeightChange: (id: string, height: number) => void,
|
|
276
|
+
) {
|
|
277
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
const el = ref.current;
|
|
280
|
+
if (!el) return;
|
|
281
|
+
const report = () => onHeightChange(id, el.offsetHeight);
|
|
282
|
+
report();
|
|
283
|
+
const observer = new ResizeObserver(report);
|
|
284
|
+
observer.observe(el);
|
|
285
|
+
return () => observer.disconnect();
|
|
286
|
+
}, [id, onHeightChange]);
|
|
287
|
+
return ref;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type ToastItemProps = {
|
|
291
|
+
toastData: QueuedToast;
|
|
292
|
+
index: number;
|
|
293
|
+
isBottom: boolean;
|
|
294
|
+
gap: number;
|
|
295
|
+
scaleFactor: number;
|
|
296
|
+
// Whether the stack is currently fanned out (group hover) — swaps this
|
|
297
|
+
// item from the collapsed peek offset/scale to its real expanded
|
|
298
|
+
// position at full size. Pausing the dismiss timer is tied to the same
|
|
299
|
+
// group-hover state (not a per-item hover), so browsing the expanded
|
|
300
|
+
// stack doesn't let a toast you're not currently pointing at expire
|
|
301
|
+
// out from under you.
|
|
302
|
+
expanded: boolean;
|
|
303
|
+
expandedOffset: number;
|
|
304
|
+
paused: boolean;
|
|
305
|
+
onHeightChange: (id: string, height: number) => void;
|
|
306
|
+
onDismiss: (id: string) => void;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
function ToastItem({
|
|
310
|
+
toastData,
|
|
311
|
+
index,
|
|
312
|
+
isBottom,
|
|
313
|
+
gap,
|
|
314
|
+
scaleFactor,
|
|
315
|
+
expanded,
|
|
316
|
+
expandedOffset,
|
|
317
|
+
paused,
|
|
318
|
+
onHeightChange,
|
|
319
|
+
onDismiss,
|
|
320
|
+
}: ToastItemProps) {
|
|
321
|
+
const remainingRef = useRef(toastData.timeout);
|
|
322
|
+
// Placeholder — always overwritten by the effect below before it's ever
|
|
323
|
+
// read (the cleanup that reads it can't fire before an effect run has
|
|
324
|
+
// set it). Date.now() can't be called here: useRef's initial argument is
|
|
325
|
+
// evaluated on every render, so an impure call there isn't render-pure.
|
|
326
|
+
const startRef = useRef(0);
|
|
327
|
+
const heightRef = useReportedHeight(toastData.id, onHeightChange);
|
|
328
|
+
|
|
329
|
+
useEffect(() => {
|
|
330
|
+
if (toastData.timeout <= 0 || paused) return;
|
|
331
|
+
startRef.current = Date.now();
|
|
332
|
+
const timer = setTimeout(
|
|
333
|
+
() => onDismiss(toastData.id),
|
|
334
|
+
remainingRef.current,
|
|
335
|
+
);
|
|
336
|
+
return () => {
|
|
337
|
+
clearTimeout(timer);
|
|
338
|
+
remainingRef.current -= Date.now() - startRef.current;
|
|
339
|
+
};
|
|
340
|
+
}, [paused, toastData.id, toastData.timeout, onDismiss]);
|
|
341
|
+
|
|
342
|
+
const colors = variantColors(toastData.variant);
|
|
343
|
+
const systemName = toastData.systemName ?? VARIANT_ICON[toastData.variant];
|
|
344
|
+
const defaultIndicator = (
|
|
345
|
+
<Shape
|
|
346
|
+
systemName={systemName}
|
|
347
|
+
shapePath={toastData.shape ?? "circle"}
|
|
348
|
+
background={colors.bg}
|
|
349
|
+
color={colors.fg}
|
|
350
|
+
size="xs"
|
|
351
|
+
isHovered={false}
|
|
352
|
+
interactive={false}
|
|
353
|
+
/>
|
|
354
|
+
);
|
|
355
|
+
const indicator =
|
|
356
|
+
toastData.indicator === null
|
|
357
|
+
? null
|
|
358
|
+
: (toastData.indicator ?? defaultIndicator);
|
|
359
|
+
|
|
360
|
+
// Every toast in the stack is absolute + anchored to the same edge; index
|
|
361
|
+
// 0 (frontmost) sits flush, each one behind it is pushed back by gap and
|
|
362
|
+
// scaled down — the classic peeking-card-stack look. zIndex has to be set
|
|
363
|
+
// explicitly since DOM order alone would put later (further-back) items
|
|
364
|
+
// on top. Expanded (group hover), all items sit at their real measured
|
|
365
|
+
// offset and full scale instead.
|
|
366
|
+
const translateY = expanded
|
|
367
|
+
? (isBottom ? -1 : 1) * expandedOffset
|
|
368
|
+
: (isBottom ? -1 : 1) * index * gap;
|
|
369
|
+
const scale = expanded ? 1 : 1 - index * scaleFactor;
|
|
370
|
+
|
|
371
|
+
return (
|
|
372
|
+
<motion.div
|
|
373
|
+
ref={heightRef}
|
|
374
|
+
initial={{ opacity: 0, y: isBottom ? 24 : -24, scale: 0.95 }}
|
|
375
|
+
animate={{ opacity: 1, y: translateY, scale }}
|
|
376
|
+
exit={{ opacity: 0, scale: 0.9 }}
|
|
377
|
+
transition={{ duration: 0.25, ease: [0.4, 0, 0.2, 1] }}
|
|
378
|
+
role="status"
|
|
379
|
+
aria-live="polite"
|
|
380
|
+
className="a11y-modal-surface"
|
|
381
|
+
style={{
|
|
382
|
+
position: "absolute",
|
|
383
|
+
[isBottom ? "bottom" : "top"]: 0,
|
|
384
|
+
left: 0,
|
|
385
|
+
right: 0,
|
|
386
|
+
zIndex: 1000 - index,
|
|
387
|
+
transformOrigin: isBottom ? "bottom center" : "top center",
|
|
388
|
+
pointerEvents: "auto",
|
|
389
|
+
display: "flex",
|
|
390
|
+
alignItems: "flex-start",
|
|
391
|
+
gap: 12,
|
|
392
|
+
boxSizing: "border-box",
|
|
393
|
+
padding: 16,
|
|
394
|
+
borderRadius: "var(--borderRadius-md)",
|
|
395
|
+
boxShadow:
|
|
396
|
+
"0 0 0 1px var(--globalUIBorder), 0 1px 1px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.1)",
|
|
397
|
+
backgroundColor: "var(--md-sys-color-surface-container-lowest)",
|
|
398
|
+
}}
|
|
399
|
+
>
|
|
400
|
+
{indicator}
|
|
401
|
+
<div
|
|
402
|
+
style={{
|
|
403
|
+
flex: 1,
|
|
404
|
+
minWidth: 0,
|
|
405
|
+
display: "flex",
|
|
406
|
+
flexDirection: "column",
|
|
407
|
+
gap: 4,
|
|
408
|
+
margin: "auto 0",
|
|
409
|
+
}}
|
|
410
|
+
>
|
|
411
|
+
<div
|
|
412
|
+
style={{ fontWeight: 500, color: "var(--md-sys-color-on-surface)" }}
|
|
413
|
+
>
|
|
414
|
+
{toastData.title}
|
|
415
|
+
</div>
|
|
416
|
+
{toastData.description && (
|
|
417
|
+
<div
|
|
418
|
+
style={{
|
|
419
|
+
fontSize: 14,
|
|
420
|
+
color: "var(--md-sys-color-on-surface-variant)",
|
|
421
|
+
}}
|
|
422
|
+
>
|
|
423
|
+
{toastData.description}
|
|
424
|
+
</div>
|
|
425
|
+
)}
|
|
426
|
+
{toastData.actionProps && (
|
|
427
|
+
<Button
|
|
428
|
+
outlined
|
|
429
|
+
onClick={() => {
|
|
430
|
+
toastData.actionProps!.onClick();
|
|
431
|
+
// Unlike Dialog's confirm, a toast action is a one-shot
|
|
432
|
+
// response — acting on it resolves the notification, so it
|
|
433
|
+
// always dismisses afterward rather than staying put.
|
|
434
|
+
onDismiss(toastData.id);
|
|
435
|
+
}}
|
|
436
|
+
style={{ marginTop: 4, alignSelf: "flex-start" }}
|
|
437
|
+
>
|
|
438
|
+
<Label
|
|
439
|
+
label={toastData.actionProps.label}
|
|
440
|
+
systemName={toastData.actionProps.systemName}
|
|
441
|
+
/>
|
|
442
|
+
</Button>
|
|
443
|
+
)}
|
|
444
|
+
</div>
|
|
445
|
+
<Button
|
|
446
|
+
text
|
|
447
|
+
onClick={() => onDismiss(toastData.id)}
|
|
448
|
+
aria-label="Dismiss"
|
|
449
|
+
style={{
|
|
450
|
+
flexShrink: 0,
|
|
451
|
+
scale: 0.8,
|
|
452
|
+
width: 36,
|
|
453
|
+
height: 36,
|
|
454
|
+
top: -12,
|
|
455
|
+
right: -12,
|
|
456
|
+
color: "var(--md-sys-color-secondary)",
|
|
457
|
+
}}
|
|
458
|
+
>
|
|
459
|
+
<Icon systemName="close" />
|
|
460
|
+
</Button>
|
|
461
|
+
</motion.div>
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
type ToastProviderProps = {
|
|
466
|
+
placement?: ToastPlacement;
|
|
467
|
+
// Collapsed peek offset, in pixels, between each stacked-behind toast's
|
|
468
|
+
// edge and the one in front of it — this is what controls how much of a
|
|
469
|
+
// back toast is visible before you hover the stack. @default
|
|
470
|
+
// TOAST_PEEK_PX (matches --borderRadius-md, the toast card's own corner
|
|
471
|
+
// radius)
|
|
472
|
+
gap?: number;
|
|
473
|
+
maxVisibleToasts?: number;
|
|
474
|
+
// How much each toast behind the frontmost shrinks, as a fraction per
|
|
475
|
+
// step (0.06 = 6% smaller per position back). Combined with `gap`, this
|
|
476
|
+
// is the other knob on how small/hidden the back toasts look while
|
|
477
|
+
// collapsed — lower it for back toasts that stay closer to full size.
|
|
478
|
+
// @default 0.06
|
|
479
|
+
scaleFactor?: number;
|
|
480
|
+
// Gap, in pixels, between toasts once the stack is fanned out (hovered) —
|
|
481
|
+
// independent from the collapsed peek `gap` above. @default 12
|
|
482
|
+
expandedGap?: number;
|
|
483
|
+
width?: number | string;
|
|
484
|
+
// Defaults to the shared queue toast()/toast.success()/etc. operate on.
|
|
485
|
+
// Pass a queue from createToastQueue() to run an independent stack — e.g.
|
|
486
|
+
// one ToastProvider + queue per placement, so a toast fired at "top"
|
|
487
|
+
// never shows up in a "bottom-end" region mounted elsewhere.
|
|
488
|
+
queue?: ToastQueue;
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// Exported standalone (not just via Toast.Provider below) because a Server
|
|
492
|
+
// Component — app/layout.tsx, notably — can't reliably resolve a nested
|
|
493
|
+
// property access like Toast.Provider through the "use client" boundary;
|
|
494
|
+
// Next's RSC machinery proxies named exports of a client module, not
|
|
495
|
+
// arbitrary properties on an object one of those exports happens to hold.
|
|
496
|
+
export function ToastProvider({
|
|
497
|
+
placement = "bottom",
|
|
498
|
+
gap = TOAST_PEEK_PX,
|
|
499
|
+
maxVisibleToasts = 3,
|
|
500
|
+
scaleFactor = 0.06,
|
|
501
|
+
expandedGap = 12,
|
|
502
|
+
width = 380,
|
|
503
|
+
queue = defaultQueue,
|
|
504
|
+
}: ToastProviderProps) {
|
|
505
|
+
const rm = useReduceMotion();
|
|
506
|
+
const allToasts = useSyncExternalStore(
|
|
507
|
+
queue.subscribe,
|
|
508
|
+
queue.getSnapshot,
|
|
509
|
+
queue.getServerSnapshot,
|
|
510
|
+
);
|
|
511
|
+
const [mounted, setMounted] = useState(false);
|
|
512
|
+
// Portal-safety: defer createPortal until after client hydration, which
|
|
513
|
+
// can only be detected post-mount.
|
|
514
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
515
|
+
useEffect(() => setMounted(true), []);
|
|
516
|
+
|
|
517
|
+
// Frontmost toast's measured height drives the stack container's height
|
|
518
|
+
// (see regionStackStyle). Pruned against the live toast list so closed
|
|
519
|
+
// toasts don't linger in the map forever.
|
|
520
|
+
const [heights, setHeights] = useState<Record<string, number>>({});
|
|
521
|
+
const handleHeightChange = useCallback((id: string, height: number) => {
|
|
522
|
+
setHeights((prev) =>
|
|
523
|
+
prev[id] === height ? prev : { ...prev, [id]: height },
|
|
524
|
+
);
|
|
525
|
+
}, []);
|
|
526
|
+
// Prunes heights for toasts no longer in the queue. Genuinely two
|
|
527
|
+
// independently-evolving pieces of state — heights arrive over time from
|
|
528
|
+
// child ResizeObservers, the queue from an external store — so this can't
|
|
529
|
+
// be computed at render time; it has to reconcile after the fact.
|
|
530
|
+
/* eslint-disable react-hooks/set-state-in-effect */
|
|
531
|
+
useEffect(() => {
|
|
532
|
+
const ids = new Set(allToasts.map((t) => t.id));
|
|
533
|
+
setHeights((prev) => {
|
|
534
|
+
let changed = false;
|
|
535
|
+
const next: Record<string, number> = {};
|
|
536
|
+
for (const key in prev) {
|
|
537
|
+
if (ids.has(key)) next[key] = prev[key];
|
|
538
|
+
else changed = true;
|
|
539
|
+
}
|
|
540
|
+
return changed ? next : prev;
|
|
541
|
+
});
|
|
542
|
+
}, [allToasts]);
|
|
543
|
+
/* eslint-enable react-hooks/set-state-in-effect */
|
|
544
|
+
|
|
545
|
+
// Hovering the stack (not any one toast) fans every visible toast out to
|
|
546
|
+
// its full size/real position, and — via the `paused` prop each item gets
|
|
547
|
+
// below — pauses all of their dismiss timers together, so browsing the
|
|
548
|
+
// expanded stack never lets one you're not pointing at expire out from
|
|
549
|
+
// under you.
|
|
550
|
+
const [expanded, setExpanded] = useState(false);
|
|
551
|
+
|
|
552
|
+
if (!mounted) return null;
|
|
553
|
+
|
|
554
|
+
const isBottom = placement.startsWith("bottom");
|
|
555
|
+
// Newest toast is pushed to the end of the queue by add(); newest should
|
|
556
|
+
// be frontmost (index 0), so the render order is reversed from queue order.
|
|
557
|
+
const visible = [...allToasts].reverse().slice(0, maxVisibleToasts);
|
|
558
|
+
const frontHeight = visible[0] ? heights[visible[0].id] : undefined;
|
|
559
|
+
const hasVisible = visible.length > 0;
|
|
560
|
+
|
|
561
|
+
// Real cumulative offsets used once the stack fans out — each toast's own
|
|
562
|
+
// measured height (heights arrive async per-item via ResizeObserver; fall
|
|
563
|
+
// back to the front toast's height for one that hasn't reported yet)
|
|
564
|
+
// stacked with expandedGap between them, instead of the uniform peek
|
|
565
|
+
// offset used while collapsed. maxVisibleToasts is small (default 3), so
|
|
566
|
+
// the O(n^2) prefix sum here is negligible.
|
|
567
|
+
const itemHeights = visible.map((t) => heights[t.id] ?? frontHeight ?? 0);
|
|
568
|
+
const expandedOffsets = itemHeights.map((_, i) =>
|
|
569
|
+
itemHeights.slice(0, i).reduce((sum, h) => sum + h + expandedGap, 0),
|
|
570
|
+
);
|
|
571
|
+
const expandedHeight =
|
|
572
|
+
itemHeights.reduce((sum, h) => sum + h, 0) +
|
|
573
|
+
Math.max(0, itemHeights.length - 1) * expandedGap;
|
|
574
|
+
|
|
575
|
+
// AnimatePresence has to stay mounted continuously — conditionally
|
|
576
|
+
// returning null once the queue empties would unmount it in the same
|
|
577
|
+
// render where the last toast is supposed to be playing its exit
|
|
578
|
+
// animation, killing that animation outright. The glow fades via a plain
|
|
579
|
+
// CSS opacity transition instead of being removed, for the same reason.
|
|
580
|
+
return createPortal(
|
|
581
|
+
<MotionConfig reducedMotion={rm ? "always" : "never"}>
|
|
582
|
+
<div style={{ ...regionAnchorStyle(placement), zIndex: 100050 }}>
|
|
583
|
+
{/* Glow layer — a sibling of the stack, not an ancestor, so the blur
|
|
584
|
+
never applies to the toasts themselves. It has no size of its
|
|
585
|
+
own; `inset` fills whatever box this anchor's one in-flow child
|
|
586
|
+
(the stack) establishes, so it tracks the stack's size exactly. */}
|
|
587
|
+
<div
|
|
588
|
+
aria-hidden
|
|
589
|
+
style={{
|
|
590
|
+
position: "absolute",
|
|
591
|
+
inset: -24,
|
|
592
|
+
background:
|
|
593
|
+
"color-mix(var(--md-sys-color-surface-container-low) 100%, transparent 25%)",
|
|
594
|
+
filter: "blur(48px)",
|
|
595
|
+
zIndex: -1,
|
|
596
|
+
pointerEvents: "none",
|
|
597
|
+
opacity: hasVisible ? 1 : 0,
|
|
598
|
+
transition: "opacity 0.25s ease",
|
|
599
|
+
}}
|
|
600
|
+
/>
|
|
601
|
+
<div
|
|
602
|
+
style={{
|
|
603
|
+
...regionStackStyle(width, expanded ? expandedHeight : frontHeight),
|
|
604
|
+
pointerEvents: hasVisible ? "auto" : "none",
|
|
605
|
+
}}
|
|
606
|
+
onMouseEnter={() => setExpanded(true)}
|
|
607
|
+
onMouseLeave={() => setExpanded(false)}
|
|
608
|
+
>
|
|
609
|
+
<AnimatePresence initial={false}>
|
|
610
|
+
{visible.map((t, index) => (
|
|
611
|
+
<ToastItem
|
|
612
|
+
key={t.id}
|
|
613
|
+
toastData={t}
|
|
614
|
+
index={index}
|
|
615
|
+
isBottom={isBottom}
|
|
616
|
+
gap={gap}
|
|
617
|
+
scaleFactor={scaleFactor}
|
|
618
|
+
expanded={expanded}
|
|
619
|
+
expandedOffset={expandedOffsets[index]}
|
|
620
|
+
paused={expanded}
|
|
621
|
+
onHeightChange={handleHeightChange}
|
|
622
|
+
onDismiss={queue.close}
|
|
623
|
+
/>
|
|
624
|
+
))}
|
|
625
|
+
</AnimatePresence>
|
|
626
|
+
</div>
|
|
627
|
+
</div>
|
|
628
|
+
</MotionConfig>,
|
|
629
|
+
document.body,
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export const Toast = { Provider: ToastProvider };
|
|
634
|
+
|
|
635
|
+
/* Example usage:
|
|
636
|
+
|
|
637
|
+
// app/layout.tsx — mount once. It's a Server Component, so import the named
|
|
638
|
+
// ToastProvider export directly rather than Toast.Provider (see the comment
|
|
639
|
+
// on ToastProvider above for why). Toast.Provider is fine to use from inside
|
|
640
|
+
// a "use client" file.
|
|
641
|
+
import { ToastProvider } from "@/components/(overlays)/toast/Toast";
|
|
642
|
+
<ToastProvider placement="bottom-end" />
|
|
643
|
+
|
|
644
|
+
// anywhere — a click handler, a promise .then(), outside React entirely
|
|
645
|
+
import { toast } from "@/components/(overlays)/toast/Toast";
|
|
646
|
+
|
|
647
|
+
toast("Event has been created");
|
|
648
|
+
|
|
649
|
+
toast.success("File saved", {
|
|
650
|
+
description: "your-file.pdf is ready to download",
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
toast.error("Storage is full", {
|
|
654
|
+
description: "Remove files to release space.",
|
|
655
|
+
actionProps: { label: "Remove", onClick: () => {} },
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// Keep the automatic variant color, just change the glyph:
|
|
659
|
+
toast.success("Upload complete", { systemName: "cloud_done" });
|
|
660
|
+
|
|
661
|
+
// Same, but rendered via Shape (the morphing blob) instead of a plain circle:
|
|
662
|
+
toast.error("Storage is full", { shape: "hexagon" });
|
|
663
|
+
|
|
664
|
+
// Fully custom indicator (bypasses variant color entirely):
|
|
665
|
+
toast("Custom", { indicator: <MyIcon /> });
|
|
666
|
+
|
|
667
|
+
// No indicator at all:
|
|
668
|
+
toast("No icon", { indicator: null });
|
|
669
|
+
|
|
670
|
+
// Testing every placement side by side — one queue + provider per placement,
|
|
671
|
+
// same pattern as HeroUI's own Placements demo:
|
|
672
|
+
const placements = ["top-start", "top", "top-end", "bottom-start", "bottom", "bottom-end"] as const;
|
|
673
|
+
const placementQueues = Object.fromEntries(
|
|
674
|
+
placements.map((p) => [p, createToastQueue()]),
|
|
675
|
+
) as Record<(typeof placements)[number], ToastQueue>;
|
|
676
|
+
|
|
677
|
+
function Placements() {
|
|
678
|
+
return (
|
|
679
|
+
<>
|
|
680
|
+
{placements.map((p) => (
|
|
681
|
+
<ToastProvider key={p} placement={p} queue={placementQueues[p]} />
|
|
682
|
+
))}
|
|
683
|
+
{placements.map((p) => (
|
|
684
|
+
<Button key={p} onClick={() => placementQueues[p].add("Event created")}>
|
|
685
|
+
<Label label={p} />
|
|
686
|
+
</Button>
|
|
687
|
+
))}
|
|
688
|
+
</>
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
*/
|