ga-toasts 1.0.0 → 2.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 +21 -0
- package/README.md +327 -554
- package/dist/ga-toasts.css +608 -0
- package/dist/ga-toasts.global.js +2 -0
- package/dist/index.cjs +1242 -0
- package/dist/index.d.cts +247 -0
- package/dist/index.d.ts +247 -0
- package/dist/index.js +1235 -0
- package/package.json +85 -23
- package/.htaccess +0 -75
- package/REDIRECT_SETUP.md +0 -149
- package/ga-toasts.d.ts +0 -99
- package/images/gennie_logo.png +0 -0
- package/index.html +0 -1034
- package/robots.txt +0 -54
- package/sitemap.xml +0 -47
- package/src/demo.css +0 -698
- package/src/demo.js +0 -467
- package/src/toasts.css +0 -1644
- package/src/toasts.js +0 -1005
- package/src/variables.css +0 -480
- package/vercel.json +0 -50
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GA Toasts — modern, accessible, dependency-free toast notifications.
|
|
3
|
+
*
|
|
4
|
+
* Design goals of the 2.x rewrite:
|
|
5
|
+
* - Every toast owns its state (element, timer, listeners) in a registry, so
|
|
6
|
+
* closing/updating never leaves dangling timers or crashes.
|
|
7
|
+
* - Listeners are attached through a per-toast AbortController and torn down in
|
|
8
|
+
* one call — no `cloneNode` tricks.
|
|
9
|
+
* - Messages are rendered as text by default (`html: true` to opt into markup).
|
|
10
|
+
* - Screen readers are notified through a persistent `aria-live` region.
|
|
11
|
+
* - The stacked layout is computed in JS (a single transform per toast).
|
|
12
|
+
*
|
|
13
|
+
* Configurability (2.1): every instance is minted by `makeToaster(config)`.
|
|
14
|
+
* The default export `toast` is one such instance; `createToaster(config)`
|
|
15
|
+
* spins up isolated, independently-themed toasters (own registry, containers,
|
|
16
|
+
* theme, icons, defaults, mount root). Theming writes `--gat-*` custom
|
|
17
|
+
* properties through a per-instance scoped <style> so dark-mode rules still win.
|
|
18
|
+
*/
|
|
19
|
+
type ToastType = 'success' | 'error' | 'warning' | 'info' | 'primary' | 'secondary' | 'loading';
|
|
20
|
+
type ToastPosition = 'top-start' | 'top-center' | 'top-end' | 'middle-start' | 'middle-center' | 'middle-end' | 'bottom-start' | 'bottom-center' | 'bottom-end';
|
|
21
|
+
type ToastAnimation = 'fade' | 'slide' | 'bounce' | 'scale';
|
|
22
|
+
type ToastVariant = '' | 'filled' | 'light';
|
|
23
|
+
type ToastSize = '' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
24
|
+
type ToastProgressPosition = 'top' | 'bottom' | 'none';
|
|
25
|
+
interface ToastAction {
|
|
26
|
+
text: string;
|
|
27
|
+
/** Extra class(es) for the button. */
|
|
28
|
+
className?: string;
|
|
29
|
+
/** @deprecated use `className` */
|
|
30
|
+
class?: string;
|
|
31
|
+
/** Click handler; receives the event and the toast handle. */
|
|
32
|
+
onClick?: (event: MouseEvent, handle: ToastHandle) => void;
|
|
33
|
+
/** @deprecated use `onClick` */
|
|
34
|
+
click?: (event: MouseEvent, handle: ToastHandle) => void;
|
|
35
|
+
/** Close the toast automatically after the handler runs (default true). */
|
|
36
|
+
closeOnClick?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface ToastOptions {
|
|
39
|
+
/** Explicit id. If a toast with this id exists it is updated instead of duplicated. */
|
|
40
|
+
id?: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
message?: string;
|
|
43
|
+
/** Small muted line above the message (e.g. a timestamp). */
|
|
44
|
+
meta?: string;
|
|
45
|
+
type?: ToastType;
|
|
46
|
+
/** Auto-close delay in ms. `0` (or negative) means the toast is sticky. */
|
|
47
|
+
duration?: number;
|
|
48
|
+
closable?: boolean;
|
|
49
|
+
position?: ToastPosition;
|
|
50
|
+
/** Custom icon markup, or `false`/`null` to hide the icon entirely. */
|
|
51
|
+
icon?: string | null | false;
|
|
52
|
+
actions?: ToastAction[];
|
|
53
|
+
size?: ToastSize;
|
|
54
|
+
variant?: ToastVariant;
|
|
55
|
+
animation?: ToastAnimation;
|
|
56
|
+
/** Treat the whole toast as a button that closes on click. */
|
|
57
|
+
clickToClose?: boolean;
|
|
58
|
+
/** Allow dismissing by dragging horizontally (pointer/touch). Default true. */
|
|
59
|
+
swipeToClose?: boolean;
|
|
60
|
+
/** Render `message` as HTML instead of escaped text. Default false. */
|
|
61
|
+
html?: boolean;
|
|
62
|
+
/** Avatar image URL shown before the title. */
|
|
63
|
+
avatar?: string | null;
|
|
64
|
+
avatarAlt?: string;
|
|
65
|
+
/** Show an unread dot. */
|
|
66
|
+
unread?: boolean;
|
|
67
|
+
truncateTitle?: boolean;
|
|
68
|
+
/** Show the countdown progress bar. Default true. */
|
|
69
|
+
progress?: boolean;
|
|
70
|
+
progressPosition?: ToastProgressPosition;
|
|
71
|
+
/** Pause the countdown while hovered/focused. Default true. */
|
|
72
|
+
pauseOnHover?: boolean;
|
|
73
|
+
/** Pause the countdown while the tab is backgrounded. Default true. */
|
|
74
|
+
pauseOnPageHidden?: boolean;
|
|
75
|
+
/** Dismiss the newest toast when Escape is pressed. Default true. */
|
|
76
|
+
closeOnEscape?: boolean;
|
|
77
|
+
/** Denser layout with reduced padding. */
|
|
78
|
+
compact?: boolean;
|
|
79
|
+
/** Show a small status chip (defaults to the capitalized type). */
|
|
80
|
+
showStatus?: boolean;
|
|
81
|
+
statusText?: string;
|
|
82
|
+
/** Automatically pick an icon based on `type`. Default true. */
|
|
83
|
+
autoIcon?: boolean;
|
|
84
|
+
/** Frosted-glass background. Default true. */
|
|
85
|
+
glassmorphism?: boolean;
|
|
86
|
+
/** Segmented progress: total steps. */
|
|
87
|
+
steps?: number;
|
|
88
|
+
/** Segmented progress: current (1-based) step. */
|
|
89
|
+
currentStep?: number;
|
|
90
|
+
/** Extra class name(s) added to the toast root. */
|
|
91
|
+
className?: string;
|
|
92
|
+
/** ARIA role. Defaults to `alert` for error/warning, `status` otherwise. */
|
|
93
|
+
role?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Arbitrary content instead of the default title/message layout. A string is
|
|
96
|
+
* inserted as HTML (dev-authored, so trusted); an element/function is used as-is.
|
|
97
|
+
*/
|
|
98
|
+
content?: string | HTMLElement | (() => HTMLElement | string);
|
|
99
|
+
/**
|
|
100
|
+
* Move keyboard focus into the toast when shown and restore it on close.
|
|
101
|
+
* Used by `confirm()`; opt in for other actionable toasts.
|
|
102
|
+
*/
|
|
103
|
+
moveFocus?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Render as a modal: a backdrop blocks the rest of the page and focus is
|
|
106
|
+
* trapped until an action is taken. Only one modal toast can be open at a
|
|
107
|
+
* time — further modal calls are ignored until it closes. Used by `confirm()`.
|
|
108
|
+
*/
|
|
109
|
+
modal?: boolean;
|
|
110
|
+
onShow?: (handle: ToastHandle) => void;
|
|
111
|
+
onClose?: (handle: ToastHandle) => void;
|
|
112
|
+
}
|
|
113
|
+
interface ConfirmOptions extends ToastOptions {
|
|
114
|
+
confirmText?: string;
|
|
115
|
+
cancelText?: string;
|
|
116
|
+
onConfirm?: () => void;
|
|
117
|
+
onCancel?: () => void;
|
|
118
|
+
}
|
|
119
|
+
interface PromiseMessages<T> {
|
|
120
|
+
loading: string;
|
|
121
|
+
success: string | ((value: T) => string);
|
|
122
|
+
error: string | ((error: unknown) => string);
|
|
123
|
+
}
|
|
124
|
+
/** Handle returned from every toast; lets you update or close it later. */
|
|
125
|
+
interface ToastHandle {
|
|
126
|
+
readonly id: string;
|
|
127
|
+
readonly el: HTMLElement;
|
|
128
|
+
update(options: Partial<ToastOptions>): ToastHandle;
|
|
129
|
+
close(): void;
|
|
130
|
+
}
|
|
131
|
+
type PresetName = 'soft' | 'solid' | 'minimal' | 'sharp' | 'material';
|
|
132
|
+
/** Design tokens. Any omitted key keeps its default. Numbers → px where sensible. */
|
|
133
|
+
interface ThemeTokens {
|
|
134
|
+
/** Start from a named preset, then override with the tokens below. */
|
|
135
|
+
preset?: PresetName;
|
|
136
|
+
width?: number | string;
|
|
137
|
+
radius?: number | string;
|
|
138
|
+
gap?: number | string;
|
|
139
|
+
edge?: number | string;
|
|
140
|
+
font?: string;
|
|
141
|
+
/** Padding + font-size scale. */
|
|
142
|
+
density?: 'compact' | 'comfortable' | 'spacious';
|
|
143
|
+
/** Shadow depth preset. */
|
|
144
|
+
elevation?: 'flat' | 'raised' | 'floating';
|
|
145
|
+
/** Card background style. */
|
|
146
|
+
surface?: 'glass' | 'solid' | 'outline';
|
|
147
|
+
/** Width of the colored leading accent bar (0 = none). */
|
|
148
|
+
accentEdge?: number | string;
|
|
149
|
+
/** Countdown indicator style. */
|
|
150
|
+
progress?: 'bar' | 'ring' | 'none';
|
|
151
|
+
/** Primary accent (maps to the `primary` type + generic accents). */
|
|
152
|
+
accent?: string;
|
|
153
|
+
/** Per-type accent colors. */
|
|
154
|
+
colors?: Partial<Record<ToastType, string>>;
|
|
155
|
+
text?: string;
|
|
156
|
+
textSoft?: string;
|
|
157
|
+
textMuted?: string;
|
|
158
|
+
/** Card surface color (sets both frosted + solid tokens). */
|
|
159
|
+
surfaceColor?: string;
|
|
160
|
+
border?: string;
|
|
161
|
+
shadow?: string;
|
|
162
|
+
chip?: string;
|
|
163
|
+
ease?: string;
|
|
164
|
+
/** Token overrides applied only under the dark theme. */
|
|
165
|
+
dark?: Partial<ThemeTokens>;
|
|
166
|
+
}
|
|
167
|
+
interface StackConfig {
|
|
168
|
+
/** px each stacked card peeks out when collapsed. */
|
|
169
|
+
peek?: number;
|
|
170
|
+
/** px gap between cards when expanded. */
|
|
171
|
+
gap?: number;
|
|
172
|
+
/** per-index scale reduction when collapsed (default 0.05). */
|
|
173
|
+
scaleStep?: number;
|
|
174
|
+
/** When the stack fans out. `hover` (default), `always`, or `never`. */
|
|
175
|
+
expand?: 'hover' | 'always' | 'never';
|
|
176
|
+
/** Reverse stacking so the newest sits at the back. */
|
|
177
|
+
newestOnTop?: boolean;
|
|
178
|
+
}
|
|
179
|
+
interface RenderContext {
|
|
180
|
+
id: string;
|
|
181
|
+
close: () => void;
|
|
182
|
+
}
|
|
183
|
+
interface ToasterConfig {
|
|
184
|
+
/** Options merged into every toast (per-toast options still win). */
|
|
185
|
+
defaults?: ToastOptions;
|
|
186
|
+
/** Per-type default auto-close duration in ms. */
|
|
187
|
+
durations?: Partial<Record<ToastType, number>>;
|
|
188
|
+
/** Theme tokens or a named preset. */
|
|
189
|
+
theme?: ThemeTokens | PresetName;
|
|
190
|
+
/** Replace built-in icons (per type, `null` to hide) and/or the close icon. */
|
|
191
|
+
icons?: Partial<Record<ToastType, string | null>> & {
|
|
192
|
+
close?: string;
|
|
193
|
+
};
|
|
194
|
+
/** How many stacked toasts stay visible per position (default 3). */
|
|
195
|
+
maxVisible?: number;
|
|
196
|
+
/** Stacking geometry + behavior. */
|
|
197
|
+
stack?: StackConfig;
|
|
198
|
+
/** Replace the default toast body with your own element. */
|
|
199
|
+
render?: (opts: ToastOptions, ctx: RenderContext) => HTMLElement | void;
|
|
200
|
+
/** `false` → don't auto-inject CSS (ship your own / headless). Default true. */
|
|
201
|
+
injectStyles?: boolean;
|
|
202
|
+
/** Nonce set on the injected <style> for strict-CSP apps. */
|
|
203
|
+
styleNonce?: string;
|
|
204
|
+
/** Mount containers/live-regions/backdrop here (portals / shadow DOM). */
|
|
205
|
+
root?: HTMLElement | ShadowRoot;
|
|
206
|
+
/** Lifecycle/debug event sink. */
|
|
207
|
+
logger?: (event: string, payload: unknown) => void;
|
|
208
|
+
}
|
|
209
|
+
interface ToastFn {
|
|
210
|
+
(message: string, options?: ToastOptions): ToastHandle;
|
|
211
|
+
show: (options?: ToastOptions) => ToastHandle;
|
|
212
|
+
success: (message: string, options?: ToastOptions) => ToastHandle;
|
|
213
|
+
error: (message: string, options?: ToastOptions) => ToastHandle;
|
|
214
|
+
warning: (message: string, options?: ToastOptions) => ToastHandle;
|
|
215
|
+
info: (message: string, options?: ToastOptions) => ToastHandle;
|
|
216
|
+
loading: (message?: string, options?: ToastOptions) => ToastHandle;
|
|
217
|
+
confirm: (message: string, options?: ConfirmOptions) => ToastHandle;
|
|
218
|
+
promise: <T>(input: Promise<T> | (() => Promise<T>), messages: PromiseMessages<T>, options?: ToastOptions) => Promise<T>;
|
|
219
|
+
custom: (content: NonNullable<ToastOptions['content']>, options?: ToastOptions) => ToastHandle;
|
|
220
|
+
close: (target: string | HTMLElement | null | undefined) => void;
|
|
221
|
+
closeAll: () => void;
|
|
222
|
+
/** Alias of `close` — dismiss one toast by id. */
|
|
223
|
+
dismiss: (target: string | HTMLElement | null | undefined) => void;
|
|
224
|
+
/** Alias of `closeAll` — dismiss every toast. */
|
|
225
|
+
dismissAll: () => void;
|
|
226
|
+
clear: (type?: ToastType) => void;
|
|
227
|
+
update: (id: string, options: Partial<ToastOptions>) => ToastHandle | null;
|
|
228
|
+
get: (id: string) => HTMLElement | null;
|
|
229
|
+
exists: (id: string) => boolean;
|
|
230
|
+
getCount: (type?: ToastType) => number;
|
|
231
|
+
setDefaults: (defaults: ToastOptions) => void;
|
|
232
|
+
setMaxVisible: (count: number) => void;
|
|
233
|
+
setLogger: (fn: ((event: string, payload: unknown) => void) | null) => void;
|
|
234
|
+
/** Configure this toaster (defaults, theme, icons, stack, headless, …). */
|
|
235
|
+
configure: (cfg: ToasterConfig) => ToastFn;
|
|
236
|
+
/** Set theme tokens or a named preset. */
|
|
237
|
+
theme: (tokens: ThemeTokens | PresetName) => ToastFn;
|
|
238
|
+
injectStyles: () => void;
|
|
239
|
+
}
|
|
240
|
+
/** Create an isolated toaster with its own theme, defaults, icons and root. */
|
|
241
|
+
declare function createToaster(config?: ToasterConfig): ToastFn;
|
|
242
|
+
/** The default, globally-shared toaster. */
|
|
243
|
+
declare const toast: ToastFn;
|
|
244
|
+
/** Named object API, backwards-compatible with GA Toasts 1.x. */
|
|
245
|
+
declare const GaToasts: ToastFn;
|
|
246
|
+
|
|
247
|
+
export { type ConfirmOptions, GaToasts, type PresetName, type PromiseMessages, type RenderContext, type StackConfig, type ThemeTokens, type ToastAction, type ToastAnimation, type ToastFn, type ToastHandle, type ToastOptions, type ToastPosition, type ToastProgressPosition, type ToastSize, type ToastType, type ToastVariant, type ToasterConfig, createToaster, toast as default, toast };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GA Toasts — modern, accessible, dependency-free toast notifications.
|
|
3
|
+
*
|
|
4
|
+
* Design goals of the 2.x rewrite:
|
|
5
|
+
* - Every toast owns its state (element, timer, listeners) in a registry, so
|
|
6
|
+
* closing/updating never leaves dangling timers or crashes.
|
|
7
|
+
* - Listeners are attached through a per-toast AbortController and torn down in
|
|
8
|
+
* one call — no `cloneNode` tricks.
|
|
9
|
+
* - Messages are rendered as text by default (`html: true` to opt into markup).
|
|
10
|
+
* - Screen readers are notified through a persistent `aria-live` region.
|
|
11
|
+
* - The stacked layout is computed in JS (a single transform per toast).
|
|
12
|
+
*
|
|
13
|
+
* Configurability (2.1): every instance is minted by `makeToaster(config)`.
|
|
14
|
+
* The default export `toast` is one such instance; `createToaster(config)`
|
|
15
|
+
* spins up isolated, independently-themed toasters (own registry, containers,
|
|
16
|
+
* theme, icons, defaults, mount root). Theming writes `--gat-*` custom
|
|
17
|
+
* properties through a per-instance scoped <style> so dark-mode rules still win.
|
|
18
|
+
*/
|
|
19
|
+
type ToastType = 'success' | 'error' | 'warning' | 'info' | 'primary' | 'secondary' | 'loading';
|
|
20
|
+
type ToastPosition = 'top-start' | 'top-center' | 'top-end' | 'middle-start' | 'middle-center' | 'middle-end' | 'bottom-start' | 'bottom-center' | 'bottom-end';
|
|
21
|
+
type ToastAnimation = 'fade' | 'slide' | 'bounce' | 'scale';
|
|
22
|
+
type ToastVariant = '' | 'filled' | 'light';
|
|
23
|
+
type ToastSize = '' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
24
|
+
type ToastProgressPosition = 'top' | 'bottom' | 'none';
|
|
25
|
+
interface ToastAction {
|
|
26
|
+
text: string;
|
|
27
|
+
/** Extra class(es) for the button. */
|
|
28
|
+
className?: string;
|
|
29
|
+
/** @deprecated use `className` */
|
|
30
|
+
class?: string;
|
|
31
|
+
/** Click handler; receives the event and the toast handle. */
|
|
32
|
+
onClick?: (event: MouseEvent, handle: ToastHandle) => void;
|
|
33
|
+
/** @deprecated use `onClick` */
|
|
34
|
+
click?: (event: MouseEvent, handle: ToastHandle) => void;
|
|
35
|
+
/** Close the toast automatically after the handler runs (default true). */
|
|
36
|
+
closeOnClick?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface ToastOptions {
|
|
39
|
+
/** Explicit id. If a toast with this id exists it is updated instead of duplicated. */
|
|
40
|
+
id?: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
message?: string;
|
|
43
|
+
/** Small muted line above the message (e.g. a timestamp). */
|
|
44
|
+
meta?: string;
|
|
45
|
+
type?: ToastType;
|
|
46
|
+
/** Auto-close delay in ms. `0` (or negative) means the toast is sticky. */
|
|
47
|
+
duration?: number;
|
|
48
|
+
closable?: boolean;
|
|
49
|
+
position?: ToastPosition;
|
|
50
|
+
/** Custom icon markup, or `false`/`null` to hide the icon entirely. */
|
|
51
|
+
icon?: string | null | false;
|
|
52
|
+
actions?: ToastAction[];
|
|
53
|
+
size?: ToastSize;
|
|
54
|
+
variant?: ToastVariant;
|
|
55
|
+
animation?: ToastAnimation;
|
|
56
|
+
/** Treat the whole toast as a button that closes on click. */
|
|
57
|
+
clickToClose?: boolean;
|
|
58
|
+
/** Allow dismissing by dragging horizontally (pointer/touch). Default true. */
|
|
59
|
+
swipeToClose?: boolean;
|
|
60
|
+
/** Render `message` as HTML instead of escaped text. Default false. */
|
|
61
|
+
html?: boolean;
|
|
62
|
+
/** Avatar image URL shown before the title. */
|
|
63
|
+
avatar?: string | null;
|
|
64
|
+
avatarAlt?: string;
|
|
65
|
+
/** Show an unread dot. */
|
|
66
|
+
unread?: boolean;
|
|
67
|
+
truncateTitle?: boolean;
|
|
68
|
+
/** Show the countdown progress bar. Default true. */
|
|
69
|
+
progress?: boolean;
|
|
70
|
+
progressPosition?: ToastProgressPosition;
|
|
71
|
+
/** Pause the countdown while hovered/focused. Default true. */
|
|
72
|
+
pauseOnHover?: boolean;
|
|
73
|
+
/** Pause the countdown while the tab is backgrounded. Default true. */
|
|
74
|
+
pauseOnPageHidden?: boolean;
|
|
75
|
+
/** Dismiss the newest toast when Escape is pressed. Default true. */
|
|
76
|
+
closeOnEscape?: boolean;
|
|
77
|
+
/** Denser layout with reduced padding. */
|
|
78
|
+
compact?: boolean;
|
|
79
|
+
/** Show a small status chip (defaults to the capitalized type). */
|
|
80
|
+
showStatus?: boolean;
|
|
81
|
+
statusText?: string;
|
|
82
|
+
/** Automatically pick an icon based on `type`. Default true. */
|
|
83
|
+
autoIcon?: boolean;
|
|
84
|
+
/** Frosted-glass background. Default true. */
|
|
85
|
+
glassmorphism?: boolean;
|
|
86
|
+
/** Segmented progress: total steps. */
|
|
87
|
+
steps?: number;
|
|
88
|
+
/** Segmented progress: current (1-based) step. */
|
|
89
|
+
currentStep?: number;
|
|
90
|
+
/** Extra class name(s) added to the toast root. */
|
|
91
|
+
className?: string;
|
|
92
|
+
/** ARIA role. Defaults to `alert` for error/warning, `status` otherwise. */
|
|
93
|
+
role?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Arbitrary content instead of the default title/message layout. A string is
|
|
96
|
+
* inserted as HTML (dev-authored, so trusted); an element/function is used as-is.
|
|
97
|
+
*/
|
|
98
|
+
content?: string | HTMLElement | (() => HTMLElement | string);
|
|
99
|
+
/**
|
|
100
|
+
* Move keyboard focus into the toast when shown and restore it on close.
|
|
101
|
+
* Used by `confirm()`; opt in for other actionable toasts.
|
|
102
|
+
*/
|
|
103
|
+
moveFocus?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Render as a modal: a backdrop blocks the rest of the page and focus is
|
|
106
|
+
* trapped until an action is taken. Only one modal toast can be open at a
|
|
107
|
+
* time — further modal calls are ignored until it closes. Used by `confirm()`.
|
|
108
|
+
*/
|
|
109
|
+
modal?: boolean;
|
|
110
|
+
onShow?: (handle: ToastHandle) => void;
|
|
111
|
+
onClose?: (handle: ToastHandle) => void;
|
|
112
|
+
}
|
|
113
|
+
interface ConfirmOptions extends ToastOptions {
|
|
114
|
+
confirmText?: string;
|
|
115
|
+
cancelText?: string;
|
|
116
|
+
onConfirm?: () => void;
|
|
117
|
+
onCancel?: () => void;
|
|
118
|
+
}
|
|
119
|
+
interface PromiseMessages<T> {
|
|
120
|
+
loading: string;
|
|
121
|
+
success: string | ((value: T) => string);
|
|
122
|
+
error: string | ((error: unknown) => string);
|
|
123
|
+
}
|
|
124
|
+
/** Handle returned from every toast; lets you update or close it later. */
|
|
125
|
+
interface ToastHandle {
|
|
126
|
+
readonly id: string;
|
|
127
|
+
readonly el: HTMLElement;
|
|
128
|
+
update(options: Partial<ToastOptions>): ToastHandle;
|
|
129
|
+
close(): void;
|
|
130
|
+
}
|
|
131
|
+
type PresetName = 'soft' | 'solid' | 'minimal' | 'sharp' | 'material';
|
|
132
|
+
/** Design tokens. Any omitted key keeps its default. Numbers → px where sensible. */
|
|
133
|
+
interface ThemeTokens {
|
|
134
|
+
/** Start from a named preset, then override with the tokens below. */
|
|
135
|
+
preset?: PresetName;
|
|
136
|
+
width?: number | string;
|
|
137
|
+
radius?: number | string;
|
|
138
|
+
gap?: number | string;
|
|
139
|
+
edge?: number | string;
|
|
140
|
+
font?: string;
|
|
141
|
+
/** Padding + font-size scale. */
|
|
142
|
+
density?: 'compact' | 'comfortable' | 'spacious';
|
|
143
|
+
/** Shadow depth preset. */
|
|
144
|
+
elevation?: 'flat' | 'raised' | 'floating';
|
|
145
|
+
/** Card background style. */
|
|
146
|
+
surface?: 'glass' | 'solid' | 'outline';
|
|
147
|
+
/** Width of the colored leading accent bar (0 = none). */
|
|
148
|
+
accentEdge?: number | string;
|
|
149
|
+
/** Countdown indicator style. */
|
|
150
|
+
progress?: 'bar' | 'ring' | 'none';
|
|
151
|
+
/** Primary accent (maps to the `primary` type + generic accents). */
|
|
152
|
+
accent?: string;
|
|
153
|
+
/** Per-type accent colors. */
|
|
154
|
+
colors?: Partial<Record<ToastType, string>>;
|
|
155
|
+
text?: string;
|
|
156
|
+
textSoft?: string;
|
|
157
|
+
textMuted?: string;
|
|
158
|
+
/** Card surface color (sets both frosted + solid tokens). */
|
|
159
|
+
surfaceColor?: string;
|
|
160
|
+
border?: string;
|
|
161
|
+
shadow?: string;
|
|
162
|
+
chip?: string;
|
|
163
|
+
ease?: string;
|
|
164
|
+
/** Token overrides applied only under the dark theme. */
|
|
165
|
+
dark?: Partial<ThemeTokens>;
|
|
166
|
+
}
|
|
167
|
+
interface StackConfig {
|
|
168
|
+
/** px each stacked card peeks out when collapsed. */
|
|
169
|
+
peek?: number;
|
|
170
|
+
/** px gap between cards when expanded. */
|
|
171
|
+
gap?: number;
|
|
172
|
+
/** per-index scale reduction when collapsed (default 0.05). */
|
|
173
|
+
scaleStep?: number;
|
|
174
|
+
/** When the stack fans out. `hover` (default), `always`, or `never`. */
|
|
175
|
+
expand?: 'hover' | 'always' | 'never';
|
|
176
|
+
/** Reverse stacking so the newest sits at the back. */
|
|
177
|
+
newestOnTop?: boolean;
|
|
178
|
+
}
|
|
179
|
+
interface RenderContext {
|
|
180
|
+
id: string;
|
|
181
|
+
close: () => void;
|
|
182
|
+
}
|
|
183
|
+
interface ToasterConfig {
|
|
184
|
+
/** Options merged into every toast (per-toast options still win). */
|
|
185
|
+
defaults?: ToastOptions;
|
|
186
|
+
/** Per-type default auto-close duration in ms. */
|
|
187
|
+
durations?: Partial<Record<ToastType, number>>;
|
|
188
|
+
/** Theme tokens or a named preset. */
|
|
189
|
+
theme?: ThemeTokens | PresetName;
|
|
190
|
+
/** Replace built-in icons (per type, `null` to hide) and/or the close icon. */
|
|
191
|
+
icons?: Partial<Record<ToastType, string | null>> & {
|
|
192
|
+
close?: string;
|
|
193
|
+
};
|
|
194
|
+
/** How many stacked toasts stay visible per position (default 3). */
|
|
195
|
+
maxVisible?: number;
|
|
196
|
+
/** Stacking geometry + behavior. */
|
|
197
|
+
stack?: StackConfig;
|
|
198
|
+
/** Replace the default toast body with your own element. */
|
|
199
|
+
render?: (opts: ToastOptions, ctx: RenderContext) => HTMLElement | void;
|
|
200
|
+
/** `false` → don't auto-inject CSS (ship your own / headless). Default true. */
|
|
201
|
+
injectStyles?: boolean;
|
|
202
|
+
/** Nonce set on the injected <style> for strict-CSP apps. */
|
|
203
|
+
styleNonce?: string;
|
|
204
|
+
/** Mount containers/live-regions/backdrop here (portals / shadow DOM). */
|
|
205
|
+
root?: HTMLElement | ShadowRoot;
|
|
206
|
+
/** Lifecycle/debug event sink. */
|
|
207
|
+
logger?: (event: string, payload: unknown) => void;
|
|
208
|
+
}
|
|
209
|
+
interface ToastFn {
|
|
210
|
+
(message: string, options?: ToastOptions): ToastHandle;
|
|
211
|
+
show: (options?: ToastOptions) => ToastHandle;
|
|
212
|
+
success: (message: string, options?: ToastOptions) => ToastHandle;
|
|
213
|
+
error: (message: string, options?: ToastOptions) => ToastHandle;
|
|
214
|
+
warning: (message: string, options?: ToastOptions) => ToastHandle;
|
|
215
|
+
info: (message: string, options?: ToastOptions) => ToastHandle;
|
|
216
|
+
loading: (message?: string, options?: ToastOptions) => ToastHandle;
|
|
217
|
+
confirm: (message: string, options?: ConfirmOptions) => ToastHandle;
|
|
218
|
+
promise: <T>(input: Promise<T> | (() => Promise<T>), messages: PromiseMessages<T>, options?: ToastOptions) => Promise<T>;
|
|
219
|
+
custom: (content: NonNullable<ToastOptions['content']>, options?: ToastOptions) => ToastHandle;
|
|
220
|
+
close: (target: string | HTMLElement | null | undefined) => void;
|
|
221
|
+
closeAll: () => void;
|
|
222
|
+
/** Alias of `close` — dismiss one toast by id. */
|
|
223
|
+
dismiss: (target: string | HTMLElement | null | undefined) => void;
|
|
224
|
+
/** Alias of `closeAll` — dismiss every toast. */
|
|
225
|
+
dismissAll: () => void;
|
|
226
|
+
clear: (type?: ToastType) => void;
|
|
227
|
+
update: (id: string, options: Partial<ToastOptions>) => ToastHandle | null;
|
|
228
|
+
get: (id: string) => HTMLElement | null;
|
|
229
|
+
exists: (id: string) => boolean;
|
|
230
|
+
getCount: (type?: ToastType) => number;
|
|
231
|
+
setDefaults: (defaults: ToastOptions) => void;
|
|
232
|
+
setMaxVisible: (count: number) => void;
|
|
233
|
+
setLogger: (fn: ((event: string, payload: unknown) => void) | null) => void;
|
|
234
|
+
/** Configure this toaster (defaults, theme, icons, stack, headless, …). */
|
|
235
|
+
configure: (cfg: ToasterConfig) => ToastFn;
|
|
236
|
+
/** Set theme tokens or a named preset. */
|
|
237
|
+
theme: (tokens: ThemeTokens | PresetName) => ToastFn;
|
|
238
|
+
injectStyles: () => void;
|
|
239
|
+
}
|
|
240
|
+
/** Create an isolated toaster with its own theme, defaults, icons and root. */
|
|
241
|
+
declare function createToaster(config?: ToasterConfig): ToastFn;
|
|
242
|
+
/** The default, globally-shared toaster. */
|
|
243
|
+
declare const toast: ToastFn;
|
|
244
|
+
/** Named object API, backwards-compatible with GA Toasts 1.x. */
|
|
245
|
+
declare const GaToasts: ToastFn;
|
|
246
|
+
|
|
247
|
+
export { type ConfirmOptions, GaToasts, type PresetName, type PromiseMessages, type RenderContext, type StackConfig, type ThemeTokens, type ToastAction, type ToastAnimation, type ToastFn, type ToastHandle, type ToastOptions, type ToastPosition, type ToastProgressPosition, type ToastSize, type ToastType, type ToastVariant, type ToasterConfig, createToaster, toast as default, toast };
|