@t007/toast 0.0.23 → 0.0.24
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/README.md +80 -15
- package/dist/index.css +15 -10
- package/dist/index.d.ts +50 -118
- package/dist/index.global.js +114 -157
- package/dist/index.js +104 -151
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Features built-in SVG icons, custom actions, and smooth hardware-accelerated ani
|
|
|
53
53
|
|
|
54
54
|
- **9 Positioning Zones**: Anchor toasts anywhere on the screen (e.g., `top-right`, `bottom-center`, `center-center`).
|
|
55
55
|
- **Dynamic Updating**: Update the text, icon, or type of an active toast without breaking its animation loop.
|
|
56
|
-
- **Queue Management**: Strict enforcement of `
|
|
56
|
+
- **Queue Management**: Strict enforcement of `limit` and `renotify` to keep the UI clean.
|
|
57
57
|
- **Custom Hardware Vibrations**: Unique vibration patterns for different alert types (`success`, `error`, `warning`).
|
|
58
58
|
|
|
59
59
|
---
|
|
@@ -120,7 +120,7 @@ toast.promise(myFetch, {
|
|
|
120
120
|
|
|
121
121
|
### CDN / Browser (Global)
|
|
122
122
|
|
|
123
|
-
If you are not using a bundler, the library automatically injects itself into the global `t007` object and provides the convenient `window.
|
|
123
|
+
If you are not using a bundler, the library automatically injects itself into the global `t007` object and provides the convenient `window.toast` fallback.
|
|
124
124
|
|
|
125
125
|
```html
|
|
126
126
|
<!DOCTYPE html>
|
|
@@ -129,17 +129,12 @@ If you are not using a bundler, the library automatically injects itself into th
|
|
|
129
129
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.min.css">
|
|
130
130
|
</head>
|
|
131
131
|
<body>
|
|
132
|
-
|
|
133
132
|
<button id="notifyBtn">Show Toast</button>
|
|
134
133
|
|
|
135
134
|
<script src="https://cdn.jsdelivr.net/npm/@t007/toast@latest"></script>
|
|
136
|
-
|
|
137
135
|
<script>
|
|
138
136
|
document.getElementById('notifyBtn').addEventListener('click', () => {
|
|
139
|
-
|
|
140
|
-
pauseOnHover: true,
|
|
141
|
-
dragToClose: true
|
|
142
|
-
}); // or use `t007.toast -> t007.toast.info()`
|
|
137
|
+
toast.info("System running smoothly.", { pauseOnHover: true, dragToClose: true }); // or `t007.toast -> t007.toast.info()`
|
|
143
138
|
});
|
|
144
139
|
</script>
|
|
145
140
|
</body>
|
|
@@ -152,20 +147,20 @@ If you are not using a bundler, the library automatically injects itself into th
|
|
|
152
147
|
|
|
153
148
|
### Basic Toasts
|
|
154
149
|
|
|
155
|
-
Trigger toasts based on their severity. Returns the unique `id` of the generated toast.
|
|
150
|
+
Trigger toasts based on their severity. Returns the unique `id` of the generated toast. If first argument is an id, don't put `id` in options; it will be taken as a fallback `render`.
|
|
156
151
|
|
|
157
152
|
- `toast(render, options)` (Default / Info)
|
|
158
|
-
- `toast.info(
|
|
159
|
-
- `toast.success(
|
|
160
|
-
- `toast.warn(
|
|
161
|
-
- `toast.error(
|
|
153
|
+
- `toast.info(renderOrId, options)`
|
|
154
|
+
- `toast.success(renderOrId, options)`
|
|
155
|
+
- `toast.warn(renderOrId, options)`
|
|
156
|
+
- `toast.error(renderOrId, options)`
|
|
162
157
|
|
|
163
158
|
### Toast Updating
|
|
164
159
|
|
|
165
160
|
You can dynamically update a toast that is currently on the screen.
|
|
166
161
|
|
|
167
162
|
```javascript
|
|
168
|
-
const toastId = toast.loading("Processing...");
|
|
163
|
+
const toastId = toast.loading("Processing..."); // id is auto-generated reliably
|
|
169
164
|
|
|
170
165
|
// Later in your code...
|
|
171
166
|
toast.update(toastId, {
|
|
@@ -176,6 +171,18 @@ toast.update(toastId, {
|
|
|
176
171
|
});
|
|
177
172
|
```
|
|
178
173
|
|
|
174
|
+
### `id` Upsert vs `tag` + `renotify`
|
|
175
|
+
|
|
176
|
+
- `id` controls in-place replacement: if a toast with that same active id exists, the call updates it instead of creating a new one.
|
|
177
|
+
- `toast.update(id, options)` is explicit update; helper calls (`success`, `info`, etc.) also upsert when `options.id` matches an active toast.
|
|
178
|
+
- `tag` is a grouping key, not an update key.
|
|
179
|
+
- `renotify: true` + same `tag` removes other active toasts with that tag before showing the new one.
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
toast.success("Added to favorites", { id: `${tipId} favorite` }); // upsert by id, only if you can handle management
|
|
183
|
+
toast.info("Sync started", { tag: "sync", renotify: true }); // one active toast per tag
|
|
184
|
+
```
|
|
185
|
+
|
|
179
186
|
### Promise Handling
|
|
180
187
|
|
|
181
188
|
Automatically maps a JavaScript Promise to the lifecycle of a toast.
|
|
@@ -221,10 +228,68 @@ window.t007.TOAST_DEFAULT_OPTIONS.vibrate = true;
|
|
|
221
228
|
window.t007.TOAST_DURATIONS.error = 10000; // Leave errors up for 10 seconds
|
|
222
229
|
```
|
|
223
230
|
|
|
224
|
-
### CSS Variables
|
|
231
|
+
### CSS Selectors & Variables
|
|
225
232
|
|
|
226
233
|
You can easily override the progress bar, animations, and container spacing by targeting `.t007-toast` in your stylesheet.
|
|
227
234
|
|
|
235
|
+
#### Corporate Override Starter (Google-like)
|
|
236
|
+
|
|
237
|
+
Use generic brand tokens first, then map them to toast variables. This keeps your theme portable across projects.
|
|
238
|
+
|
|
239
|
+
```css
|
|
240
|
+
/* 1) Brand/system tokens (generic names) */
|
|
241
|
+
:root {
|
|
242
|
+
--app-surface: #ffffff;
|
|
243
|
+
--app-text: #202124;
|
|
244
|
+
--app-muted: #5f6368;
|
|
245
|
+
--app-muted-2: #9aa0a6;
|
|
246
|
+
}
|
|
247
|
+
/* 2) Map tokens to toast variables (theme layer) */
|
|
248
|
+
.t007-toast {
|
|
249
|
+
--t007-toast-type-color: var(--app-text);
|
|
250
|
+
--t007-toast-background: var(--app-surface);
|
|
251
|
+
--t007-toast-text-shadow: none;
|
|
252
|
+
--t007-toast-text-stroke: 0;
|
|
253
|
+
--t007-toast-x-color: var(--app-muted-2);
|
|
254
|
+
/* ...check source code for all variables... */
|
|
255
|
+
}
|
|
256
|
+
/* 3) Container sizing/layout layer */
|
|
257
|
+
.t007-toast-container {
|
|
258
|
+
--t007-toast-unit: 0.9rem;
|
|
259
|
+
--t007-toast-width: calc(var(--t007-toast-unit) * 25);
|
|
260
|
+
--t007-toast-min-height: 3.25rem;
|
|
261
|
+
--t007-toast-progress-height: calc(var(--t007-toast-unit) / 6);
|
|
262
|
+
--t007-toast-icon-width: calc(var(--t007-toast-unit) * 1.25);
|
|
263
|
+
--t007-toast-icon-height: calc(var(--t007-toast-unit) * 1.25);
|
|
264
|
+
--t007-toast-x-size: calc(var(--t007-toast-unit) * 1.5);
|
|
265
|
+
}
|
|
266
|
+
@media (max-width: 40rem) {
|
|
267
|
+
.t007-toast-container {
|
|
268
|
+
--t007-toast-unit: 0.95rem;
|
|
269
|
+
--t007-toast-container-margin: 16px;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
#### Specificity Note (Important)
|
|
275
|
+
|
|
276
|
+
- Start with `:root` for shared tokens.
|
|
277
|
+
- If a token does not apply, override directly on `.t007-toast` (visuals/colors).
|
|
278
|
+
- For sizing/layout variables, override `.t007-toast-container` (unit, width, icon size, margins).
|
|
279
|
+
- For strong app themes (e.g. `html[data-theme="dark"]`), use equal/stronger selectors on both `.t007-toast` and `.t007-toast-container`.
|
|
280
|
+
- Check source code for more details.
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
### Runtime Data Attributes
|
|
284
|
+
|
|
285
|
+
The library writes useful data attributes to toast DOM nodes at runtime:
|
|
286
|
+
|
|
287
|
+
- Toast root (`.t007-toast`): `data-group-id`, `data-animation`, `data-tag`, `data-drag-to-close`
|
|
288
|
+
- Container (`.t007-toast-container`): `data-position`
|
|
289
|
+
- Body text (`.t007-toast-body-text`): `data-render`
|
|
290
|
+
- Icon (`.t007-toast-icon`): `data-icon`
|
|
291
|
+
- Image (`.t007-toast-image`): `data-loaded`
|
|
292
|
+
-
|
|
228
293
|
-----
|
|
229
294
|
|
|
230
295
|
## Author
|
package/dist/index.css
CHANGED
|
@@ -35,11 +35,12 @@
|
|
|
35
35
|
}
|
|
36
36
|
:where(:root, .t007-toast-container) {
|
|
37
37
|
--t007-toast-unit: 1rem;
|
|
38
|
-
--t007-toast-container-margin
|
|
39
|
-
--t007-toast-container-margin-
|
|
40
|
-
--t007-toast-container-margin-
|
|
41
|
-
--t007-toast-container-margin-
|
|
42
|
-
--t007-toast-container-
|
|
38
|
+
--t007-toast-container-margin: calc(var(--t007-toast-unit) / 2);
|
|
39
|
+
--t007-toast-container-margin-top: var(--t007-toast-container-margin);
|
|
40
|
+
--t007-toast-container-margin-bottom: var(--t007-toast-container-margin);
|
|
41
|
+
--t007-toast-container-margin-left: var(--t007-toast-container-margin);
|
|
42
|
+
--t007-toast-container-margin-right: var(--t007-toast-container-margin);
|
|
43
|
+
--t007-toast-container-gap: var(--t007-toast-container-margin);
|
|
43
44
|
--t007-toast-min-width: unset;
|
|
44
45
|
--t007-toast-width: calc(var(--t007-toast-unit) * 20);
|
|
45
46
|
--t007-toast-max-width: 100%;
|
|
@@ -203,6 +204,10 @@
|
|
|
203
204
|
outline: var(--t007-toast-focus-visible-outline);
|
|
204
205
|
outline-offset: calc(var(--t007-toast-unit) / 7.5);
|
|
205
206
|
}
|
|
207
|
+
*:where(:has(> .t007-toast-container .t007-toast.t007-toast-scoped)) {
|
|
208
|
+
position: relative;
|
|
209
|
+
overflow: hidden;
|
|
210
|
+
}
|
|
206
211
|
.t007-toast-container {
|
|
207
212
|
position: var(--t007-toast-container-position);
|
|
208
213
|
margin-top: var(--t007-toast-container-margin-top);
|
|
@@ -330,21 +335,21 @@
|
|
|
330
335
|
.t007-toast[data-animation=zoom].t007-toast-show {
|
|
331
336
|
animation-name: t007-zoom-in;
|
|
332
337
|
}
|
|
333
|
-
.t007-toast:is(.info, .success, .error, .warning) {
|
|
338
|
+
.t007-toast-container .t007-toast:is(.info, .success, .error, .warning) {
|
|
334
339
|
--t007-toast-font-color: var(--t007-toast-type-color);
|
|
335
340
|
--t007-toast-progress-background: var(--t007-toast-type-color);
|
|
336
341
|
--t007-toast-progress-backdrop-background: rgb(from var(--t007-toast-type-color) r g b/0);
|
|
337
342
|
}
|
|
338
|
-
.t007-toast.info {
|
|
343
|
+
.t007-toast-container .t007-toast.info {
|
|
339
344
|
--t007-toast-type-color: var(--t007-toast-info-color);
|
|
340
345
|
}
|
|
341
|
-
.t007-toast.success {
|
|
346
|
+
.t007-toast-container .t007-toast.success {
|
|
342
347
|
--t007-toast-type-color: var(--t007-toast-success-color);
|
|
343
348
|
}
|
|
344
|
-
.t007-toast.error {
|
|
349
|
+
.t007-toast-container .t007-toast.error {
|
|
345
350
|
--t007-toast-type-color: var(--t007-toast-error-color);
|
|
346
351
|
}
|
|
347
|
-
.t007-toast.warning {
|
|
352
|
+
.t007-toast-container .t007-toast.warning {
|
|
348
353
|
--t007-toast-type-color: var(--t007-toast-warning-color);
|
|
349
354
|
}
|
|
350
355
|
.t007-toast.progress::before,
|
package/dist/index.d.ts
CHANGED
|
@@ -3,50 +3,18 @@ import "@t007/utils";
|
|
|
3
3
|
/** Toast severity level. */
|
|
4
4
|
export type ToastType = "info" | "success" | "error" | "warning";
|
|
5
5
|
/** Screen anchor for toast placement. */
|
|
6
|
-
export type ToastPosition =
|
|
7
|
-
| "top-left"
|
|
8
|
-
| "top-center"
|
|
9
|
-
| "top-right"
|
|
10
|
-
| "bottom-left"
|
|
11
|
-
| "bottom-center"
|
|
12
|
-
| "bottom-right"
|
|
13
|
-
| "center-left"
|
|
14
|
-
| "center-center"
|
|
15
|
-
| "center-right";
|
|
6
|
+
export type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "center-left" | "center-center" | "center-right";
|
|
16
7
|
/** Motion preset used when a toast enters or leaves the screen. */
|
|
17
|
-
export type ToastAnimation =
|
|
18
|
-
| "fade"
|
|
19
|
-
| "zoom"
|
|
20
|
-
| "slide"
|
|
21
|
-
| "slide-left"
|
|
22
|
-
| "slide-right"
|
|
23
|
-
| "slide-up"
|
|
24
|
-
| "slide-down"
|
|
25
|
-
| boolean;
|
|
8
|
+
export type ToastAnimation = "fade" | "zoom" | "slide" | "slide-left" | "slide-right" | "slide-up" | "slide-down" | boolean;
|
|
26
9
|
/** Allowed drag directions for dismiss gestures. */
|
|
27
|
-
export type ToastDragDir =
|
|
28
|
-
| "x"
|
|
29
|
-
| "y"
|
|
30
|
-
| "xy"
|
|
31
|
-
| "x|y"
|
|
32
|
-
| "x||y"
|
|
33
|
-
| "x+"
|
|
34
|
-
| "x-"
|
|
35
|
-
| "y+"
|
|
36
|
-
| "y-"
|
|
37
|
-
| "xy+"
|
|
38
|
-
| "xy-"
|
|
39
|
-
| "x|y+"
|
|
40
|
-
| "x|y-"
|
|
41
|
-
| "x||y+"
|
|
42
|
-
| "x||y-";
|
|
10
|
+
export type ToastDragDir = "x" | "y" | "xy" | "x|y" | "x||y" | "x+" | "x-" | "y+" | "y-" | "xy+" | "xy-" | "x|y+" | "x|y-" | "x||y+" | "x||y-";
|
|
43
11
|
|
|
44
12
|
/** Configuration object for creating and updating a toast. */
|
|
45
13
|
export interface ToastOptions {
|
|
46
|
-
/** Explicit toast id. */
|
|
14
|
+
/** Explicit toast id. Reusing an active id updates that toast in place (upsert-style), preserving position/animation state. */
|
|
47
15
|
id?: string;
|
|
48
16
|
/** Prefix used when ids are generated automatically. */
|
|
49
|
-
|
|
17
|
+
groupId?: string;
|
|
50
18
|
/** Delay before the toast is initialized. */
|
|
51
19
|
delay?: number | null;
|
|
52
20
|
/** Container element used to host toast stacks. */
|
|
@@ -73,6 +41,8 @@ export interface ToastOptions {
|
|
|
73
41
|
closeOnClick?: boolean;
|
|
74
42
|
/** Hide the progress bar. */
|
|
75
43
|
hideProgressBar?: boolean;
|
|
44
|
+
/** Manual progress value (0-1) used by the progress bar when set directly. */
|
|
45
|
+
nprogress?: number;
|
|
76
46
|
/** Pause auto-close while the pointer is over the toast. */
|
|
77
47
|
pauseOnHover?: boolean;
|
|
78
48
|
/** Pause auto-close while the document is hidden. */
|
|
@@ -83,9 +53,9 @@ export interface ToastOptions {
|
|
|
83
53
|
dragToClosePercent?: number | { x?: number; y?: number };
|
|
84
54
|
/** Axis or direction filter used by the drag gesture system. */
|
|
85
55
|
dragToCloseDir?: ToastDragDir;
|
|
86
|
-
/**
|
|
56
|
+
/** When true and `tag` is provided, any other active toast with the same tag is removed before this toast renders. */
|
|
87
57
|
renotify?: boolean;
|
|
88
|
-
/** Arbitrary tag used for grouping
|
|
58
|
+
/** Arbitrary tag used for grouping and renotify matching. Does not update by itself; pair with `renotify` to enforce one-toast-per-tag behavior. */
|
|
89
59
|
tag?: string | number;
|
|
90
60
|
/** Trigger vibration when the toast appears. */
|
|
91
61
|
vibrate?: boolean | number[];
|
|
@@ -94,7 +64,7 @@ export interface ToastOptions {
|
|
|
94
64
|
/** Put new toasts at the front of the stack. */
|
|
95
65
|
newestOnTop?: boolean;
|
|
96
66
|
/** Maximum number of toasts allowed in a container. */
|
|
97
|
-
|
|
67
|
+
limit?: number;
|
|
98
68
|
/** Action buttons rendered under the message body. */
|
|
99
69
|
actions?: Record<string, (e: MouseEvent, toast: ToastInstance) => void> | false;
|
|
100
70
|
/** Callback fired when the toast closes. */
|
|
@@ -106,18 +76,19 @@ export interface ToastOptions {
|
|
|
106
76
|
|
|
107
77
|
/** Live toast instance returned by the runtime. */
|
|
108
78
|
export interface ToastInstance {
|
|
109
|
-
/** Unique toast id. */
|
|
110
|
-
id: string;
|
|
111
79
|
/** Current option bag applied to the instance. */
|
|
112
80
|
opts: ToastOptions;
|
|
113
81
|
/** Pending timeouts waiting to apply queued updates. */
|
|
114
82
|
queue: number[];
|
|
115
|
-
/** Whether the toast
|
|
116
|
-
|
|
117
|
-
/** Root DOM node for the toast.
|
|
83
|
+
/** Whether the toast is active and in the DOM. */
|
|
84
|
+
inactive: boolean;
|
|
85
|
+
/** Root DOM node for the toast.
|
|
86
|
+
* Runtime datasets written here: `data-group-id`, `data-animation`, `data-tag`, `data-drag-to-close`.
|
|
87
|
+
* Related runtime datasets: container `data-position`, body text `data-render`, icon `data-icon`, image `data-loaded`.
|
|
88
|
+
*/
|
|
118
89
|
toastElement: HTMLElement;
|
|
119
|
-
/** Build the DOM node and
|
|
120
|
-
|
|
90
|
+
/** Build the DOM node and setup its lifecycle. */
|
|
91
|
+
activate(): void;
|
|
121
92
|
/** Apply new options and return the toast id.
|
|
122
93
|
* @param options Options to apply.
|
|
123
94
|
* @returns Toast id.
|
|
@@ -131,7 +102,7 @@ export interface ToastInstance {
|
|
|
131
102
|
* @param manner Removal mode.
|
|
132
103
|
* @param timeElapsed Whether the auto-close timer already elapsed.
|
|
133
104
|
*/
|
|
134
|
-
|
|
105
|
+
remove(manner?: "smooth" | "instant", timeElapsed?: boolean): void;
|
|
135
106
|
}
|
|
136
107
|
|
|
137
108
|
/** Promise state configuration used by toast.promise. */
|
|
@@ -141,7 +112,6 @@ export interface ToastPromiseState<T = any> extends Omit<ToastOptions, "render"
|
|
|
141
112
|
/** Render HTML for the promise state. */
|
|
142
113
|
bodyHTML?: string | ((response: T) => string);
|
|
143
114
|
}
|
|
144
|
-
|
|
145
115
|
/** Configuration object accepted by toast.promise. */
|
|
146
116
|
export interface ToastPromiseConfig<T = any> {
|
|
147
117
|
/** Pending-state text or options. */
|
|
@@ -160,6 +130,11 @@ export interface Toast {
|
|
|
160
130
|
* @returns Toast id.
|
|
161
131
|
*/
|
|
162
132
|
(render?: string, options?: ToastOptions): string;
|
|
133
|
+
/** Check if a toast is currently active.
|
|
134
|
+
* @param id Toast id.
|
|
135
|
+
* @returns True if the toast is active, false otherwise.
|
|
136
|
+
*/
|
|
137
|
+
isActive(id: string): boolean;
|
|
163
138
|
/** Update an existing toast by id.
|
|
164
139
|
* @param id Toast id.
|
|
165
140
|
* @param options Options to apply.
|
|
@@ -167,41 +142,41 @@ export interface Toast {
|
|
|
167
142
|
*/
|
|
168
143
|
update(id: string, options: ToastOptions): string | false;
|
|
169
144
|
/** Show an info toast.
|
|
170
|
-
* @param
|
|
145
|
+
* @param renderOrId Body text or toast id.
|
|
171
146
|
* @param options Toast configuration.
|
|
172
147
|
* @returns Toast id.
|
|
173
148
|
*/
|
|
174
|
-
info(
|
|
149
|
+
info(renderOrId?: string, options?: ToastOptions): string;
|
|
175
150
|
/** Show a success toast.
|
|
176
|
-
* @param
|
|
151
|
+
* @param renderOrId Body text or toast id.
|
|
177
152
|
* @param options Toast configuration.
|
|
178
153
|
* @returns Toast id.
|
|
179
154
|
*/
|
|
180
|
-
success(
|
|
155
|
+
success(renderOrId?: string, options?: ToastOptions): string;
|
|
181
156
|
/** Show a warning toast.
|
|
182
|
-
* @param
|
|
157
|
+
* @param renderOrId Body text or toast id.
|
|
183
158
|
* @param options Toast configuration.
|
|
184
159
|
* @returns Toast id.
|
|
185
160
|
*/
|
|
186
|
-
warn(
|
|
161
|
+
warn(renderOrId?: string, options?: ToastOptions): string;
|
|
187
162
|
/** Show an error toast.
|
|
188
|
-
* @param
|
|
163
|
+
* @param renderOrId Body text or toast id.
|
|
189
164
|
* @param options Toast configuration.
|
|
190
165
|
* @returns Toast id.
|
|
191
166
|
*/
|
|
192
|
-
error(
|
|
167
|
+
error(renderOrId?: string, options?: ToastOptions): string;
|
|
193
168
|
/** Show a loading toast.
|
|
194
|
-
* @param
|
|
169
|
+
* @param renderOrId Body text or toast id.
|
|
195
170
|
* @param options Toast configuration.
|
|
196
171
|
* @returns Toast id.
|
|
197
172
|
*/
|
|
198
|
-
loading(
|
|
173
|
+
loading(renderOrId?: string, options?: ToastOptions): string;
|
|
199
174
|
/** Bind a promise to the toast lifecycle.
|
|
200
175
|
* @param promise Promise to observe.
|
|
201
176
|
* @param options Pending, success, and error states.
|
|
202
177
|
* @returns The original promise.
|
|
203
178
|
*/
|
|
204
|
-
promise<T>(promise: Promise<T>,
|
|
179
|
+
promise<T>(promise: Promise<T>, config?: ToastPromiseConfig<T>): Promise<T>;
|
|
205
180
|
/** Dismiss a single toast or the whole stack.
|
|
206
181
|
* @param id Toast id to dismiss.
|
|
207
182
|
* @param manner Removal mode.
|
|
@@ -209,88 +184,45 @@ export interface Toast {
|
|
|
209
184
|
*/
|
|
210
185
|
dismiss(id?: string, manner?: "smooth" | "instant", timeElapsed?: boolean): void;
|
|
211
186
|
/** Dismiss every toast that matches an optional prefix.
|
|
212
|
-
* @param
|
|
187
|
+
* @param groupId Optional id prefix filter.
|
|
213
188
|
*/
|
|
214
|
-
dismissAll(
|
|
189
|
+
dismissAll(groupId?: string): void;
|
|
215
190
|
/** Run an action against every matching toast instance.
|
|
216
191
|
* @param action Instance method to invoke.
|
|
217
192
|
* @param options Options forwarded to the instance method.
|
|
218
|
-
* @param
|
|
193
|
+
* @param groupId Optional id prefix filter.
|
|
219
194
|
*/
|
|
220
|
-
doForAll(action: string, options?: any,
|
|
195
|
+
doForAll(action: string, options?: any, groupId?: string): void;
|
|
221
196
|
/** Return every matching toast instance.
|
|
222
|
-
* @param
|
|
197
|
+
* @param groupId Optional id prefix filter.
|
|
223
198
|
* @returns Matching toast instances.
|
|
224
199
|
*/
|
|
225
|
-
getAll(
|
|
200
|
+
getAll(groupId?: string): ToastInstance[];
|
|
226
201
|
}
|
|
227
202
|
|
|
228
203
|
/** Helper methods used internally by toaster() and promise flows. */
|
|
229
204
|
export interface Toasting {
|
|
230
|
-
|
|
231
|
-
* @param base Toast factory to use.
|
|
232
|
-
* @param id Toast id.
|
|
233
|
-
* @param options Options to apply.
|
|
234
|
-
* @returns Updated id or false when no toast exists.
|
|
235
|
-
*/
|
|
205
|
+
isActive(base: Toast, id: string): boolean;
|
|
236
206
|
update(base: Toast, id: string, options: ToastOptions): boolean | string;
|
|
237
|
-
|
|
238
|
-
* @param base Toast factory to extend.
|
|
239
|
-
* @param defaults Default option factory.
|
|
240
|
-
* @param action Helper name to create.
|
|
241
|
-
*/
|
|
242
|
-
message(base: Toast, defaults: () => ToastOptions, action: string): void;
|
|
243
|
-
/** Create a loading toast from an id or a message.
|
|
244
|
-
* @param base Toast factory to use.
|
|
245
|
-
* @param renderOrId Toast id or loading text.
|
|
246
|
-
* @param options Loading options.
|
|
247
|
-
* @returns Toast id.
|
|
248
|
-
*/
|
|
207
|
+
message(base: Toast, getDefaults: () => ToastOptions, action: string, renderOrId: string, options?: ToastOptions): string;
|
|
249
208
|
loading(base: Toast, renderOrId: string, options?: ToastOptions): string;
|
|
250
|
-
/** Bind promise resolution states to an active toast.
|
|
251
|
-
* @param base Toast factory to use.
|
|
252
|
-
* @param promise Promise to observe.
|
|
253
|
-
* @param config Promise state configuration.
|
|
254
|
-
* @returns The original promise.
|
|
255
|
-
*/
|
|
256
209
|
promise<T>(base: Toast, promise: Promise<T>, config?: ToastPromiseConfig<T>): Promise<T>;
|
|
257
|
-
/** Dismiss a toast by id or clear all matching toasts.
|
|
258
|
-
* @param base Toast factory to use.
|
|
259
|
-
* @param id Toast id.
|
|
260
|
-
* @param manner Removal mode.
|
|
261
|
-
* @param timeElapsed Whether the auto-close timer already elapsed.
|
|
262
|
-
*/
|
|
263
210
|
dismiss(base: Toast, id?: string, manner?: string, timeElapsed?: boolean): void;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
*/
|
|
268
|
-
dismissAll(base: Toast, idPrefix?: string): void;
|
|
269
|
-
/** Run a method on every matching toast instance.
|
|
270
|
-
* @param base Toast factory to use.
|
|
271
|
-
* @param action Instance method to invoke.
|
|
272
|
-
* @param options Options forwarded to the instance method.
|
|
273
|
-
* @param idPrefix Optional id prefix filter.
|
|
274
|
-
*/
|
|
275
|
-
doForAll(base: Toast, action: string, options?: any, idPrefix?: string): void;
|
|
276
|
-
/** Return every matching toast instance.
|
|
277
|
-
* @param base Toast factory to use.
|
|
278
|
-
* @param idPrefix Optional id prefix filter.
|
|
279
|
-
* @returns Matching toast instances.
|
|
280
|
-
*/
|
|
281
|
-
getAll(base: Toast, idPrefix?: string): ToastInstance[];
|
|
211
|
+
dismissAll(base: Toast, groupId?: string): void;
|
|
212
|
+
doForAll(base: Toast, action: string, options?: any, groupId?: string): void;
|
|
213
|
+
getAll(base: Toast, groupId?: string): ToastInstance[];
|
|
282
214
|
}
|
|
283
215
|
|
|
284
216
|
// BUNDLE EXPORTS & GLOBAL DECLARATIONS
|
|
285
217
|
|
|
286
218
|
/** Internal helper methods used by the toast factory. */
|
|
287
219
|
export const toasting: Toasting;
|
|
288
|
-
/** Create a toast factory with custom defaults.
|
|
220
|
+
/** Create a toast factory with custom defaults and a group id.
|
|
289
221
|
* @param defOptions Default options merged into every toast.
|
|
290
|
-
* @param
|
|
222
|
+
* @param groupId Prefix applied to generated ids.
|
|
291
223
|
* @returns Toast factory.
|
|
292
224
|
*/
|
|
293
|
-
export function toaster(defOptions?: ToastOptions,
|
|
225
|
+
export function toaster(defOptions?: ToastOptions, groupId?: string): Toast;
|
|
294
226
|
/** Default toast factory instance attached by the bundle. */
|
|
295
227
|
declare const toast: Toast;
|
|
296
228
|
export default toast;
|
|
@@ -315,6 +247,6 @@ declare global {
|
|
|
315
247
|
TOAST_ICONS: Record<ToastType | "loading", string>;
|
|
316
248
|
}
|
|
317
249
|
interface Window {
|
|
318
|
-
|
|
250
|
+
toast?: Toast;
|
|
319
251
|
}
|
|
320
252
|
}
|