@zag-js/toast 0.82.2 → 1.0.1
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/index.d.mts +198 -134
- package/dist/index.d.ts +198 -134
- package/dist/index.js +757 -624
- package/dist/index.mjs +757 -625
- package/package.json +15 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import { CommonProperties, Direction, RequiredBy, PropTypes, DirectionProperty, NormalizeProps } from '@zag-js/types';
|
|
2
1
|
import * as _zag_js_core from '@zag-js/core';
|
|
3
|
-
import { Machine,
|
|
2
|
+
import { Service, Machine, EventObject } from '@zag-js/core';
|
|
3
|
+
import { CommonProperties, Direction, DirectionProperty, Required, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
|
|
4
4
|
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
5
5
|
|
|
6
6
|
type Type = "success" | "error" | "loading" | "info" | (string & {});
|
|
7
7
|
type Placement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end";
|
|
8
8
|
type Status = "visible" | "dismissing" | "unmounted";
|
|
9
|
-
interface
|
|
9
|
+
interface StatusChangeDetails {
|
|
10
10
|
/**
|
|
11
|
-
* The
|
|
11
|
+
* The status of the toast
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
status: Status;
|
|
14
14
|
/**
|
|
15
|
-
* The
|
|
15
|
+
* The reason for the status change
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
src?: string | undefined;
|
|
18
18
|
}
|
|
19
|
-
interface
|
|
20
|
-
|
|
19
|
+
interface ToastHeight {
|
|
20
|
+
/**
|
|
21
|
+
* The id of the toast
|
|
22
|
+
*/
|
|
23
|
+
id: string;
|
|
24
|
+
/**
|
|
25
|
+
* The height of the toast
|
|
26
|
+
*/
|
|
27
|
+
height: number;
|
|
21
28
|
}
|
|
22
29
|
interface ActionOptions {
|
|
23
30
|
/**
|
|
@@ -29,7 +36,15 @@ interface ActionOptions {
|
|
|
29
36
|
*/
|
|
30
37
|
onClick: () => void;
|
|
31
38
|
}
|
|
32
|
-
interface Options<T
|
|
39
|
+
interface Options<T = any> {
|
|
40
|
+
/**
|
|
41
|
+
* The title of the toast.
|
|
42
|
+
*/
|
|
43
|
+
title?: T | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The description of the toast.
|
|
46
|
+
*/
|
|
47
|
+
description?: T | undefined;
|
|
33
48
|
/**
|
|
34
49
|
* The duration the toast will be visible
|
|
35
50
|
*/
|
|
@@ -39,10 +54,6 @@ interface Options<T> extends GenericOptions<T> {
|
|
|
39
54
|
* Useful for exit transitions.
|
|
40
55
|
*/
|
|
41
56
|
removeDelay?: number | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* The placement of the toast
|
|
44
|
-
*/
|
|
45
|
-
placement?: Placement | undefined;
|
|
46
57
|
/**
|
|
47
58
|
* The unique id of the toast
|
|
48
59
|
*/
|
|
@@ -54,202 +65,251 @@ interface Options<T> extends GenericOptions<T> {
|
|
|
54
65
|
/**
|
|
55
66
|
* Function called when the toast is visible
|
|
56
67
|
*/
|
|
57
|
-
onStatusChange
|
|
68
|
+
onStatusChange?: ((details: StatusChangeDetails) => void) | undefined;
|
|
58
69
|
/**
|
|
59
70
|
* The action of the toast
|
|
60
71
|
*/
|
|
61
72
|
action?: ActionOptions | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the toast is closable
|
|
75
|
+
*/
|
|
76
|
+
closable?: boolean | undefined;
|
|
62
77
|
/**
|
|
63
78
|
* The metadata of the toast
|
|
64
79
|
*/
|
|
65
80
|
meta?: Record<string, any> | undefined;
|
|
66
81
|
}
|
|
67
|
-
interface
|
|
82
|
+
interface ToastProps<T = any> extends Omit<CommonProperties, "id">, Options<T> {
|
|
68
83
|
/**
|
|
69
|
-
* The
|
|
70
|
-
* Useful for exit transitions.
|
|
84
|
+
* The direction of the toast
|
|
71
85
|
*/
|
|
72
|
-
|
|
86
|
+
dir?: Direction | undefined;
|
|
73
87
|
/**
|
|
74
|
-
* The
|
|
88
|
+
* The gap of the toast
|
|
75
89
|
*/
|
|
76
|
-
|
|
90
|
+
gap?: number;
|
|
91
|
+
}
|
|
92
|
+
type ToastPropsWithDefault = "type" | "parent" | "duration" | "id";
|
|
93
|
+
type ToastSchema<O = any> = {
|
|
94
|
+
props: RequiredBy<ToastProps<O>, ToastPropsWithDefault>;
|
|
95
|
+
context: {
|
|
96
|
+
mounted: boolean;
|
|
97
|
+
initialHeight: number;
|
|
98
|
+
remainingTime: number;
|
|
99
|
+
};
|
|
100
|
+
computed: {
|
|
101
|
+
height: number;
|
|
102
|
+
heightIndex: number;
|
|
103
|
+
heightBefore: number;
|
|
104
|
+
frontmost: boolean;
|
|
105
|
+
zIndex: number;
|
|
106
|
+
shouldPersist: boolean;
|
|
107
|
+
};
|
|
108
|
+
refs: {
|
|
109
|
+
closeTimerStartTime: number;
|
|
110
|
+
lastCloseStartTimerStartTime: number;
|
|
111
|
+
};
|
|
112
|
+
state: "visible" | "visible:updating" | "dismissing" | "unmounted" | "visible:persist";
|
|
113
|
+
tag: "visible" | "paused" | "updating";
|
|
114
|
+
guard: string;
|
|
115
|
+
action: string;
|
|
116
|
+
effect: string;
|
|
117
|
+
event: EventObject;
|
|
118
|
+
};
|
|
119
|
+
type ToastService = Service<ToastSchema>;
|
|
120
|
+
type ToastMachine = Machine<ToastSchema>;
|
|
121
|
+
interface ToastStoreProps {
|
|
77
122
|
/**
|
|
78
|
-
* The
|
|
123
|
+
* The placement of the toast
|
|
124
|
+
* @default "bottom"
|
|
79
125
|
*/
|
|
80
|
-
|
|
126
|
+
placement?: Placement | undefined;
|
|
81
127
|
/**
|
|
82
|
-
* The
|
|
128
|
+
* The maximum number of toasts
|
|
129
|
+
* @default 24
|
|
83
130
|
*/
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
interface MachinePrivateContext {
|
|
87
|
-
}
|
|
88
|
-
interface MachineState {
|
|
89
|
-
value: "visible" | "visible:updating" | "dismissing" | "unmounted" | "visible:persist";
|
|
90
|
-
tags: "visible" | "paused" | "updating";
|
|
91
|
-
}
|
|
92
|
-
type State<T = any> = StateMachine.State<MachineContext<T>, MachineState>;
|
|
93
|
-
type Send = StateMachine.Send;
|
|
94
|
-
type Service<T = any> = Machine<MachineContext<T>, MachineState>;
|
|
95
|
-
interface GroupPublicContext extends DirectionProperty, CommonProperties {
|
|
131
|
+
max?: number | undefined;
|
|
96
132
|
/**
|
|
97
|
-
* Whether to
|
|
98
|
-
* @default false
|
|
133
|
+
* Whether to overlap the toasts
|
|
99
134
|
*/
|
|
100
|
-
|
|
135
|
+
overlap?: boolean | undefined;
|
|
101
136
|
/**
|
|
102
|
-
* The
|
|
103
|
-
*
|
|
137
|
+
* The duration of the toast.
|
|
138
|
+
* By default, it is determined by the type of the toast.
|
|
104
139
|
*/
|
|
105
|
-
|
|
140
|
+
duration?: number | undefined;
|
|
106
141
|
/**
|
|
107
|
-
* The
|
|
108
|
-
* @default
|
|
142
|
+
* The gap between the toasts
|
|
143
|
+
* @default 16
|
|
109
144
|
*/
|
|
110
|
-
|
|
145
|
+
gap?: number | undefined;
|
|
111
146
|
/**
|
|
112
147
|
* The offset from the safe environment edge of the viewport
|
|
113
148
|
* @default "1rem"
|
|
114
149
|
*/
|
|
115
|
-
offsets
|
|
150
|
+
offsets?: string | Record<"left" | "right" | "bottom" | "top", string> | undefined;
|
|
116
151
|
/**
|
|
117
152
|
* The hotkey that will move focus to the toast group
|
|
118
153
|
* @default '["altKey", "KeyT"]'
|
|
119
154
|
*/
|
|
120
|
-
hotkey
|
|
121
|
-
/**
|
|
122
|
-
* Whether the toasts should overlap each other
|
|
123
|
-
*/
|
|
124
|
-
overlap?: boolean | undefined;
|
|
125
|
-
/**
|
|
126
|
-
* The placement of the toast
|
|
127
|
-
*/
|
|
128
|
-
placement: Placement;
|
|
155
|
+
hotkey?: string[] | undefined;
|
|
129
156
|
/**
|
|
130
157
|
* The duration for the toast to kept alive before it is removed.
|
|
131
158
|
* Useful for exit transitions.
|
|
132
159
|
*
|
|
133
160
|
* @default 200
|
|
134
161
|
*/
|
|
135
|
-
removeDelay
|
|
162
|
+
removeDelay?: number | undefined;
|
|
136
163
|
/**
|
|
137
|
-
*
|
|
164
|
+
* Whether to pause toast when the user leaves the browser tab
|
|
165
|
+
* @default false
|
|
138
166
|
*/
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
interface UserDefinedGroupContext extends RequiredBy<GroupPublicContext, "id"> {
|
|
167
|
+
pauseOnPageIdle?: boolean | undefined;
|
|
142
168
|
}
|
|
143
|
-
|
|
169
|
+
interface ToastGroupProps extends DirectionProperty, CommonProperties {
|
|
144
170
|
/**
|
|
145
|
-
*
|
|
146
|
-
* The total number of toasts in the group
|
|
171
|
+
* The store of the toast
|
|
147
172
|
*/
|
|
148
|
-
|
|
149
|
-
}>;
|
|
150
|
-
interface GroupPrivateContext<T> extends GenericOptions<T> {
|
|
151
|
-
}
|
|
152
|
-
interface GroupMachineContext<T = any> extends GroupPublicContext, GroupPrivateContext<T>, GroupComputedContext {
|
|
153
|
-
}
|
|
154
|
-
interface GroupMachineState {
|
|
155
|
-
value: "stack" | "overlap";
|
|
156
|
-
}
|
|
157
|
-
type GroupState<T = any> = StateMachine.State<GroupMachineContext<T>>;
|
|
158
|
-
type GroupSend = StateMachine.Send;
|
|
159
|
-
type GroupService<T = any> = Machine<GroupMachineContext<T>, GroupMachineState>;
|
|
160
|
-
type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
|
|
161
|
-
interface PromiseOptions<V, O = any> {
|
|
162
|
-
loading: Options<O>;
|
|
163
|
-
success: MaybeFunction<Options<O>, V>;
|
|
164
|
-
error: MaybeFunction<Options<O>, Error>;
|
|
165
|
-
finally?: (() => void | Promise<void>) | undefined;
|
|
173
|
+
store: ToastStore;
|
|
166
174
|
}
|
|
167
|
-
|
|
175
|
+
type ToastGroupSchema = {
|
|
176
|
+
state: "stack" | "overlap";
|
|
177
|
+
props: ToastGroupProps;
|
|
178
|
+
context: {
|
|
179
|
+
toasts: RequiredBy<ToastProps, ToastPropsWithDefault>[];
|
|
180
|
+
heights: ToastHeight[];
|
|
181
|
+
};
|
|
182
|
+
computed: {
|
|
183
|
+
count: number;
|
|
184
|
+
overlap: boolean;
|
|
185
|
+
placement: Placement;
|
|
186
|
+
};
|
|
187
|
+
refs: {
|
|
188
|
+
dismissableCleanup?: VoidFunction | undefined;
|
|
189
|
+
lastFocusedEl: HTMLElement | null;
|
|
190
|
+
isFocusWithin: boolean;
|
|
191
|
+
};
|
|
192
|
+
guard: string;
|
|
193
|
+
effect: string;
|
|
194
|
+
action: string;
|
|
195
|
+
event: EventObject;
|
|
196
|
+
};
|
|
197
|
+
type ToastGroupService = Service<ToastGroupSchema>;
|
|
198
|
+
type ToastGroupMachine = Machine<ToastGroupSchema>;
|
|
199
|
+
interface ToastStore<V = any> {
|
|
168
200
|
/**
|
|
169
|
-
* The
|
|
201
|
+
* The attributes of the toast store
|
|
170
202
|
*/
|
|
171
|
-
|
|
203
|
+
attrs: Required<ToastStoreProps>;
|
|
172
204
|
/**
|
|
173
|
-
*
|
|
205
|
+
* Subscribe to the toast store
|
|
174
206
|
*/
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
interface GroupMachineApi<T extends PropTypes = PropTypes, O = any> {
|
|
207
|
+
subscribe: (subscriber: (...args: any[]) => void) => VoidFunction;
|
|
178
208
|
/**
|
|
179
|
-
*
|
|
209
|
+
* Create a new toast with the given options
|
|
180
210
|
*/
|
|
181
|
-
|
|
211
|
+
create: (data: Options<V>) => string;
|
|
182
212
|
/**
|
|
183
|
-
*
|
|
213
|
+
* Update an existing toast with new properties
|
|
184
214
|
*/
|
|
185
|
-
|
|
215
|
+
update: (id: string, data: Partial<ToastProps<V>>) => string;
|
|
186
216
|
/**
|
|
187
|
-
*
|
|
217
|
+
* Remove a toast by its ID
|
|
188
218
|
*/
|
|
189
|
-
|
|
219
|
+
remove: (id: string) => void;
|
|
190
220
|
/**
|
|
191
|
-
*
|
|
221
|
+
* Dismiss a toast by its ID. If no ID is provided, dismisses all toasts
|
|
192
222
|
*/
|
|
193
|
-
|
|
223
|
+
dismiss: (id?: string) => void;
|
|
194
224
|
/**
|
|
195
|
-
*
|
|
225
|
+
* Create an error toast with the given options
|
|
196
226
|
*/
|
|
197
|
-
|
|
227
|
+
error: (data: Options<V>) => void;
|
|
198
228
|
/**
|
|
199
|
-
*
|
|
229
|
+
* Create a success toast with the given options
|
|
200
230
|
*/
|
|
201
|
-
|
|
231
|
+
success: (data: Options<V>) => void;
|
|
202
232
|
/**
|
|
203
|
-
*
|
|
233
|
+
* Create an info toast with the given options
|
|
204
234
|
*/
|
|
205
|
-
|
|
235
|
+
info: (data: Options<V>) => void;
|
|
206
236
|
/**
|
|
207
|
-
*
|
|
237
|
+
* Create a warning toast with the given options
|
|
208
238
|
*/
|
|
209
|
-
|
|
239
|
+
warning: (data: Options<V>) => void;
|
|
210
240
|
/**
|
|
211
|
-
*
|
|
241
|
+
* Create a loading toast with the given options
|
|
212
242
|
*/
|
|
213
|
-
|
|
243
|
+
loading: (data: Options<V>) => void;
|
|
214
244
|
/**
|
|
215
|
-
*
|
|
245
|
+
* Get all currently visible toasts
|
|
216
246
|
*/
|
|
217
|
-
|
|
247
|
+
getVisibleToasts: () => Partial<ToastProps<V>>[];
|
|
218
248
|
/**
|
|
219
|
-
*
|
|
249
|
+
* Get the total number of toasts
|
|
220
250
|
*/
|
|
221
|
-
|
|
251
|
+
getCount: () => number;
|
|
222
252
|
/**
|
|
223
|
-
*
|
|
253
|
+
* Create a toast that tracks a promise's state
|
|
224
254
|
*/
|
|
225
|
-
|
|
255
|
+
promise: <T>(promise: Promise<T> | (() => Promise<T>), options: PromiseOptions<T, V>, shared?: Omit<Options<V>, "type">) => {
|
|
256
|
+
id: string | undefined;
|
|
257
|
+
unwrap: () => Promise<T>;
|
|
258
|
+
} | undefined;
|
|
226
259
|
/**
|
|
227
|
-
*
|
|
228
|
-
* If no id is provided, all toasts will be dismissed.
|
|
260
|
+
* Pause a toast's auto-dismiss timer. If no ID is provided, pauses all toasts
|
|
229
261
|
*/
|
|
230
|
-
|
|
262
|
+
pause: (id?: string) => void;
|
|
231
263
|
/**
|
|
232
|
-
*
|
|
264
|
+
* Resume a toast's auto-dismiss timer. If no ID is provided, resumes all toasts
|
|
233
265
|
*/
|
|
234
|
-
|
|
266
|
+
resume: (id?: string) => void;
|
|
235
267
|
/**
|
|
236
|
-
*
|
|
237
|
-
* If no id is provided, all toasts will be removed.
|
|
268
|
+
* Check if a toast with the given ID is currently visible
|
|
238
269
|
*/
|
|
239
|
-
|
|
270
|
+
isVisible: (id: string) => boolean;
|
|
240
271
|
/**
|
|
241
|
-
*
|
|
242
|
-
* - When the promise resolves, the toast will be updated with the success options.
|
|
243
|
-
* - When the promise rejects, the toast will be updated with the error options.
|
|
272
|
+
* Check if a toast with the given ID has been dismissed
|
|
244
273
|
*/
|
|
245
|
-
|
|
274
|
+
isDismissed: (id: string) => boolean;
|
|
275
|
+
}
|
|
276
|
+
type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
|
|
277
|
+
interface PromiseOptions<V, O = any> {
|
|
278
|
+
loading?: Omit<Options<O>, "type">;
|
|
279
|
+
success?: MaybeFunction<Omit<Options<O>, "type">, V>;
|
|
280
|
+
error?: MaybeFunction<Omit<Options<O>, "type">, unknown>;
|
|
281
|
+
finally?: (() => void | Promise<void>) | undefined;
|
|
282
|
+
}
|
|
283
|
+
interface GroupProps {
|
|
284
|
+
/**
|
|
285
|
+
* The human-readable label for the toast region
|
|
286
|
+
*/
|
|
287
|
+
label?: string | undefined;
|
|
288
|
+
}
|
|
289
|
+
interface ToastGroupApi<T extends PropTypes = PropTypes, O = any> {
|
|
246
290
|
/**
|
|
247
|
-
*
|
|
291
|
+
* The total number of toasts
|
|
292
|
+
*/
|
|
293
|
+
getCount(): number;
|
|
294
|
+
/**
|
|
295
|
+
* The toasts
|
|
296
|
+
*/
|
|
297
|
+
getToasts(): ToastProps[];
|
|
298
|
+
/**
|
|
299
|
+
* Subscribe to the toast group
|
|
248
300
|
*/
|
|
249
301
|
subscribe(callback: (toasts: Options<O>[]) => void): VoidFunction;
|
|
250
|
-
getGroupProps(options
|
|
302
|
+
getGroupProps(options?: GroupProps): T["element"];
|
|
251
303
|
}
|
|
252
|
-
interface
|
|
304
|
+
interface ToastApi<T extends PropTypes = PropTypes, O = any> {
|
|
305
|
+
/**
|
|
306
|
+
* The title of the toast.
|
|
307
|
+
*/
|
|
308
|
+
title: O;
|
|
309
|
+
/**
|
|
310
|
+
* The description of the toast.
|
|
311
|
+
*/
|
|
312
|
+
description: O;
|
|
253
313
|
/**
|
|
254
314
|
* The type of the toast.
|
|
255
315
|
*/
|
|
@@ -262,6 +322,10 @@ interface MachineApi<T extends PropTypes = PropTypes, O = any> extends GenericOp
|
|
|
262
322
|
* Whether the toast is visible.
|
|
263
323
|
*/
|
|
264
324
|
visible: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* Whether the toast should render a close button
|
|
327
|
+
*/
|
|
328
|
+
closable: boolean;
|
|
265
329
|
/**
|
|
266
330
|
* Whether the toast is paused.
|
|
267
331
|
*/
|
|
@@ -287,19 +351,19 @@ interface MachineApi<T extends PropTypes = PropTypes, O = any> extends GenericOp
|
|
|
287
351
|
getActionTriggerProps(): T["button"];
|
|
288
352
|
}
|
|
289
353
|
|
|
290
|
-
declare function groupConnect<T extends PropTypes, O = any>(
|
|
354
|
+
declare function groupConnect<T extends PropTypes, O = any>(service: Service<ToastGroupSchema>, normalize: NormalizeProps<T>): ToastGroupApi<T, O>;
|
|
291
355
|
|
|
292
|
-
declare
|
|
356
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"title" | "description" | "group" | "root" | "actionTrigger" | "closeTrigger">;
|
|
293
357
|
|
|
294
|
-
declare function
|
|
358
|
+
declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
|
295
359
|
|
|
296
|
-
declare const
|
|
360
|
+
declare const machine: _zag_js_core.Machine<ToastSchema>;
|
|
297
361
|
|
|
298
|
-
declare function
|
|
362
|
+
declare function createToastStore<V = any>(props: ToastStoreProps): ToastStore<V>;
|
|
299
363
|
|
|
300
364
|
declare const group: {
|
|
301
365
|
connect: typeof groupConnect;
|
|
302
|
-
machine:
|
|
366
|
+
machine: _zag_js_core.Machine<ToastGroupSchema>;
|
|
303
367
|
};
|
|
304
368
|
|
|
305
|
-
export { type ActionOptions, type
|
|
369
|
+
export { type ActionOptions, type ToastApi as Api, type ToastGroupApi as GroupApi, type ToastGroupMachine as GroupMachine, type ToastGroupProps as GroupProps, type ToastGroupService as GroupService, type ToastMachine as Machine, type Options, type Placement, type PromiseOptions, type ToastProps as Props, type ToastService as Service, type Status, type StatusChangeDetails, type ToastStore as Store, type ToastStoreProps as StoreProps, type Type, anatomy, connect, createToastStore as createStore, group, machine };
|