@urbicon-ui/blocks 6.21.0 → 6.21.2
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/components/Calendar/calendar.variants.d.ts +132 -419
- package/dist/components/CommandPalette/commandPalette.variants.d.ts +24 -51
- package/dist/components/CompositionBar/CompositionBar.svelte +6 -1
- package/dist/components/CompositionBar/composition-bar.variants.d.ts +23 -83
- package/dist/components/CompositionBar/composition-bar.variants.js +9 -3
- package/dist/components/EmptyState/emptyState.variants.d.ts +11 -27
- package/dist/components/FileUpload/fileUpload.variants.d.ts +24 -93
- package/dist/components/Guide/GuidePanel.svelte +38 -0
- package/dist/components/Guide/guide.variants.d.ts +69 -124
- package/dist/components/Guide/guide.variants.js +6 -1
- package/dist/components/NumberInput/NumberInput.svelte +197 -0
- package/dist/components/NumberInput/NumberInput.svelte.d.ts +4 -0
- package/dist/components/NumberInput/index.d.ts +55 -0
- package/dist/components/NumberInput/index.js +1 -0
- package/dist/components/Planner/planner.variants.d.ts +23 -94
- package/dist/components/Sankey/sankey.variants.d.ts +15 -48
- package/dist/components/SidebarLayout/sidebar-layout.variants.d.ts +10 -38
- package/dist/components/SidebarLayout/sidebar-layout.variants.js +12 -2
- package/dist/components/ThemeSwitcher/themeSwitcher.variants.d.ts +9 -36
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +1 -0
- package/dist/i18n/index.d.ts +8 -372
- package/dist/internal/charts/variants.d.ts +18 -31
- package/dist/primitives/Accordion/Accordion.svelte +11 -0
- package/dist/primitives/Accordion/AccordionItem.svelte +9 -3
- package/dist/primitives/Accordion/accordion.variants.d.ts +12 -43
- package/dist/primitives/Accordion/accordion.variants.js +6 -2
- package/dist/primitives/Accordion/index.d.ts +12 -0
- package/dist/primitives/Alert/alert.variants.d.ts +21 -62
- package/dist/primitives/Avatar/avatar.variants.d.ts +18 -138
- package/dist/primitives/Badge/Badge.svelte +12 -4
- package/dist/primitives/Badge/badge.variants.d.ts +19 -92
- package/dist/primitives/Badge/badge.variants.js +11 -4
- package/dist/primitives/Badge/index.d.ts +26 -6
- package/dist/primitives/Breadcrumb/Breadcrumb.svelte +11 -6
- package/dist/primitives/Breadcrumb/breadcrumb.variants.d.ts +13 -40
- package/dist/primitives/Breadcrumb/index.d.ts +2 -2
- package/dist/primitives/Button/button.variants.d.ts +19 -98
- package/dist/primitives/Button/button.variants.js +13 -9
- package/dist/primitives/ButtonGroup/buttongroup.variants.d.ts +9 -29
- package/dist/primitives/ButtonGroup/buttongroup.variants.js +3 -1
- package/dist/primitives/Card/card.variants.d.ts +14 -81
- package/dist/primitives/Checkbox/Checkbox.svelte +3 -3
- package/dist/primitives/Checkbox/checkbox.variants.d.ts +18 -77
- package/dist/primitives/Collapsible/Collapsible.svelte +10 -0
- package/dist/primitives/Collapsible/collapsible.variants.d.ts +11 -40
- package/dist/primitives/Collapsible/collapsible.variants.js +7 -2
- package/dist/primitives/Collapsible/index.d.ts +16 -0
- package/dist/primitives/Combobox/Combobox.svelte +478 -104
- package/dist/primitives/Combobox/combobox.variants.d.ts +112 -94
- package/dist/primitives/Combobox/combobox.variants.js +94 -13
- package/dist/primitives/Combobox/index.d.ts +166 -51
- package/dist/primitives/ConfirmDialog/index.d.ts +19 -0
- package/dist/primitives/Dialog/Dialog.svelte +95 -10
- package/dist/primitives/Dialog/dialog.variants.d.ts +15 -54
- package/dist/primitives/Dialog/index.d.ts +12 -1
- package/dist/primitives/Drawer/Drawer.svelte +23 -11
- package/dist/primitives/Drawer/drawer.variants.d.ts +22 -49
- package/dist/primitives/Drawer/drawer.variants.js +45 -10
- package/dist/primitives/Drawer/index.d.ts +13 -4
- package/dist/primitives/FormField/FormField.svelte +6 -6
- package/dist/primitives/FormField/index.d.ts +13 -4
- package/dist/primitives/Input/Input.svelte +8 -4
- package/dist/primitives/Input/input.variants.d.ts +32 -139
- package/dist/primitives/Input/input.variants.js +12 -10
- package/dist/primitives/JourneyTimeline/journey-timeline.variants.d.ts +55 -197
- package/dist/primitives/JourneyTimeline/journey-timeline.variants.js +4 -1
- package/dist/primitives/Menu/Menu.svelte +66 -4
- package/dist/primitives/Menu/index.d.ts +25 -0
- package/dist/primitives/Menu/menu.variants.d.ts +29 -93
- package/dist/primitives/Pagination/Pagination.svelte +28 -13
- package/dist/primitives/Pagination/index.d.ts +44 -0
- package/dist/primitives/Pagination/pagination.variants.d.ts +16 -54
- package/dist/primitives/Pagination/pagination.variants.js +16 -14
- package/dist/primitives/Popover/Popover.svelte +11 -1
- package/dist/primitives/Popover/index.d.ts +3 -3
- package/dist/primitives/Popover/popover.variants.d.ts +4 -2
- package/dist/primitives/Progress/progress.variants.d.ts +19 -83
- package/dist/primitives/Progress/progress.variants.js +2 -1
- package/dist/primitives/RadioGroup/RadioGroup.svelte +3 -3
- package/dist/primitives/RadioGroup/radioGroup.variants.d.ts +28 -109
- package/dist/primitives/SegmentGroup/SegmentGroup.svelte +14 -6
- package/dist/primitives/SegmentGroup/segmentgroup.variants.d.ts +12 -53
- package/dist/primitives/SegmentGroup/segmentgroup.variants.js +10 -10
- package/dist/primitives/Select/Select.svelte +21 -11
- package/dist/primitives/Select/index.d.ts +7 -0
- package/dist/primitives/Select/select.variants.d.ts +61 -150
- package/dist/primitives/Select/select.variants.js +24 -4
- package/dist/primitives/Separator/separator.variants.d.ts +4 -2
- package/dist/primitives/Sidebar/Sidebar.svelte +10 -15
- package/dist/primitives/Sidebar/sidebar.variants.d.ts +11 -29
- package/dist/primitives/Skeleton/skeleton.variants.d.ts +9 -36
- package/dist/primitives/Slider/Slider.svelte +4 -8
- package/dist/primitives/Slider/slider.variants.d.ts +37 -136
- package/dist/primitives/Slider/slider.variants.js +8 -5
- package/dist/primitives/Spinner/spinner.variants.d.ts +38 -135
- package/dist/primitives/Stepper/stepper.variants.d.ts +32 -130
- package/dist/primitives/Tab/Tab.svelte +14 -6
- package/dist/primitives/Tab/tab.variants.d.ts +17 -78
- package/dist/primitives/Textarea/Textarea.svelte +4 -5
- package/dist/primitives/Textarea/textarea.variants.d.ts +33 -118
- package/dist/primitives/Textarea/textarea.variants.js +17 -12
- package/dist/primitives/Toast/Toaster.svelte +58 -5
- package/dist/primitives/Toast/index.d.ts +39 -0
- package/dist/primitives/Toast/toast.store.svelte.d.ts +25 -1
- package/dist/primitives/Toast/toast.store.svelte.js +91 -1
- package/dist/primitives/Toast/toast.variants.d.ts +40 -78
- package/dist/primitives/Toast/toast.variants.js +15 -0
- package/dist/primitives/Toggle/Toggle.svelte +17 -3
- package/dist/primitives/Toggle/index.d.ts +8 -2
- package/dist/primitives/Toggle/toggle.variants.d.ts +24 -71
- package/dist/primitives/Toggle/toggle.variants.js +26 -0
- package/dist/primitives/Toolbar/toolbar.variants.d.ts +9 -60
- package/dist/primitives/Tooltip/Tooltip.svelte +58 -21
- package/dist/primitives/Tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/primitives/Tooltip/index.d.ts +45 -3
- package/dist/primitives/Tooltip/tooltip.variants.d.ts +14 -53
- package/dist/primitives/Tooltip/tooltip.variants.js +9 -3
- package/dist/primitives/index.d.ts +3 -3
- package/dist/style/foundation.css +4 -1
- package/dist/style/interaction.css +39 -11
- package/dist/style/semantic.css +2 -2
- package/dist/style/themes/index.css +1 -1
- package/dist/translations/de.d.ts +3 -0
- package/dist/translations/de.js +4 -1
- package/dist/translations/en.d.ts +3 -0
- package/dist/translations/en.js +4 -1
- package/dist/utils/guide.svelte.d.ts +8 -2
- package/dist/utils/guide.svelte.js +86 -5
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +5 -0
- package/dist/utils/overlay.d.ts +33 -4
- package/dist/utils/overlay.js +61 -18
- package/dist/utils/roving.d.ts +15 -0
- package/dist/utils/roving.js +44 -0
- package/dist/utils/use-floating-panel.svelte.d.ts +4 -1
- package/dist/utils/use-floating-panel.svelte.js +23 -1
- package/dist/utils/use-form-field.svelte.d.ts +9 -9
- package/dist/utils/use-form-field.svelte.js +12 -12
- package/dist/utils/variants.d.ts +60 -16
- package/dist/utils/variants.js +424 -123
- package/package.json +9 -6
|
@@ -1,194 +1,109 @@
|
|
|
1
1
|
import { type SlotNames, type VariantProps } from '../../utils/variants.js';
|
|
2
|
-
export declare const textareaVariants: (props?:
|
|
3
|
-
tier
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
filled: {
|
|
16
|
-
base: string;
|
|
17
|
-
};
|
|
18
|
-
ghost: {
|
|
19
|
-
base: string;
|
|
20
|
-
};
|
|
21
|
-
underline: {
|
|
22
|
-
base: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
size: {
|
|
26
|
-
sm: {
|
|
27
|
-
base: string;
|
|
28
|
-
};
|
|
29
|
-
md: {
|
|
30
|
-
base: string;
|
|
31
|
-
};
|
|
32
|
-
lg: {
|
|
33
|
-
base: string;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
intent: {
|
|
37
|
-
default: {};
|
|
38
|
-
success: {
|
|
39
|
-
base: string;
|
|
40
|
-
message: string;
|
|
41
|
-
};
|
|
42
|
-
warning: {
|
|
43
|
-
base: string;
|
|
44
|
-
message: string;
|
|
45
|
-
};
|
|
46
|
-
danger: {
|
|
47
|
-
base: string;
|
|
48
|
-
message: string;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
autoResize: {
|
|
52
|
-
true: {
|
|
53
|
-
base: string;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
disabled: {
|
|
57
|
-
true: {
|
|
58
|
-
base: string;
|
|
59
|
-
label: string;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
readonly: {
|
|
63
|
-
true: {
|
|
64
|
-
base: string;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
error: {
|
|
68
|
-
true: {
|
|
69
|
-
base: string;
|
|
70
|
-
message: string;
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
required: {
|
|
74
|
-
true: {
|
|
75
|
-
label: string;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
messageType: {
|
|
79
|
-
error: {
|
|
80
|
-
message: string;
|
|
81
|
-
};
|
|
82
|
-
helper: {
|
|
83
|
-
message: string;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
counterState: {
|
|
87
|
-
normal: {};
|
|
88
|
-
warning: {
|
|
89
|
-
counter: string;
|
|
90
|
-
};
|
|
91
|
-
over: {
|
|
92
|
-
counter: string;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
}> | undefined) => {
|
|
2
|
+
export declare const textareaVariants: ((props?: {
|
|
3
|
+
tier?: "commit" | "modify" | undefined;
|
|
4
|
+
variant?: "ghost" | "filled" | "outlined" | "underline" | undefined;
|
|
5
|
+
size?: "sm" | "md" | "lg" | "xl" | "xs" | undefined;
|
|
6
|
+
intent?: "default" | "success" | "warning" | "danger" | undefined;
|
|
7
|
+
autoResize?: boolean | undefined;
|
|
8
|
+
disabled?: boolean | undefined;
|
|
9
|
+
readonly?: boolean | undefined;
|
|
10
|
+
messageType?: "error" | "helper" | undefined;
|
|
11
|
+
error?: boolean | undefined;
|
|
12
|
+
required?: boolean | undefined;
|
|
13
|
+
counterState?: "warning" | "normal" | "over" | undefined;
|
|
14
|
+
} | undefined) => {
|
|
96
15
|
wrapper: (props?: ({
|
|
97
16
|
tier?: "commit" | "modify" | undefined;
|
|
98
17
|
variant?: "ghost" | "filled" | "outlined" | "underline" | undefined;
|
|
99
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
18
|
+
size?: "sm" | "md" | "lg" | "xl" | "xs" | undefined;
|
|
100
19
|
intent?: "default" | "success" | "warning" | "danger" | undefined;
|
|
101
20
|
autoResize?: boolean | undefined;
|
|
102
21
|
disabled?: boolean | undefined;
|
|
103
22
|
readonly?: boolean | undefined;
|
|
23
|
+
messageType?: "error" | "helper" | undefined;
|
|
104
24
|
error?: boolean | undefined;
|
|
105
25
|
required?: boolean | undefined;
|
|
106
|
-
messageType?: "error" | "helper" | undefined;
|
|
107
26
|
counterState?: "warning" | "normal" | "over" | undefined;
|
|
108
27
|
} & {
|
|
109
|
-
class?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
110
|
-
className?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
28
|
+
class?: string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | /*elided*/ any | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined;
|
|
111
29
|
}) | undefined) => string;
|
|
112
30
|
base: (props?: ({
|
|
113
31
|
tier?: "commit" | "modify" | undefined;
|
|
114
32
|
variant?: "ghost" | "filled" | "outlined" | "underline" | undefined;
|
|
115
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
33
|
+
size?: "sm" | "md" | "lg" | "xl" | "xs" | undefined;
|
|
116
34
|
intent?: "default" | "success" | "warning" | "danger" | undefined;
|
|
117
35
|
autoResize?: boolean | undefined;
|
|
118
36
|
disabled?: boolean | undefined;
|
|
119
37
|
readonly?: boolean | undefined;
|
|
38
|
+
messageType?: "error" | "helper" | undefined;
|
|
120
39
|
error?: boolean | undefined;
|
|
121
40
|
required?: boolean | undefined;
|
|
122
|
-
messageType?: "error" | "helper" | undefined;
|
|
123
41
|
counterState?: "warning" | "normal" | "over" | undefined;
|
|
124
42
|
} & {
|
|
125
|
-
class?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
126
|
-
className?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
43
|
+
class?: string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | /*elided*/ any | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined;
|
|
127
44
|
}) | undefined) => string;
|
|
128
45
|
label: (props?: ({
|
|
129
46
|
tier?: "commit" | "modify" | undefined;
|
|
130
47
|
variant?: "ghost" | "filled" | "outlined" | "underline" | undefined;
|
|
131
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
48
|
+
size?: "sm" | "md" | "lg" | "xl" | "xs" | undefined;
|
|
132
49
|
intent?: "default" | "success" | "warning" | "danger" | undefined;
|
|
133
50
|
autoResize?: boolean | undefined;
|
|
134
51
|
disabled?: boolean | undefined;
|
|
135
52
|
readonly?: boolean | undefined;
|
|
53
|
+
messageType?: "error" | "helper" | undefined;
|
|
136
54
|
error?: boolean | undefined;
|
|
137
55
|
required?: boolean | undefined;
|
|
138
|
-
messageType?: "error" | "helper" | undefined;
|
|
139
56
|
counterState?: "warning" | "normal" | "over" | undefined;
|
|
140
57
|
} & {
|
|
141
|
-
class?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
142
|
-
className?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
58
|
+
class?: string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | /*elided*/ any | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined;
|
|
143
59
|
}) | undefined) => string;
|
|
144
60
|
footer: (props?: ({
|
|
145
61
|
tier?: "commit" | "modify" | undefined;
|
|
146
62
|
variant?: "ghost" | "filled" | "outlined" | "underline" | undefined;
|
|
147
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
63
|
+
size?: "sm" | "md" | "lg" | "xl" | "xs" | undefined;
|
|
148
64
|
intent?: "default" | "success" | "warning" | "danger" | undefined;
|
|
149
65
|
autoResize?: boolean | undefined;
|
|
150
66
|
disabled?: boolean | undefined;
|
|
151
67
|
readonly?: boolean | undefined;
|
|
68
|
+
messageType?: "error" | "helper" | undefined;
|
|
152
69
|
error?: boolean | undefined;
|
|
153
70
|
required?: boolean | undefined;
|
|
154
|
-
messageType?: "error" | "helper" | undefined;
|
|
155
71
|
counterState?: "warning" | "normal" | "over" | undefined;
|
|
156
72
|
} & {
|
|
157
|
-
class?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
158
|
-
className?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
73
|
+
class?: string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | /*elided*/ any | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined;
|
|
159
74
|
}) | undefined) => string;
|
|
160
75
|
message: (props?: ({
|
|
161
76
|
tier?: "commit" | "modify" | undefined;
|
|
162
77
|
variant?: "ghost" | "filled" | "outlined" | "underline" | undefined;
|
|
163
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
78
|
+
size?: "sm" | "md" | "lg" | "xl" | "xs" | undefined;
|
|
164
79
|
intent?: "default" | "success" | "warning" | "danger" | undefined;
|
|
165
80
|
autoResize?: boolean | undefined;
|
|
166
81
|
disabled?: boolean | undefined;
|
|
167
82
|
readonly?: boolean | undefined;
|
|
83
|
+
messageType?: "error" | "helper" | undefined;
|
|
168
84
|
error?: boolean | undefined;
|
|
169
85
|
required?: boolean | undefined;
|
|
170
|
-
messageType?: "error" | "helper" | undefined;
|
|
171
86
|
counterState?: "warning" | "normal" | "over" | undefined;
|
|
172
87
|
} & {
|
|
173
|
-
class?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
174
|
-
className?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
88
|
+
class?: string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | /*elided*/ any | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined;
|
|
175
89
|
}) | undefined) => string;
|
|
176
90
|
counter: (props?: ({
|
|
177
91
|
tier?: "commit" | "modify" | undefined;
|
|
178
92
|
variant?: "ghost" | "filled" | "outlined" | "underline" | undefined;
|
|
179
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
93
|
+
size?: "sm" | "md" | "lg" | "xl" | "xs" | undefined;
|
|
180
94
|
intent?: "default" | "success" | "warning" | "danger" | undefined;
|
|
181
95
|
autoResize?: boolean | undefined;
|
|
182
96
|
disabled?: boolean | undefined;
|
|
183
97
|
readonly?: boolean | undefined;
|
|
98
|
+
messageType?: "error" | "helper" | undefined;
|
|
184
99
|
error?: boolean | undefined;
|
|
185
100
|
required?: boolean | undefined;
|
|
186
|
-
messageType?: "error" | "helper" | undefined;
|
|
187
101
|
counterState?: "warning" | "normal" | "over" | undefined;
|
|
188
102
|
} & {
|
|
189
|
-
class?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
190
|
-
className?: string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | (string | false | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined;
|
|
103
|
+
class?: string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | (string | number | false | /*elided*/ any | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined)[] | Record<string, boolean | null | undefined> | null | undefined;
|
|
191
104
|
}) | undefined) => string;
|
|
105
|
+
}) & {
|
|
106
|
+
readonly config: import("../../utils/variants.js").TVConfig;
|
|
192
107
|
};
|
|
193
108
|
export type TextareaVariants = VariantProps<typeof textareaVariants>;
|
|
194
109
|
/** Slot names derived from the `tv()` config above — single source of truth for `slotClasses`. */
|
|
@@ -39,25 +39,28 @@ export const textareaVariants = tv({
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
size: {
|
|
42
|
+
// Full xs–xl scale (form-family symmetry with Input's ladder).
|
|
42
43
|
// `pointer-coarse:text-base` floors the font to 16px on touch so iOS
|
|
43
|
-
// Safari doesn't auto-zoom the field on focus. Desktop keeps 14px.
|
|
44
|
+
// Safari doesn't auto-zoom the field on focus. Desktop keeps 12/14px.
|
|
45
|
+
xs: { base: 'px-2 py-1.5 text-xs pointer-coarse:text-base min-h-[4rem]' },
|
|
44
46
|
sm: { base: 'px-3 py-2 text-sm pointer-coarse:text-base min-h-[5rem]' },
|
|
45
47
|
md: { base: 'px-4 py-3 text-base min-h-[7rem]' },
|
|
46
|
-
lg: { base: 'px-6 py-4 text-lg min-h-[9rem]' }
|
|
48
|
+
lg: { base: 'px-6 py-4 text-lg min-h-[9rem]' },
|
|
49
|
+
xl: { base: 'px-8 py-5 text-xl min-h-[11rem]' }
|
|
47
50
|
},
|
|
51
|
+
// Message colour is owned by messageType/error (declared below) — an
|
|
52
|
+
// intent-level message tone could never win the fold and shipped
|
|
53
|
+
// inconsistently under the old stylesheet-order tie-break.
|
|
48
54
|
intent: {
|
|
49
55
|
default: {},
|
|
50
56
|
success: {
|
|
51
|
-
base: 'border-success focus-visible:border-success focus-visible:ring-success/20'
|
|
52
|
-
message: 'text-success'
|
|
57
|
+
base: 'border-success focus-visible:border-success focus-visible:ring-success/20'
|
|
53
58
|
},
|
|
54
59
|
warning: {
|
|
55
|
-
base: 'border-warning focus-visible:border-warning focus-visible:ring-warning/20'
|
|
56
|
-
message: 'text-warning-emphasis'
|
|
60
|
+
base: 'border-warning focus-visible:border-warning focus-visible:ring-warning/20'
|
|
57
61
|
},
|
|
58
62
|
danger: {
|
|
59
|
-
base: 'border-danger focus-visible:border-danger focus-visible:ring-danger/20'
|
|
60
|
-
message: 'text-danger'
|
|
63
|
+
base: 'border-danger focus-visible:border-danger focus-visible:ring-danger/20'
|
|
61
64
|
}
|
|
62
65
|
},
|
|
63
66
|
autoResize: {
|
|
@@ -74,6 +77,12 @@ export const textareaVariants = tv({
|
|
|
74
77
|
base: 'bg-surface-subtle cursor-default'
|
|
75
78
|
}
|
|
76
79
|
},
|
|
80
|
+
// Declared BEFORE `error` so the error tone wins the message-color
|
|
81
|
+
// bucket in every call shape — `{ error: true }` alone must read red.
|
|
82
|
+
messageType: {
|
|
83
|
+
error: { message: 'text-danger' },
|
|
84
|
+
helper: { message: 'text-text-tertiary' }
|
|
85
|
+
},
|
|
77
86
|
error: {
|
|
78
87
|
true: {
|
|
79
88
|
base: 'border-danger focus-visible:border-danger focus-visible:ring-danger/20',
|
|
@@ -85,10 +94,6 @@ export const textareaVariants = tv({
|
|
|
85
94
|
label: "after:content-['*'] after:ml-1 after:text-danger"
|
|
86
95
|
}
|
|
87
96
|
},
|
|
88
|
-
messageType: {
|
|
89
|
-
error: { message: 'text-danger' },
|
|
90
|
-
helper: { message: 'text-text-tertiary' }
|
|
91
|
-
},
|
|
92
97
|
counterState: {
|
|
93
98
|
normal: {},
|
|
94
99
|
warning: { counter: 'text-warning-emphasis' },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useBlocksI18n } from '../..';
|
|
3
3
|
import { fly } from 'svelte/transition';
|
|
4
|
-
import {
|
|
4
|
+
import { getOverlayMotion } from '../../utils';
|
|
5
5
|
import { toastVariants, type ToastVariants } from './toast.variants';
|
|
6
6
|
import { toaster } from './toast.store.svelte';
|
|
7
7
|
import { resolveIcon, type IconComponent } from '../../icons';
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
import WarningTriangleIconDefault from '../../icons/WarningTriangleIcon.svelte';
|
|
12
12
|
import DangerCircleIconDefault from '../../icons/DangerCircleIcon.svelte';
|
|
13
13
|
import { getBlocksConfig, resolveSlotClasses } from '../../provider';
|
|
14
|
-
import
|
|
14
|
+
import Spinner from '../Spinner/Spinner.svelte';
|
|
15
|
+
import type { ToastData, ToastProps } from './index';
|
|
15
16
|
|
|
16
17
|
const bt = useBlocksI18n();
|
|
17
18
|
|
|
@@ -29,6 +30,8 @@
|
|
|
29
30
|
let {
|
|
30
31
|
placement = 'bottom-right',
|
|
31
32
|
max = 5,
|
|
33
|
+
transitionDuration,
|
|
34
|
+
transitionEasing,
|
|
32
35
|
class: className = '',
|
|
33
36
|
unstyled: unstyledProp = false,
|
|
34
37
|
slotClasses: slotClassesProp = {},
|
|
@@ -64,12 +67,25 @@
|
|
|
64
67
|
content: () => '',
|
|
65
68
|
title: () => '',
|
|
66
69
|
description: () => '',
|
|
70
|
+
actions: () => '',
|
|
71
|
+
actionButton: () => '',
|
|
72
|
+
cancelButton: () => '',
|
|
67
73
|
dismissButton: () => '',
|
|
68
74
|
progress: () => ''
|
|
69
75
|
}
|
|
70
76
|
: toastVariants({ placement })
|
|
71
77
|
);
|
|
72
78
|
|
|
79
|
+
// Run a toast action/cancel button: fire its handler, then dismiss unless the
|
|
80
|
+
// action opted out (`dismissOnClick: false`, e.g. a "Retry" that re-issues the
|
|
81
|
+
// async work and updates the same toast).
|
|
82
|
+
function runAction(toast: ToastData, which: 'action' | 'cancel') {
|
|
83
|
+
const action = toast[which];
|
|
84
|
+
if (!action) return;
|
|
85
|
+
action.onClick?.(toast.id);
|
|
86
|
+
if (action.dismissOnClick !== false) toaster.dismiss(toast.id);
|
|
87
|
+
}
|
|
88
|
+
|
|
73
89
|
function slot(key: keyof typeof styles, intent?: string) {
|
|
74
90
|
const overrides = slotClasses?.[key];
|
|
75
91
|
if (unstyled) return overrides ?? '';
|
|
@@ -84,11 +100,22 @@
|
|
|
84
100
|
const isBottom = placement.startsWith('bottom');
|
|
85
101
|
const isRight = placement.endsWith('right');
|
|
86
102
|
const isLeft = placement.endsWith('left');
|
|
103
|
+
// Enter/exit motion resolved from the shared overlay tokens
|
|
104
|
+
// (--blocks-overlay-*, same source as Dialog/Drawer): a global theme or
|
|
105
|
+
// `prefers-reduced-motion` retunes every toast, and the two props override
|
|
106
|
+
// it per toaster instance. Resolved per toast so the live reduced-motion
|
|
107
|
+
// value applies; `fly` is symmetric here, so the enter duration drives both
|
|
108
|
+
// directions.
|
|
109
|
+
const motion = getOverlayMotion({
|
|
110
|
+
enterDuration: transitionDuration,
|
|
111
|
+
exitDuration: transitionDuration,
|
|
112
|
+
easing: transitionEasing
|
|
113
|
+
});
|
|
87
114
|
return {
|
|
88
115
|
y: isBottom ? 20 : -20,
|
|
89
116
|
x: isRight ? 20 : isLeft ? -20 : 0,
|
|
90
|
-
duration:
|
|
91
|
-
easing:
|
|
117
|
+
duration: motion.enterDuration,
|
|
118
|
+
easing: motion.easing
|
|
92
119
|
};
|
|
93
120
|
}
|
|
94
121
|
</script>
|
|
@@ -102,7 +129,11 @@
|
|
|
102
129
|
{#each visibleToasts as toast (toast.id)}
|
|
103
130
|
{@const IntentIcon = INTENT_ICON_MAP[toast.intent] ?? INTENT_ICON_MAP.neutral}
|
|
104
131
|
<div class={slot('toast', toast.intent)} role="alert" transition:fly={flyParams()}>
|
|
105
|
-
|
|
132
|
+
{#if toast.loading}
|
|
133
|
+
<span class={slot('icon', toast.intent)}><Spinner size="sm" /></span>
|
|
134
|
+
{:else}
|
|
135
|
+
<IntentIcon class={slot('icon', toast.intent)} />
|
|
136
|
+
{/if}
|
|
106
137
|
|
|
107
138
|
<div class={slot('content')}>
|
|
108
139
|
{#if toast.title}
|
|
@@ -111,6 +142,28 @@
|
|
|
111
142
|
{#if toast.description}
|
|
112
143
|
<div class={slot('description')}>{toast.description}</div>
|
|
113
144
|
{/if}
|
|
145
|
+
{#if toast.action || toast.cancel}
|
|
146
|
+
<div class={slot('actions')}>
|
|
147
|
+
{#if toast.action}
|
|
148
|
+
<button
|
|
149
|
+
type="button"
|
|
150
|
+
class={slot('actionButton')}
|
|
151
|
+
onclick={() => runAction(toast, 'action')}
|
|
152
|
+
>
|
|
153
|
+
{toast.action.label}
|
|
154
|
+
</button>
|
|
155
|
+
{/if}
|
|
156
|
+
{#if toast.cancel}
|
|
157
|
+
<button
|
|
158
|
+
type="button"
|
|
159
|
+
class={slot('cancelButton')}
|
|
160
|
+
onclick={() => runAction(toast, 'cancel')}
|
|
161
|
+
>
|
|
162
|
+
{toast.cancel.label}
|
|
163
|
+
</button>
|
|
164
|
+
{/if}
|
|
165
|
+
</div>
|
|
166
|
+
{/if}
|
|
114
167
|
</div>
|
|
115
168
|
|
|
116
169
|
{#if toast.dismissible}
|
|
@@ -11,6 +11,17 @@ export declare const TOAST_INTENTS: readonly ["primary", "info", "success", "war
|
|
|
11
11
|
* standard intent palette.
|
|
12
12
|
*/
|
|
13
13
|
export type ToastIntent = (typeof TOAST_INTENTS)[number];
|
|
14
|
+
/**
|
|
15
|
+
* An action or cancel button rendered inside a toast (Sonner-style).
|
|
16
|
+
*/
|
|
17
|
+
export interface ToastAction {
|
|
18
|
+
/** Button label. */
|
|
19
|
+
label: string;
|
|
20
|
+
/** Click handler. Receives the toast id so the handler can dismiss/update it. */
|
|
21
|
+
onClick?: (id: string) => void;
|
|
22
|
+
/** Dismiss the toast after the click. @default true */
|
|
23
|
+
dismissOnClick?: boolean;
|
|
24
|
+
}
|
|
14
25
|
/**
|
|
15
26
|
* Internal data shape for a rendered toast. Created by `toaster.add()`.
|
|
16
27
|
*/
|
|
@@ -29,6 +40,25 @@ export interface ToastData {
|
|
|
29
40
|
dismissible: boolean;
|
|
30
41
|
/** Show an animated progress bar that counts down the remaining `duration`. @default true */
|
|
31
42
|
showProgress: boolean;
|
|
43
|
+
/** Primary action button (prominent). */
|
|
44
|
+
action?: ToastAction;
|
|
45
|
+
/** Secondary/cancel button (quiet). */
|
|
46
|
+
cancel?: ToastAction;
|
|
47
|
+
/** Render a spinner instead of the intent icon (used by `toaster.promise` while pending). @default false */
|
|
48
|
+
loading?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Per-state config for `toaster.promise`. Each state is either a plain title
|
|
52
|
+
* string or a full {@link ToastInput}; `success`/`error` may also be a function
|
|
53
|
+
* of the resolved value / rejection reason.
|
|
54
|
+
*/
|
|
55
|
+
export interface ToastPromiseOptions<T> {
|
|
56
|
+
/** Shown while the promise is pending (spinner, persistent, not dismissible). */
|
|
57
|
+
loading: string | ToastInput;
|
|
58
|
+
/** Shown when the promise resolves. */
|
|
59
|
+
success: string | ToastInput | ((value: T) => string | ToastInput);
|
|
60
|
+
/** Shown when the promise rejects. */
|
|
61
|
+
error: string | ToastInput | ((reason: unknown) => string | ToastInput);
|
|
32
62
|
}
|
|
33
63
|
/**
|
|
34
64
|
* Options accepted by `toaster.add()` and the shorthand methods (`info`, `success`, `warning`, `danger`).
|
|
@@ -77,6 +107,15 @@ export interface ToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'childr
|
|
|
77
107
|
placement?: ToastPlacement;
|
|
78
108
|
/** Maximum number of toasts visible at once. Oldest are hidden first. @default 5 */
|
|
79
109
|
max?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Override the enter/exit fly animation duration in milliseconds for every
|
|
112
|
+
* toast in this toaster. Defaults to the overlay token
|
|
113
|
+
* `--blocks-overlay-enter-duration` (200ms). Set globally via the CSS custom
|
|
114
|
+
* property or per-instance via this prop. Respects `prefers-reduced-motion`.
|
|
115
|
+
*/
|
|
116
|
+
transitionDuration?: number;
|
|
117
|
+
/** Override the enter/exit fly easing. Defaults to the overlay token easing (`quintOut`). */
|
|
118
|
+
transitionEasing?: (t: number) => number;
|
|
80
119
|
/** Extra classes merged onto the container element. */
|
|
81
120
|
class?: string;
|
|
82
121
|
/** Strip all default tv classes. Use with `slotClasses` for a fully custom look. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToastData, ToastInput, ToastShorthandOpts } from './index.js';
|
|
1
|
+
import type { ToastData, ToastInput, ToastPromiseOptions, ToastShorthandOpts } from './index.js';
|
|
2
2
|
import type { ToastPlacement } from './toast.variants.js';
|
|
3
3
|
/**
|
|
4
4
|
* Reactive store that manages the global toast queue.
|
|
@@ -24,6 +24,30 @@ declare class ToastStore {
|
|
|
24
24
|
registerSubscriber(): () => void;
|
|
25
25
|
/** Create a toast with full control over all options. Returns the toast ID for programmatic dismissal. */
|
|
26
26
|
add(input: ToastInput): string;
|
|
27
|
+
/**
|
|
28
|
+
* Merge new fields into an existing toast in place — same id, same stack
|
|
29
|
+
* position — and reset its auto-dismiss timer to the new `duration`. No-op if
|
|
30
|
+
* the toast is gone. Backs `promise()`, which flips a pending toast to
|
|
31
|
+
* success/error without it sliding out and a new one flying in.
|
|
32
|
+
*/
|
|
33
|
+
update(id: string, input: ToastInput): void;
|
|
34
|
+
/**
|
|
35
|
+
* Drive a toast through a promise's lifecycle (Sonner-style). Shows a
|
|
36
|
+
* persistent, non-dismissible spinner toast while pending, then flips it in
|
|
37
|
+
* place to success on resolve or danger on reject. `success`/`error` may be a
|
|
38
|
+
* plain title, a full {@link ToastInput}, or a function of the resolved value
|
|
39
|
+
* / rejection reason. Returns the toast id.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* toaster.promise(saveDraft(), {
|
|
44
|
+
* loading: 'Saving…',
|
|
45
|
+
* success: (draft) => `Saved “${draft.title}”`,
|
|
46
|
+
* error: (e) => `Could not save: ${e.message}`
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
promise<T>(promise: Promise<T>, opts: ToastPromiseOptions<T>): string;
|
|
27
51
|
/** Remove a single toast by ID. Clears its auto-dismiss timer. */
|
|
28
52
|
dismiss(id: string): void;
|
|
29
53
|
/** Remove all toasts and cancel their timers. */
|
|
@@ -50,7 +50,10 @@ class ToastStore {
|
|
|
50
50
|
description: input.description,
|
|
51
51
|
duration: input.duration ?? 5000,
|
|
52
52
|
dismissible: input.dismissible ?? true,
|
|
53
|
-
showProgress: input.showProgress ?? true
|
|
53
|
+
showProgress: input.showProgress ?? true,
|
|
54
|
+
action: input.action,
|
|
55
|
+
cancel: input.cancel,
|
|
56
|
+
loading: input.loading ?? false
|
|
54
57
|
};
|
|
55
58
|
this.toasts = [...this.toasts, toast];
|
|
56
59
|
if (toast.duration > 0) {
|
|
@@ -58,6 +61,93 @@ class ToastStore {
|
|
|
58
61
|
}
|
|
59
62
|
return id;
|
|
60
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Merge new fields into an existing toast in place — same id, same stack
|
|
66
|
+
* position — and reset its auto-dismiss timer to the new `duration`. No-op if
|
|
67
|
+
* the toast is gone. Backs `promise()`, which flips a pending toast to
|
|
68
|
+
* success/error without it sliding out and a new one flying in.
|
|
69
|
+
*/
|
|
70
|
+
update(id, input) {
|
|
71
|
+
const idx = this.toasts.findIndex((t) => t.id === id);
|
|
72
|
+
if (idx === -1)
|
|
73
|
+
return;
|
|
74
|
+
const next = { ...this.toasts[idx], ...input };
|
|
75
|
+
this.toasts = [...this.toasts.slice(0, idx), next, ...this.toasts.slice(idx + 1)];
|
|
76
|
+
const timer = this.timers.get(id);
|
|
77
|
+
if (timer) {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
this.timers.delete(id);
|
|
80
|
+
}
|
|
81
|
+
if (next.duration > 0) {
|
|
82
|
+
this.timers.set(id, setTimeout(() => this.dismiss(id), next.duration));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Drive a toast through a promise's lifecycle (Sonner-style). Shows a
|
|
87
|
+
* persistent, non-dismissible spinner toast while pending, then flips it in
|
|
88
|
+
* place to success on resolve or danger on reject. `success`/`error` may be a
|
|
89
|
+
* plain title, a full {@link ToastInput}, or a function of the resolved value
|
|
90
|
+
* / rejection reason. Returns the toast id.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* toaster.promise(saveDraft(), {
|
|
95
|
+
* loading: 'Saving…',
|
|
96
|
+
* success: (draft) => `Saved “${draft.title}”`,
|
|
97
|
+
* error: (e) => `Could not save: ${e.message}`
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
promise(promise, opts) {
|
|
102
|
+
const loadingInput = typeof opts.loading === 'string' ? { title: opts.loading } : opts.loading;
|
|
103
|
+
const id = this.add({
|
|
104
|
+
intent: 'neutral',
|
|
105
|
+
...loadingInput,
|
|
106
|
+
loading: true,
|
|
107
|
+
duration: 0,
|
|
108
|
+
dismissible: false,
|
|
109
|
+
showProgress: false
|
|
110
|
+
});
|
|
111
|
+
// Shared settle fields: leave the spinner/persistent/non-dismissible state
|
|
112
|
+
// and become a normal auto-dismissing toast. `description: undefined` clears
|
|
113
|
+
// the loading description unless the success/error config sets its own.
|
|
114
|
+
const settled = {
|
|
115
|
+
loading: false,
|
|
116
|
+
duration: 5000,
|
|
117
|
+
dismissible: true,
|
|
118
|
+
showProgress: true
|
|
119
|
+
};
|
|
120
|
+
// A throwing user formatter must not turn into an unhandled rejection on the
|
|
121
|
+
// internal `.then`; fall back to a bare settled toast (still flips out of the
|
|
122
|
+
// loading state) and dev-warn instead.
|
|
123
|
+
const resolveMessage = (fn, arg, label) => {
|
|
124
|
+
let out;
|
|
125
|
+
try {
|
|
126
|
+
out = typeof fn === 'function' ? fn(arg) : fn;
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
if (import.meta.env?.DEV)
|
|
130
|
+
console.warn(`[Toast] promise ${label} formatter threw:`, err);
|
|
131
|
+
}
|
|
132
|
+
return typeof out === 'string' ? { title: out } : out;
|
|
133
|
+
};
|
|
134
|
+
promise.then((value) => {
|
|
135
|
+
this.update(id, {
|
|
136
|
+
intent: 'success',
|
|
137
|
+
description: undefined,
|
|
138
|
+
...settled,
|
|
139
|
+
...resolveMessage(opts.success, value, 'success')
|
|
140
|
+
});
|
|
141
|
+
}, (reason) => {
|
|
142
|
+
this.update(id, {
|
|
143
|
+
intent: 'danger',
|
|
144
|
+
description: undefined,
|
|
145
|
+
...settled,
|
|
146
|
+
...resolveMessage(opts.error, reason, 'error')
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
return id;
|
|
150
|
+
}
|
|
61
151
|
/** Remove a single toast by ID. Clears its auto-dismiss timer. */
|
|
62
152
|
dismiss(id) {
|
|
63
153
|
const timer = this.timers.get(id);
|