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