@zag-js/toast 0.1.11 → 0.1.14
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.ts +2 -0
- package/dist/index.js +134 -125
- package/dist/index.mjs +134 -125
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -177,6 +177,7 @@ declare function createToastMachine(options?: Options): _zag_js_core.Machine<Mac
|
|
|
177
177
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
178
178
|
type: Type;
|
|
179
179
|
title: string | undefined;
|
|
180
|
+
description: string | undefined;
|
|
180
181
|
placement: Placement;
|
|
181
182
|
isVisible: boolean;
|
|
182
183
|
isPaused: boolean;
|
|
@@ -186,6 +187,7 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
186
187
|
rootProps: T["element"];
|
|
187
188
|
progressbarProps: T["element"];
|
|
188
189
|
titleProps: T["element"];
|
|
190
|
+
descriptionProps: T["element"];
|
|
189
191
|
closeButtonProps: T["button"];
|
|
190
192
|
render(): any;
|
|
191
193
|
};
|
package/dist/index.js
CHANGED
|
@@ -112,6 +112,7 @@ var dom = defineDomHelpers({
|
|
|
112
112
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
113
113
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
114
114
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
115
|
+
getDescriptionId: (ctx) => `toast-description:${ctx.id}`,
|
|
115
116
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
116
117
|
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
117
118
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
@@ -317,146 +318,149 @@ var { not, and, or } = import_core2.guards;
|
|
|
317
318
|
function createToastMachine(options = {}) {
|
|
318
319
|
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500, ...rest } = options;
|
|
319
320
|
const __duration = getToastDuration(duration, type);
|
|
320
|
-
return (0, import_core2.createMachine)(
|
|
321
|
-
|
|
322
|
-
entry: "invokeOnOpen",
|
|
323
|
-
initial: type === "loading" ? "persist" : "active",
|
|
324
|
-
context: {
|
|
321
|
+
return (0, import_core2.createMachine)(
|
|
322
|
+
{
|
|
325
323
|
id,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
338
|
-
target: "persist",
|
|
339
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
343
|
-
target: "active:temp",
|
|
344
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
348
|
-
}
|
|
349
|
-
]
|
|
350
|
-
},
|
|
351
|
-
states: {
|
|
352
|
-
"active:temp": {
|
|
353
|
-
tags: ["visible", "updating"],
|
|
354
|
-
after: {
|
|
355
|
-
0: "active"
|
|
356
|
-
}
|
|
324
|
+
entry: "invokeOnOpen",
|
|
325
|
+
initial: type === "loading" ? "persist" : "active",
|
|
326
|
+
context: {
|
|
327
|
+
id,
|
|
328
|
+
type,
|
|
329
|
+
remaining: __duration,
|
|
330
|
+
duration: __duration,
|
|
331
|
+
removeDelay,
|
|
332
|
+
createdAt: Date.now(),
|
|
333
|
+
placement,
|
|
334
|
+
...rest
|
|
357
335
|
},
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
target: "active",
|
|
365
|
-
actions: ["setCreatedAt"]
|
|
336
|
+
on: {
|
|
337
|
+
UPDATE: [
|
|
338
|
+
{
|
|
339
|
+
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
340
|
+
target: "persist",
|
|
341
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
366
342
|
},
|
|
367
|
-
|
|
368
|
-
|
|
343
|
+
{
|
|
344
|
+
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
345
|
+
target: "active:temp",
|
|
346
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
350
|
+
}
|
|
351
|
+
]
|
|
369
352
|
},
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
353
|
+
states: {
|
|
354
|
+
"active:temp": {
|
|
355
|
+
tags: ["visible", "updating"],
|
|
356
|
+
after: {
|
|
357
|
+
0: "active"
|
|
358
|
+
}
|
|
375
359
|
},
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
360
|
+
persist: {
|
|
361
|
+
tags: ["visible", "paused"],
|
|
362
|
+
activities: "trackDocumentVisibility",
|
|
363
|
+
on: {
|
|
364
|
+
RESUME: {
|
|
365
|
+
guard: not("isLoadingType"),
|
|
366
|
+
target: "active",
|
|
367
|
+
actions: ["setCreatedAt"]
|
|
368
|
+
},
|
|
369
|
+
DISMISS: "dismissing"
|
|
381
370
|
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
371
|
+
},
|
|
372
|
+
active: {
|
|
373
|
+
tags: ["visible"],
|
|
374
|
+
activities: "trackDocumentVisibility",
|
|
375
|
+
after: {
|
|
376
|
+
VISIBLE_DURATION: "dismissing"
|
|
377
|
+
},
|
|
378
|
+
on: {
|
|
379
|
+
DISMISS: "dismissing",
|
|
380
|
+
PAUSE: {
|
|
381
|
+
target: "persist",
|
|
382
|
+
actions: "setRemainingDuration"
|
|
383
|
+
}
|
|
390
384
|
}
|
|
385
|
+
},
|
|
386
|
+
dismissing: {
|
|
387
|
+
entry: "invokeOnClosing",
|
|
388
|
+
after: {
|
|
389
|
+
REMOVE_DELAY: {
|
|
390
|
+
target: "inactive",
|
|
391
|
+
actions: "notifyParentToRemove"
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
inactive: {
|
|
396
|
+
entry: "invokeOnClose",
|
|
397
|
+
type: "final"
|
|
391
398
|
}
|
|
392
|
-
},
|
|
393
|
-
inactive: {
|
|
394
|
-
entry: "invokeOnClose",
|
|
395
|
-
type: "final"
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}, {
|
|
399
|
-
activities: {
|
|
400
|
-
trackDocumentVisibility(ctx, _evt, { send }) {
|
|
401
|
-
if (!ctx.pauseOnPageIdle)
|
|
402
|
-
return;
|
|
403
|
-
return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
|
|
404
|
-
send(hidden ? "PAUSE" : "RESUME");
|
|
405
|
-
});
|
|
406
399
|
}
|
|
407
400
|
},
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
},
|
|
418
|
-
hasDurationChanged: (ctx, evt) => {
|
|
419
|
-
var _a;
|
|
420
|
-
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
|
|
421
|
-
}
|
|
422
|
-
},
|
|
423
|
-
delays: {
|
|
424
|
-
VISIBLE_DURATION: (ctx) => ctx.remaining,
|
|
425
|
-
REMOVE_DELAY: (ctx) => ctx.removeDelay
|
|
426
|
-
},
|
|
427
|
-
actions: {
|
|
428
|
-
setRemainingDuration(ctx) {
|
|
429
|
-
ctx.remaining -= Date.now() - ctx.createdAt;
|
|
430
|
-
},
|
|
431
|
-
setCreatedAt(ctx) {
|
|
432
|
-
ctx.createdAt = Date.now();
|
|
433
|
-
},
|
|
434
|
-
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
435
|
-
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
436
|
-
},
|
|
437
|
-
invokeOnClosing(ctx) {
|
|
438
|
-
var _a;
|
|
439
|
-
(_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
|
|
440
|
-
},
|
|
441
|
-
invokeOnClose(ctx) {
|
|
442
|
-
var _a;
|
|
443
|
-
(_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
|
|
401
|
+
{
|
|
402
|
+
activities: {
|
|
403
|
+
trackDocumentVisibility(ctx, _evt, { send }) {
|
|
404
|
+
if (!ctx.pauseOnPageIdle)
|
|
405
|
+
return;
|
|
406
|
+
return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
|
|
407
|
+
send(hidden ? "PAUSE" : "RESUME");
|
|
408
|
+
});
|
|
409
|
+
}
|
|
444
410
|
},
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
411
|
+
guards: {
|
|
412
|
+
isChangingToLoading: (_, evt) => {
|
|
413
|
+
var _a;
|
|
414
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
|
|
415
|
+
},
|
|
416
|
+
isLoadingType: (ctx) => ctx.type === "loading",
|
|
417
|
+
hasTypeChanged: (ctx, evt) => {
|
|
418
|
+
var _a;
|
|
419
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
|
|
420
|
+
},
|
|
421
|
+
hasDurationChanged: (ctx, evt) => {
|
|
422
|
+
var _a;
|
|
423
|
+
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
|
|
424
|
+
}
|
|
448
425
|
},
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
(
|
|
426
|
+
delays: {
|
|
427
|
+
VISIBLE_DURATION: (ctx) => ctx.remaining,
|
|
428
|
+
REMOVE_DELAY: (ctx) => ctx.removeDelay
|
|
452
429
|
},
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
430
|
+
actions: {
|
|
431
|
+
setRemainingDuration(ctx) {
|
|
432
|
+
ctx.remaining -= Date.now() - ctx.createdAt;
|
|
433
|
+
},
|
|
434
|
+
setCreatedAt(ctx) {
|
|
435
|
+
ctx.createdAt = Date.now();
|
|
436
|
+
},
|
|
437
|
+
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
438
|
+
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
439
|
+
},
|
|
440
|
+
invokeOnClosing(ctx) {
|
|
441
|
+
var _a;
|
|
442
|
+
(_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
|
|
443
|
+
},
|
|
444
|
+
invokeOnClose(ctx) {
|
|
445
|
+
var _a;
|
|
446
|
+
(_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
|
|
447
|
+
},
|
|
448
|
+
invokeOnOpen(ctx) {
|
|
449
|
+
var _a;
|
|
450
|
+
(_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
|
|
451
|
+
},
|
|
452
|
+
invokeOnUpdate(ctx) {
|
|
453
|
+
var _a;
|
|
454
|
+
(_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
|
|
455
|
+
},
|
|
456
|
+
setContext(ctx, evt) {
|
|
457
|
+
const { duration: duration2, type: type2 } = evt.toast;
|
|
458
|
+
const time = getToastDuration(duration2, type2);
|
|
459
|
+
Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
|
|
460
|
+
}
|
|
457
461
|
}
|
|
458
462
|
}
|
|
459
|
-
|
|
463
|
+
);
|
|
460
464
|
}
|
|
461
465
|
|
|
462
466
|
// src/toast-group.machine.ts
|
|
@@ -560,6 +564,7 @@ function connect(state, send, normalize) {
|
|
|
560
564
|
return {
|
|
561
565
|
type: state.context.type,
|
|
562
566
|
title: state.context.title,
|
|
567
|
+
description: state.context.description,
|
|
563
568
|
placement,
|
|
564
569
|
isVisible,
|
|
565
570
|
isPaused,
|
|
@@ -632,6 +637,10 @@ function connect(state, send, normalize) {
|
|
|
632
637
|
"data-part": "title",
|
|
633
638
|
id: dom.getTitleId(state.context)
|
|
634
639
|
}),
|
|
640
|
+
descriptionProps: normalize.element({
|
|
641
|
+
"data-part": "description",
|
|
642
|
+
id: dom.getDescriptionId(state.context)
|
|
643
|
+
}),
|
|
635
644
|
closeButtonProps: normalize.button({
|
|
636
645
|
id: dom.getCloseButtonId(state.context),
|
|
637
646
|
"data-part": "close-button",
|
package/dist/index.mjs
CHANGED
|
@@ -83,6 +83,7 @@ var dom = defineDomHelpers({
|
|
|
83
83
|
getGroupId: (placement) => `toast-group:${placement}`,
|
|
84
84
|
getContainerId: (ctx) => `toast:${ctx.id}`,
|
|
85
85
|
getTitleId: (ctx) => `toast-title:${ctx.id}`,
|
|
86
|
+
getDescriptionId: (ctx) => `toast-description:${ctx.id}`,
|
|
86
87
|
getCloseButtonId: (ctx) => `toast-close-button:${ctx.id}`,
|
|
87
88
|
getPortalId: (ctx) => `toast-portal:${ctx.id}`,
|
|
88
89
|
getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
|
|
@@ -288,146 +289,149 @@ var { not, and, or } = guards;
|
|
|
288
289
|
function createToastMachine(options = {}) {
|
|
289
290
|
const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 500, ...rest } = options;
|
|
290
291
|
const __duration = getToastDuration(duration, type);
|
|
291
|
-
return createMachine(
|
|
292
|
-
|
|
293
|
-
entry: "invokeOnOpen",
|
|
294
|
-
initial: type === "loading" ? "persist" : "active",
|
|
295
|
-
context: {
|
|
292
|
+
return createMachine(
|
|
293
|
+
{
|
|
296
294
|
id,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
309
|
-
target: "persist",
|
|
310
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
314
|
-
target: "active:temp",
|
|
315
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
actions: ["setContext", "invokeOnUpdate"]
|
|
319
|
-
}
|
|
320
|
-
]
|
|
321
|
-
},
|
|
322
|
-
states: {
|
|
323
|
-
"active:temp": {
|
|
324
|
-
tags: ["visible", "updating"],
|
|
325
|
-
after: {
|
|
326
|
-
0: "active"
|
|
327
|
-
}
|
|
295
|
+
entry: "invokeOnOpen",
|
|
296
|
+
initial: type === "loading" ? "persist" : "active",
|
|
297
|
+
context: {
|
|
298
|
+
id,
|
|
299
|
+
type,
|
|
300
|
+
remaining: __duration,
|
|
301
|
+
duration: __duration,
|
|
302
|
+
removeDelay,
|
|
303
|
+
createdAt: Date.now(),
|
|
304
|
+
placement,
|
|
305
|
+
...rest
|
|
328
306
|
},
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
target: "active",
|
|
336
|
-
actions: ["setCreatedAt"]
|
|
307
|
+
on: {
|
|
308
|
+
UPDATE: [
|
|
309
|
+
{
|
|
310
|
+
guard: and("hasTypeChanged", "isChangingToLoading"),
|
|
311
|
+
target: "persist",
|
|
312
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
337
313
|
},
|
|
338
|
-
|
|
339
|
-
|
|
314
|
+
{
|
|
315
|
+
guard: or("hasDurationChanged", "hasTypeChanged"),
|
|
316
|
+
target: "active:temp",
|
|
317
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
actions: ["setContext", "invokeOnUpdate"]
|
|
321
|
+
}
|
|
322
|
+
]
|
|
340
323
|
},
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
324
|
+
states: {
|
|
325
|
+
"active:temp": {
|
|
326
|
+
tags: ["visible", "updating"],
|
|
327
|
+
after: {
|
|
328
|
+
0: "active"
|
|
329
|
+
}
|
|
346
330
|
},
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
331
|
+
persist: {
|
|
332
|
+
tags: ["visible", "paused"],
|
|
333
|
+
activities: "trackDocumentVisibility",
|
|
334
|
+
on: {
|
|
335
|
+
RESUME: {
|
|
336
|
+
guard: not("isLoadingType"),
|
|
337
|
+
target: "active",
|
|
338
|
+
actions: ["setCreatedAt"]
|
|
339
|
+
},
|
|
340
|
+
DISMISS: "dismissing"
|
|
352
341
|
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
342
|
+
},
|
|
343
|
+
active: {
|
|
344
|
+
tags: ["visible"],
|
|
345
|
+
activities: "trackDocumentVisibility",
|
|
346
|
+
after: {
|
|
347
|
+
VISIBLE_DURATION: "dismissing"
|
|
348
|
+
},
|
|
349
|
+
on: {
|
|
350
|
+
DISMISS: "dismissing",
|
|
351
|
+
PAUSE: {
|
|
352
|
+
target: "persist",
|
|
353
|
+
actions: "setRemainingDuration"
|
|
354
|
+
}
|
|
361
355
|
}
|
|
356
|
+
},
|
|
357
|
+
dismissing: {
|
|
358
|
+
entry: "invokeOnClosing",
|
|
359
|
+
after: {
|
|
360
|
+
REMOVE_DELAY: {
|
|
361
|
+
target: "inactive",
|
|
362
|
+
actions: "notifyParentToRemove"
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
inactive: {
|
|
367
|
+
entry: "invokeOnClose",
|
|
368
|
+
type: "final"
|
|
362
369
|
}
|
|
363
|
-
},
|
|
364
|
-
inactive: {
|
|
365
|
-
entry: "invokeOnClose",
|
|
366
|
-
type: "final"
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}, {
|
|
370
|
-
activities: {
|
|
371
|
-
trackDocumentVisibility(ctx, _evt, { send }) {
|
|
372
|
-
if (!ctx.pauseOnPageIdle)
|
|
373
|
-
return;
|
|
374
|
-
return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
|
|
375
|
-
send(hidden ? "PAUSE" : "RESUME");
|
|
376
|
-
});
|
|
377
370
|
}
|
|
378
371
|
},
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
},
|
|
389
|
-
hasDurationChanged: (ctx, evt) => {
|
|
390
|
-
var _a;
|
|
391
|
-
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
delays: {
|
|
395
|
-
VISIBLE_DURATION: (ctx) => ctx.remaining,
|
|
396
|
-
REMOVE_DELAY: (ctx) => ctx.removeDelay
|
|
397
|
-
},
|
|
398
|
-
actions: {
|
|
399
|
-
setRemainingDuration(ctx) {
|
|
400
|
-
ctx.remaining -= Date.now() - ctx.createdAt;
|
|
401
|
-
},
|
|
402
|
-
setCreatedAt(ctx) {
|
|
403
|
-
ctx.createdAt = Date.now();
|
|
404
|
-
},
|
|
405
|
-
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
406
|
-
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
407
|
-
},
|
|
408
|
-
invokeOnClosing(ctx) {
|
|
409
|
-
var _a;
|
|
410
|
-
(_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
|
|
411
|
-
},
|
|
412
|
-
invokeOnClose(ctx) {
|
|
413
|
-
var _a;
|
|
414
|
-
(_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
|
|
372
|
+
{
|
|
373
|
+
activities: {
|
|
374
|
+
trackDocumentVisibility(ctx, _evt, { send }) {
|
|
375
|
+
if (!ctx.pauseOnPageIdle)
|
|
376
|
+
return;
|
|
377
|
+
return trackDocumentVisibility(dom.getDoc(ctx), function(hidden) {
|
|
378
|
+
send(hidden ? "PAUSE" : "RESUME");
|
|
379
|
+
});
|
|
380
|
+
}
|
|
415
381
|
},
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
382
|
+
guards: {
|
|
383
|
+
isChangingToLoading: (_, evt) => {
|
|
384
|
+
var _a;
|
|
385
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
|
|
386
|
+
},
|
|
387
|
+
isLoadingType: (ctx) => ctx.type === "loading",
|
|
388
|
+
hasTypeChanged: (ctx, evt) => {
|
|
389
|
+
var _a;
|
|
390
|
+
return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx.type;
|
|
391
|
+
},
|
|
392
|
+
hasDurationChanged: (ctx, evt) => {
|
|
393
|
+
var _a;
|
|
394
|
+
return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx.duration;
|
|
395
|
+
}
|
|
419
396
|
},
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
(
|
|
397
|
+
delays: {
|
|
398
|
+
VISIBLE_DURATION: (ctx) => ctx.remaining,
|
|
399
|
+
REMOVE_DELAY: (ctx) => ctx.removeDelay
|
|
423
400
|
},
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
401
|
+
actions: {
|
|
402
|
+
setRemainingDuration(ctx) {
|
|
403
|
+
ctx.remaining -= Date.now() - ctx.createdAt;
|
|
404
|
+
},
|
|
405
|
+
setCreatedAt(ctx) {
|
|
406
|
+
ctx.createdAt = Date.now();
|
|
407
|
+
},
|
|
408
|
+
notifyParentToRemove(_ctx, _evt, { self }) {
|
|
409
|
+
self.sendParent({ type: "REMOVE_TOAST", id: self.id });
|
|
410
|
+
},
|
|
411
|
+
invokeOnClosing(ctx) {
|
|
412
|
+
var _a;
|
|
413
|
+
(_a = ctx.onClosing) == null ? void 0 : _a.call(ctx);
|
|
414
|
+
},
|
|
415
|
+
invokeOnClose(ctx) {
|
|
416
|
+
var _a;
|
|
417
|
+
(_a = ctx.onClose) == null ? void 0 : _a.call(ctx);
|
|
418
|
+
},
|
|
419
|
+
invokeOnOpen(ctx) {
|
|
420
|
+
var _a;
|
|
421
|
+
(_a = ctx.onOpen) == null ? void 0 : _a.call(ctx);
|
|
422
|
+
},
|
|
423
|
+
invokeOnUpdate(ctx) {
|
|
424
|
+
var _a;
|
|
425
|
+
(_a = ctx.onUpdate) == null ? void 0 : _a.call(ctx);
|
|
426
|
+
},
|
|
427
|
+
setContext(ctx, evt) {
|
|
428
|
+
const { duration: duration2, type: type2 } = evt.toast;
|
|
429
|
+
const time = getToastDuration(duration2, type2);
|
|
430
|
+
Object.assign(ctx, { ...evt.toast, duration: time, remaining: time });
|
|
431
|
+
}
|
|
428
432
|
}
|
|
429
433
|
}
|
|
430
|
-
|
|
434
|
+
);
|
|
431
435
|
}
|
|
432
436
|
|
|
433
437
|
// src/toast-group.machine.ts
|
|
@@ -531,6 +535,7 @@ function connect(state, send, normalize) {
|
|
|
531
535
|
return {
|
|
532
536
|
type: state.context.type,
|
|
533
537
|
title: state.context.title,
|
|
538
|
+
description: state.context.description,
|
|
534
539
|
placement,
|
|
535
540
|
isVisible,
|
|
536
541
|
isPaused,
|
|
@@ -603,6 +608,10 @@ function connect(state, send, normalize) {
|
|
|
603
608
|
"data-part": "title",
|
|
604
609
|
id: dom.getTitleId(state.context)
|
|
605
610
|
}),
|
|
611
|
+
descriptionProps: normalize.element({
|
|
612
|
+
"data-part": "description",
|
|
613
|
+
id: dom.getDescriptionId(state.context)
|
|
614
|
+
}),
|
|
606
615
|
closeButtonProps: normalize.button({
|
|
607
616
|
id: dom.getCloseButtonId(state.context),
|
|
608
617
|
"data-part": "close-button",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.1.
|
|
33
|
-
"@zag-js/types": "0.2.
|
|
32
|
+
"@zag-js/core": "0.1.10",
|
|
33
|
+
"@zag-js/types": "0.2.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@zag-js/dom-utils": "0.1.
|
|
37
|
-
"@zag-js/utils": "0.1.
|
|
36
|
+
"@zag-js/dom-utils": "0.1.11",
|
|
37
|
+
"@zag-js/utils": "0.1.4"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build-fast": "tsup src/index.ts --format=esm,cjs",
|