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