@zag-js/toast 0.82.2 → 1.0.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/dist/index.d.mts +196 -134
- package/dist/index.d.ts +196 -134
- package/dist/index.js +760 -625
- package/dist/index.mjs +760 -626
- package/package.json +15 -10
package/dist/index.d.mts
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 {
|
|
2
|
+
import { Service, 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,249 @@ 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
|
+
interface ToastStoreProps {
|
|
77
121
|
/**
|
|
78
|
-
* The
|
|
122
|
+
* The placement of the toast
|
|
123
|
+
* @default "bottom"
|
|
79
124
|
*/
|
|
80
|
-
|
|
125
|
+
placement?: Placement | undefined;
|
|
81
126
|
/**
|
|
82
|
-
* The
|
|
127
|
+
* The maximum number of toasts
|
|
128
|
+
* @default 24
|
|
83
129
|
*/
|
|
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 {
|
|
130
|
+
max?: number | undefined;
|
|
96
131
|
/**
|
|
97
|
-
* Whether to
|
|
98
|
-
* @default false
|
|
132
|
+
* Whether to overlap the toasts
|
|
99
133
|
*/
|
|
100
|
-
|
|
134
|
+
overlap?: boolean | undefined;
|
|
101
135
|
/**
|
|
102
|
-
* The
|
|
103
|
-
*
|
|
136
|
+
* The duration of the toast.
|
|
137
|
+
* By default, it is determined by the type of the toast.
|
|
104
138
|
*/
|
|
105
|
-
|
|
139
|
+
duration?: number | undefined;
|
|
106
140
|
/**
|
|
107
|
-
* The
|
|
108
|
-
* @default
|
|
141
|
+
* The gap between the toasts
|
|
142
|
+
* @default 16
|
|
109
143
|
*/
|
|
110
|
-
|
|
144
|
+
gap?: number | undefined;
|
|
111
145
|
/**
|
|
112
146
|
* The offset from the safe environment edge of the viewport
|
|
113
147
|
* @default "1rem"
|
|
114
148
|
*/
|
|
115
|
-
offsets
|
|
149
|
+
offsets?: string | Record<"left" | "right" | "bottom" | "top", string> | undefined;
|
|
116
150
|
/**
|
|
117
151
|
* The hotkey that will move focus to the toast group
|
|
118
152
|
* @default '["altKey", "KeyT"]'
|
|
119
153
|
*/
|
|
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;
|
|
154
|
+
hotkey?: string[] | undefined;
|
|
129
155
|
/**
|
|
130
156
|
* The duration for the toast to kept alive before it is removed.
|
|
131
157
|
* Useful for exit transitions.
|
|
132
158
|
*
|
|
133
159
|
* @default 200
|
|
134
160
|
*/
|
|
135
|
-
removeDelay
|
|
161
|
+
removeDelay?: number | undefined;
|
|
136
162
|
/**
|
|
137
|
-
*
|
|
163
|
+
* Whether to pause toast when the user leaves the browser tab
|
|
164
|
+
* @default false
|
|
138
165
|
*/
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
interface UserDefinedGroupContext extends RequiredBy<GroupPublicContext, "id"> {
|
|
166
|
+
pauseOnPageIdle?: boolean | undefined;
|
|
142
167
|
}
|
|
143
|
-
|
|
168
|
+
interface ToastGroupProps extends DirectionProperty, CommonProperties {
|
|
144
169
|
/**
|
|
145
|
-
*
|
|
146
|
-
* The total number of toasts in the group
|
|
170
|
+
* The store of the toast
|
|
147
171
|
*/
|
|
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;
|
|
172
|
+
store: ToastStore;
|
|
166
173
|
}
|
|
167
|
-
|
|
174
|
+
type ToastGroupSchema = {
|
|
175
|
+
state: "stack" | "overlap";
|
|
176
|
+
props: ToastGroupProps;
|
|
177
|
+
context: {
|
|
178
|
+
toasts: RequiredBy<ToastProps, ToastPropsWithDefault>[];
|
|
179
|
+
heights: ToastHeight[];
|
|
180
|
+
};
|
|
181
|
+
computed: {
|
|
182
|
+
count: number;
|
|
183
|
+
overlap: boolean;
|
|
184
|
+
placement: Placement;
|
|
185
|
+
};
|
|
186
|
+
refs: {
|
|
187
|
+
dismissableCleanup?: VoidFunction | undefined;
|
|
188
|
+
lastFocusedEl: HTMLElement | null;
|
|
189
|
+
isFocusWithin: boolean;
|
|
190
|
+
};
|
|
191
|
+
guard: string;
|
|
192
|
+
effect: string;
|
|
193
|
+
action: string;
|
|
194
|
+
event: EventObject;
|
|
195
|
+
};
|
|
196
|
+
type ToastGroupService = Service<ToastGroupSchema>;
|
|
197
|
+
interface ToastStore<V = any> {
|
|
168
198
|
/**
|
|
169
|
-
* The
|
|
199
|
+
* The attributes of the toast store
|
|
170
200
|
*/
|
|
171
|
-
|
|
201
|
+
attrs: Required<ToastStoreProps>;
|
|
172
202
|
/**
|
|
173
|
-
*
|
|
203
|
+
* Subscribe to the toast store
|
|
174
204
|
*/
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
interface GroupMachineApi<T extends PropTypes = PropTypes, O = any> {
|
|
205
|
+
subscribe: (subscriber: (...args: any[]) => void) => VoidFunction;
|
|
178
206
|
/**
|
|
179
|
-
*
|
|
207
|
+
* Create a new toast with the given options
|
|
180
208
|
*/
|
|
181
|
-
|
|
209
|
+
create: (data: Options<V>) => string;
|
|
182
210
|
/**
|
|
183
|
-
*
|
|
211
|
+
* Update an existing toast with new properties
|
|
184
212
|
*/
|
|
185
|
-
|
|
213
|
+
update: (id: string, data: Partial<ToastProps<V>>) => string;
|
|
186
214
|
/**
|
|
187
|
-
*
|
|
215
|
+
* Remove a toast by its ID
|
|
188
216
|
*/
|
|
189
|
-
|
|
217
|
+
remove: (id: string) => void;
|
|
190
218
|
/**
|
|
191
|
-
*
|
|
219
|
+
* Dismiss a toast by its ID. If no ID is provided, dismisses all toasts
|
|
192
220
|
*/
|
|
193
|
-
|
|
221
|
+
dismiss: (id?: string) => void;
|
|
194
222
|
/**
|
|
195
|
-
*
|
|
223
|
+
* Create an error toast with the given options
|
|
196
224
|
*/
|
|
197
|
-
|
|
225
|
+
error: (data: Options<V>) => void;
|
|
198
226
|
/**
|
|
199
|
-
*
|
|
227
|
+
* Create a success toast with the given options
|
|
200
228
|
*/
|
|
201
|
-
|
|
229
|
+
success: (data: Options<V>) => void;
|
|
202
230
|
/**
|
|
203
|
-
*
|
|
231
|
+
* Create an info toast with the given options
|
|
204
232
|
*/
|
|
205
|
-
|
|
233
|
+
info: (data: Options<V>) => void;
|
|
206
234
|
/**
|
|
207
|
-
*
|
|
235
|
+
* Create a warning toast with the given options
|
|
208
236
|
*/
|
|
209
|
-
|
|
237
|
+
warning: (data: Options<V>) => void;
|
|
210
238
|
/**
|
|
211
|
-
*
|
|
239
|
+
* Create a loading toast with the given options
|
|
212
240
|
*/
|
|
213
|
-
|
|
241
|
+
loading: (data: Options<V>) => void;
|
|
214
242
|
/**
|
|
215
|
-
*
|
|
243
|
+
* Get all currently visible toasts
|
|
216
244
|
*/
|
|
217
|
-
|
|
245
|
+
getVisibleToasts: () => Partial<ToastProps<V>>[];
|
|
218
246
|
/**
|
|
219
|
-
*
|
|
247
|
+
* Get the total number of toasts
|
|
220
248
|
*/
|
|
221
|
-
|
|
249
|
+
getCount: () => number;
|
|
222
250
|
/**
|
|
223
|
-
*
|
|
251
|
+
* Create a toast that tracks a promise's state
|
|
224
252
|
*/
|
|
225
|
-
|
|
253
|
+
promise: <T>(promise: Promise<T> | (() => Promise<T>), options: PromiseOptions<T, V>, shared?: Omit<Options<V>, "type">) => {
|
|
254
|
+
id: string | undefined;
|
|
255
|
+
unwrap: () => Promise<T>;
|
|
256
|
+
} | undefined;
|
|
226
257
|
/**
|
|
227
|
-
*
|
|
228
|
-
* If no id is provided, all toasts will be dismissed.
|
|
258
|
+
* Pause a toast's auto-dismiss timer. If no ID is provided, pauses all toasts
|
|
229
259
|
*/
|
|
230
|
-
|
|
260
|
+
pause: (id?: string) => void;
|
|
231
261
|
/**
|
|
232
|
-
*
|
|
262
|
+
* Resume a toast's auto-dismiss timer. If no ID is provided, resumes all toasts
|
|
233
263
|
*/
|
|
234
|
-
|
|
264
|
+
resume: (id?: string) => void;
|
|
235
265
|
/**
|
|
236
|
-
*
|
|
237
|
-
* If no id is provided, all toasts will be removed.
|
|
266
|
+
* Check if a toast with the given ID is currently visible
|
|
238
267
|
*/
|
|
239
|
-
|
|
268
|
+
isVisible: (id: string) => boolean;
|
|
240
269
|
/**
|
|
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.
|
|
270
|
+
* Check if a toast with the given ID has been dismissed
|
|
244
271
|
*/
|
|
245
|
-
|
|
272
|
+
isDismissed: (id: string) => boolean;
|
|
273
|
+
}
|
|
274
|
+
type MaybeFunction<Value, Args> = Value | ((arg: Args) => Value);
|
|
275
|
+
interface PromiseOptions<V, O = any> {
|
|
276
|
+
loading?: Omit<Options<O>, "type">;
|
|
277
|
+
success?: MaybeFunction<Omit<Options<O>, "type">, V>;
|
|
278
|
+
error?: MaybeFunction<Omit<Options<O>, "type">, unknown>;
|
|
279
|
+
finally?: (() => void | Promise<void>) | undefined;
|
|
280
|
+
}
|
|
281
|
+
interface GroupProps {
|
|
282
|
+
/**
|
|
283
|
+
* The human-readable label for the toast region
|
|
284
|
+
*/
|
|
285
|
+
label?: string | undefined;
|
|
286
|
+
}
|
|
287
|
+
interface ToastGroupApi<T extends PropTypes = PropTypes, O = any> {
|
|
246
288
|
/**
|
|
247
|
-
*
|
|
289
|
+
* The total number of toasts
|
|
290
|
+
*/
|
|
291
|
+
getCount(): number;
|
|
292
|
+
/**
|
|
293
|
+
* The toasts
|
|
294
|
+
*/
|
|
295
|
+
getToasts(): ToastProps[];
|
|
296
|
+
/**
|
|
297
|
+
* Subscribe to the toast group
|
|
248
298
|
*/
|
|
249
299
|
subscribe(callback: (toasts: Options<O>[]) => void): VoidFunction;
|
|
250
|
-
getGroupProps(options
|
|
300
|
+
getGroupProps(options?: GroupProps): T["element"];
|
|
251
301
|
}
|
|
252
|
-
interface
|
|
302
|
+
interface ToastApi<T extends PropTypes = PropTypes, O = any> {
|
|
303
|
+
/**
|
|
304
|
+
* The title of the toast.
|
|
305
|
+
*/
|
|
306
|
+
title: O;
|
|
307
|
+
/**
|
|
308
|
+
* The description of the toast.
|
|
309
|
+
*/
|
|
310
|
+
description: O;
|
|
253
311
|
/**
|
|
254
312
|
* The type of the toast.
|
|
255
313
|
*/
|
|
@@ -262,6 +320,10 @@ interface MachineApi<T extends PropTypes = PropTypes, O = any> extends GenericOp
|
|
|
262
320
|
* Whether the toast is visible.
|
|
263
321
|
*/
|
|
264
322
|
visible: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Whether the toast should render a close button
|
|
325
|
+
*/
|
|
326
|
+
closable: boolean;
|
|
265
327
|
/**
|
|
266
328
|
* Whether the toast is paused.
|
|
267
329
|
*/
|
|
@@ -287,19 +349,19 @@ interface MachineApi<T extends PropTypes = PropTypes, O = any> extends GenericOp
|
|
|
287
349
|
getActionTriggerProps(): T["button"];
|
|
288
350
|
}
|
|
289
351
|
|
|
290
|
-
declare function groupConnect<T extends PropTypes, O = any>(
|
|
352
|
+
declare function groupConnect<T extends PropTypes, O = any>(service: Service<ToastGroupSchema>, normalize: NormalizeProps<T>): ToastGroupApi<T, O>;
|
|
291
353
|
|
|
292
|
-
declare
|
|
354
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"title" | "description" | "group" | "root" | "actionTrigger" | "closeTrigger">;
|
|
293
355
|
|
|
294
|
-
declare function
|
|
356
|
+
declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
|
|
295
357
|
|
|
296
|
-
declare const
|
|
358
|
+
declare const machine: _zag_js_core.MachineConfig<ToastSchema>;
|
|
297
359
|
|
|
298
|
-
declare function
|
|
360
|
+
declare function createToastStore<V = any>(props: ToastStoreProps): ToastStore<V>;
|
|
299
361
|
|
|
300
362
|
declare const group: {
|
|
301
363
|
connect: typeof groupConnect;
|
|
302
|
-
machine:
|
|
364
|
+
machine: _zag_js_core.MachineConfig<ToastGroupSchema>;
|
|
303
365
|
};
|
|
304
366
|
|
|
305
|
-
export { type ActionOptions, type
|
|
367
|
+
export { type ActionOptions, type ToastApi as Api, type ToastGroupApi as GroupApi, type ToastGroupProps as GroupProps, type ToastGroupService as GroupService, 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 };
|