@zag-js/toast 2.0.0-next.0 → 2.0.0-next.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _zag_js_core from '@zag-js/core';
2
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, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, ToastQueuePriority, Type } from './toast.types.mjs';
3
+ export { ActionOptions, ToastApi as Api, ToastGroupApi as GroupApi, ToastGroupMachine as GroupMachine, ToastGroupProps as GroupProps, ToastGroupService as GroupService, GroupState, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, RootState, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, ToastQueuePriority, Type } from './toast.types.mjs';
4
4
  import { groupConnect } from './toast-group.connect.mjs';
5
5
  export { anatomy } from './toast.anatomy.mjs';
6
6
  export { connect } from './toast.connect.mjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _zag_js_core from '@zag-js/core';
2
2
  import { ToastGroupSchema } from './toast.types.js';
3
- export { ActionOptions, ToastApi as Api, ToastGroupApi as GroupApi, ToastGroupMachine as GroupMachine, ToastGroupProps as GroupProps, ToastGroupService as GroupService, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, ToastQueuePriority, Type } from './toast.types.js';
3
+ export { ActionOptions, ToastApi as Api, ToastGroupApi as GroupApi, ToastGroupMachine as GroupMachine, ToastGroupProps as GroupProps, ToastGroupService as GroupService, GroupState, IntlTranslations, ToastMachine as Machine, Options, Placement, PromiseOptions, ToastProps as Props, RootState, ToastService as Service, Status, StatusChangeDetails, ToastStore as Store, ToastStoreProps as StoreProps, ToastHeight, ToastQueuePriority, Type } from './toast.types.js';
4
4
  import { groupConnect } from './toast-group.connect.js';
5
5
  export { anatomy } from './toast.anatomy.js';
6
6
  export { connect } from './toast.connect.js';
@@ -39,6 +39,11 @@ var dom = __toESM(require("./toast.dom.js"));
39
39
  var import_toast2 = require("./toast.utils.js");
40
40
  function groupConnect(service, normalize) {
41
41
  const { context, prop, send, refs, computed, scope } = service;
42
+ function getGroupState() {
43
+ const placement = computed("placement");
44
+ const [side, align = "center"] = placement.split("-");
45
+ return { placement, side, align };
46
+ }
42
47
  return {
43
48
  getCount() {
44
49
  return context.get("toasts").length;
@@ -46,12 +51,13 @@ function groupConnect(service, normalize) {
46
51
  getToasts() {
47
52
  return context.get("toasts");
48
53
  },
54
+ getGroupState,
49
55
  getGroupProps(options = {}) {
50
56
  const { label = "Notifications" } = options;
51
57
  const { hotkey } = prop("store").attrs;
52
58
  const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
53
- const placement = computed("placement");
54
- const [side, align = "center"] = placement.split("-");
59
+ const groupState = getGroupState();
60
+ const { placement, side, align } = groupState;
55
61
  return normalize.element({
56
62
  ...import_toast.parts.group.attrs(scope.id),
57
63
  dir: prop("dir"),
@@ -5,6 +5,11 @@ import * as dom from "./toast.dom.mjs";
5
5
  import { getGroupPlacementStyle } from "./toast.utils.mjs";
6
6
  function groupConnect(service, normalize) {
7
7
  const { context, prop, send, refs, computed, scope } = service;
8
+ function getGroupState() {
9
+ const placement = computed("placement");
10
+ const [side, align = "center"] = placement.split("-");
11
+ return { placement, side, align };
12
+ }
8
13
  return {
9
14
  getCount() {
10
15
  return context.get("toasts").length;
@@ -12,12 +17,13 @@ function groupConnect(service, normalize) {
12
17
  getToasts() {
13
18
  return context.get("toasts");
14
19
  },
20
+ getGroupState,
15
21
  getGroupProps(options = {}) {
16
22
  const { label = "Notifications" } = options;
17
23
  const { hotkey } = prop("store").attrs;
18
24
  const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
19
- const placement = computed("placement");
20
- const [side, align = "center"] = placement.split("-");
25
+ const groupState = getGroupState();
26
+ const { placement, side, align } = groupState;
21
27
  return normalize.element({
22
28
  ...parts.group.attrs(scope.id),
23
29
  dir: prop("dir"),
@@ -51,6 +51,9 @@ function connect(service, normalize) {
51
51
  const description = prop("description");
52
52
  const action = prop("action");
53
53
  const [side, align = "center"] = placement.split("-");
54
+ function getRootState() {
55
+ return { visible, paused, mounted, frontmost, stacked: !!stacked, type, placement, side, align };
56
+ }
54
57
  return {
55
58
  type,
56
59
  title,
@@ -68,21 +71,23 @@ function connect(service, normalize) {
68
71
  dismiss() {
69
72
  send({ type: "DISMISS", src: "programmatic" });
70
73
  },
74
+ getRootState,
71
75
  getRootProps() {
76
+ const rootState = getRootState();
72
77
  return normalize.element({
73
78
  ...import_toast.parts.root.attrs(scope.id),
74
79
  dir: prop("dir"),
75
- "data-state": visible ? "open" : "closed",
76
- "data-type": type,
77
- "data-placement": placement,
78
- "data-align": align,
79
- "data-side": side,
80
- "data-mounted": (0, import_dom_query.dataAttr)(mounted),
81
- "data-paused": (0, import_dom_query.dataAttr)(paused),
82
- "data-first": (0, import_dom_query.dataAttr)(frontmost),
83
- "data-sibling": (0, import_dom_query.dataAttr)(!frontmost),
84
- "data-stack": (0, import_dom_query.dataAttr)(stacked),
85
- "data-overlap": (0, import_dom_query.dataAttr)(!stacked),
80
+ "data-state": rootState.visible ? "open" : "closed",
81
+ "data-type": rootState.type,
82
+ "data-placement": rootState.placement,
83
+ "data-align": rootState.align,
84
+ "data-side": rootState.side,
85
+ "data-mounted": (0, import_dom_query.dataAttr)(rootState.mounted),
86
+ "data-paused": (0, import_dom_query.dataAttr)(rootState.paused),
87
+ "data-first": (0, import_dom_query.dataAttr)(rootState.frontmost),
88
+ "data-sibling": (0, import_dom_query.dataAttr)(!rootState.frontmost),
89
+ "data-stack": (0, import_dom_query.dataAttr)(rootState.stacked),
90
+ "data-overlap": (0, import_dom_query.dataAttr)(!rootState.stacked),
86
91
  role: "status",
87
92
  "aria-atomic": "true",
88
93
  "aria-describedby": description ? dom.getDescriptionId(scope) : void 0,
@@ -17,6 +17,9 @@ function connect(service, normalize) {
17
17
  const description = prop("description");
18
18
  const action = prop("action");
19
19
  const [side, align = "center"] = placement.split("-");
20
+ function getRootState() {
21
+ return { visible, paused, mounted, frontmost, stacked: !!stacked, type, placement, side, align };
22
+ }
20
23
  return {
21
24
  type,
22
25
  title,
@@ -34,21 +37,23 @@ function connect(service, normalize) {
34
37
  dismiss() {
35
38
  send({ type: "DISMISS", src: "programmatic" });
36
39
  },
40
+ getRootState,
37
41
  getRootProps() {
42
+ const rootState = getRootState();
38
43
  return normalize.element({
39
44
  ...parts.root.attrs(scope.id),
40
45
  dir: prop("dir"),
41
- "data-state": visible ? "open" : "closed",
42
- "data-type": type,
43
- "data-placement": placement,
44
- "data-align": align,
45
- "data-side": side,
46
- "data-mounted": dataAttr(mounted),
47
- "data-paused": dataAttr(paused),
48
- "data-first": dataAttr(frontmost),
49
- "data-sibling": dataAttr(!frontmost),
50
- "data-stack": dataAttr(stacked),
51
- "data-overlap": dataAttr(!stacked),
46
+ "data-state": rootState.visible ? "open" : "closed",
47
+ "data-type": rootState.type,
48
+ "data-placement": rootState.placement,
49
+ "data-align": rootState.align,
50
+ "data-side": rootState.side,
51
+ "data-mounted": dataAttr(rootState.mounted),
52
+ "data-paused": dataAttr(rootState.paused),
53
+ "data-first": dataAttr(rootState.frontmost),
54
+ "data-sibling": dataAttr(!rootState.frontmost),
55
+ "data-stack": dataAttr(rootState.stacked),
56
+ "data-overlap": dataAttr(!rootState.stacked),
52
57
  role: "status",
53
58
  "aria-atomic": "true",
54
59
  "aria-describedby": description ? dom.getDescriptionId(scope) : void 0,
@@ -205,10 +205,7 @@ var machine = (0, import_core.createMachine)({
205
205
  const rootEl = dom.getRootEl(scope);
206
206
  if (!rootEl) return;
207
207
  const syncHeight = () => {
208
- const originalHeight = rootEl.style.height;
209
- rootEl.style.height = "auto";
210
- const height = rootEl.getBoundingClientRect().height;
211
- rootEl.style.height = originalHeight;
208
+ const height = measureLayoutHeight(rootEl);
212
209
  const item = { id: prop("id"), height };
213
210
  setHeight(prop("parent"), item);
214
211
  };
@@ -238,10 +235,7 @@ var machine = (0, import_core.createMachine)({
238
235
  queueMicrotask(() => {
239
236
  const rootEl = dom.getRootEl(scope);
240
237
  if (!rootEl) return;
241
- const originalHeight = rootEl.style.height;
242
- rootEl.style.height = "auto";
243
- const height = rootEl.getBoundingClientRect().height;
244
- rootEl.style.height = originalHeight;
238
+ const height = measureLayoutHeight(rootEl);
245
239
  context.set("initialHeight", height);
246
240
  const item = { id: prop("id"), height };
247
241
  setHeight(prop("parent"), item);
@@ -278,6 +272,13 @@ var machine = (0, import_core.createMachine)({
278
272
  }
279
273
  }
280
274
  });
275
+ function measureLayoutHeight(el) {
276
+ const prevHeight = el.style.height;
277
+ el.style.height = "auto";
278
+ const height = el.offsetHeight;
279
+ el.style.height = prevHeight;
280
+ return height;
281
+ }
281
282
  function setHeight(parent, item) {
282
283
  const { id, height } = item;
283
284
  parent.context.set("heights", (prev) => {
@@ -171,10 +171,7 @@ var machine = createMachine({
171
171
  const rootEl = dom.getRootEl(scope);
172
172
  if (!rootEl) return;
173
173
  const syncHeight = () => {
174
- const originalHeight = rootEl.style.height;
175
- rootEl.style.height = "auto";
176
- const height = rootEl.getBoundingClientRect().height;
177
- rootEl.style.height = originalHeight;
174
+ const height = measureLayoutHeight(rootEl);
178
175
  const item = { id: prop("id"), height };
179
176
  setHeight(prop("parent"), item);
180
177
  };
@@ -204,10 +201,7 @@ var machine = createMachine({
204
201
  queueMicrotask(() => {
205
202
  const rootEl = dom.getRootEl(scope);
206
203
  if (!rootEl) return;
207
- const originalHeight = rootEl.style.height;
208
- rootEl.style.height = "auto";
209
- const height = rootEl.getBoundingClientRect().height;
210
- rootEl.style.height = originalHeight;
204
+ const height = measureLayoutHeight(rootEl);
211
205
  context.set("initialHeight", height);
212
206
  const item = { id: prop("id"), height };
213
207
  setHeight(prop("parent"), item);
@@ -244,6 +238,13 @@ var machine = createMachine({
244
238
  }
245
239
  }
246
240
  });
241
+ function measureLayoutHeight(el) {
242
+ const prevHeight = el.style.height;
243
+ el.style.height = "auto";
244
+ const height = el.offsetHeight;
245
+ el.style.height = prevHeight;
246
+ return height;
247
+ }
247
248
  function setHeight(parent, item) {
248
249
  const { id, height } = item;
249
250
  parent.context.set("heights", (prev) => {
@@ -26,6 +26,44 @@ interface ToastHeight {
26
26
  */
27
27
  height: number;
28
28
  }
29
+ interface RootState {
30
+ /**
31
+ * Whether the toast is visible
32
+ */
33
+ visible: boolean;
34
+ /**
35
+ * Whether the toast is paused
36
+ */
37
+ paused: boolean;
38
+ /**
39
+ * Whether the toast has mounted into the DOM
40
+ */
41
+ mounted: boolean;
42
+ /**
43
+ * Whether the toast is the frontmost (topmost) toast in the group
44
+ */
45
+ frontmost: boolean;
46
+ /**
47
+ * Whether the toasts in the group are stacked instead of overlapping
48
+ */
49
+ stacked: boolean;
50
+ /**
51
+ * The type of the toast
52
+ */
53
+ type: Type;
54
+ /**
55
+ * The placement of the toast
56
+ */
57
+ placement: Placement;
58
+ /**
59
+ * The side of the toast placement
60
+ */
61
+ side: string;
62
+ /**
63
+ * The horizontal alignment of the toast placement
64
+ */
65
+ align: string;
66
+ }
29
67
  interface ActionOptions {
30
68
  /**
31
69
  * The label of the action
@@ -317,6 +355,20 @@ interface GroupProps {
317
355
  */
318
356
  label?: string | undefined;
319
357
  }
358
+ interface GroupState {
359
+ /**
360
+ * The placement of the toast group
361
+ */
362
+ placement: Placement;
363
+ /**
364
+ * The side of the toast group placement
365
+ */
366
+ side: string;
367
+ /**
368
+ * The horizontal alignment of the toast group placement
369
+ */
370
+ align: string;
371
+ }
320
372
  interface ToastGroupApi<T extends PropTypes = PropTypes, O = any> {
321
373
  /**
322
374
  * The total number of toasts
@@ -330,6 +382,10 @@ interface ToastGroupApi<T extends PropTypes = PropTypes, O = any> {
330
382
  * Subscribe to the toast group
331
383
  */
332
384
  subscribe: (callback: (toasts: Options<O>[]) => void) => VoidFunction;
385
+ /**
386
+ * Returns the state of the group
387
+ */
388
+ getGroupState: () => GroupState;
333
389
  getGroupProps: (options?: GroupProps) => T["element"];
334
390
  }
335
391
  interface ToastApi<T extends PropTypes = PropTypes, O = any> {
@@ -373,6 +429,10 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
373
429
  * Function to instantly dismiss the toast.
374
430
  */
375
431
  dismiss: VoidFunction;
432
+ /**
433
+ * Returns the state of the root
434
+ */
435
+ getRootState: () => RootState;
376
436
  getRootProps: () => T["element"];
377
437
  getTitleProps: () => T["element"];
378
438
  getGhostBeforeProps: () => T["element"];
@@ -382,4 +442,4 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
382
442
  getActionTriggerProps: () => T["button"];
383
443
  }
384
444
 
385
- export type { ActionOptions, GroupProps, IntlTranslations, Options, Placement, PromiseOptions, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastQueuePriority, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
445
+ export type { ActionOptions, GroupProps, GroupState, IntlTranslations, Options, Placement, PromiseOptions, RootState, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastQueuePriority, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
@@ -26,6 +26,44 @@ interface ToastHeight {
26
26
  */
27
27
  height: number;
28
28
  }
29
+ interface RootState {
30
+ /**
31
+ * Whether the toast is visible
32
+ */
33
+ visible: boolean;
34
+ /**
35
+ * Whether the toast is paused
36
+ */
37
+ paused: boolean;
38
+ /**
39
+ * Whether the toast has mounted into the DOM
40
+ */
41
+ mounted: boolean;
42
+ /**
43
+ * Whether the toast is the frontmost (topmost) toast in the group
44
+ */
45
+ frontmost: boolean;
46
+ /**
47
+ * Whether the toasts in the group are stacked instead of overlapping
48
+ */
49
+ stacked: boolean;
50
+ /**
51
+ * The type of the toast
52
+ */
53
+ type: Type;
54
+ /**
55
+ * The placement of the toast
56
+ */
57
+ placement: Placement;
58
+ /**
59
+ * The side of the toast placement
60
+ */
61
+ side: string;
62
+ /**
63
+ * The horizontal alignment of the toast placement
64
+ */
65
+ align: string;
66
+ }
29
67
  interface ActionOptions {
30
68
  /**
31
69
  * The label of the action
@@ -317,6 +355,20 @@ interface GroupProps {
317
355
  */
318
356
  label?: string | undefined;
319
357
  }
358
+ interface GroupState {
359
+ /**
360
+ * The placement of the toast group
361
+ */
362
+ placement: Placement;
363
+ /**
364
+ * The side of the toast group placement
365
+ */
366
+ side: string;
367
+ /**
368
+ * The horizontal alignment of the toast group placement
369
+ */
370
+ align: string;
371
+ }
320
372
  interface ToastGroupApi<T extends PropTypes = PropTypes, O = any> {
321
373
  /**
322
374
  * The total number of toasts
@@ -330,6 +382,10 @@ interface ToastGroupApi<T extends PropTypes = PropTypes, O = any> {
330
382
  * Subscribe to the toast group
331
383
  */
332
384
  subscribe: (callback: (toasts: Options<O>[]) => void) => VoidFunction;
385
+ /**
386
+ * Returns the state of the group
387
+ */
388
+ getGroupState: () => GroupState;
333
389
  getGroupProps: (options?: GroupProps) => T["element"];
334
390
  }
335
391
  interface ToastApi<T extends PropTypes = PropTypes, O = any> {
@@ -373,6 +429,10 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
373
429
  * Function to instantly dismiss the toast.
374
430
  */
375
431
  dismiss: VoidFunction;
432
+ /**
433
+ * Returns the state of the root
434
+ */
435
+ getRootState: () => RootState;
376
436
  getRootProps: () => T["element"];
377
437
  getTitleProps: () => T["element"];
378
438
  getGhostBeforeProps: () => T["element"];
@@ -382,4 +442,4 @@ interface ToastApi<T extends PropTypes = PropTypes, O = any> {
382
442
  getActionTriggerProps: () => T["button"];
383
443
  }
384
444
 
385
- export type { ActionOptions, GroupProps, IntlTranslations, Options, Placement, PromiseOptions, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastQueuePriority, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
445
+ export type { ActionOptions, GroupProps, GroupState, IntlTranslations, Options, Placement, PromiseOptions, RootState, Status, StatusChangeDetails, ToastApi, ToastGroupApi, ToastGroupMachine, ToastGroupProps, ToastGroupSchema, ToastGroupService, ToastHeight, ToastMachine, ToastProps, ToastQueuePriority, ToastSchema, ToastService, ToastStore, ToastStoreProps, Type };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/toast",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.1",
4
4
  "description": "Core logic for the toast widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -14,7 +14,10 @@
14
14
  "author": "Segun Adebayo <sage@adebayosegun.com>",
15
15
  "homepage": "https://github.com/chakra-ui/zag#readme",
16
16
  "license": "MIT",
17
- "repository": "https://github.com/chakra-ui/zag/tree/main/packages/toast",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/chakra-ui/zag/tree/main/packages/toast"
20
+ },
18
21
  "sideEffects": false,
19
22
  "files": [
20
23
  "dist"
@@ -26,12 +29,12 @@
26
29
  "url": "https://github.com/chakra-ui/zag/issues"
27
30
  },
28
31
  "dependencies": {
29
- "@zag-js/anatomy": "2.0.0-next.0",
30
- "@zag-js/core": "2.0.0-next.0",
31
- "@zag-js/dom-query": "2.0.0-next.0",
32
- "@zag-js/dismissable": "2.0.0-next.0",
33
- "@zag-js/utils": "2.0.0-next.0",
34
- "@zag-js/types": "2.0.0-next.0"
32
+ "@zag-js/anatomy": "2.0.0-next.1",
33
+ "@zag-js/core": "2.0.0-next.1",
34
+ "@zag-js/dom-query": "2.0.0-next.1",
35
+ "@zag-js/dismissable": "2.0.0-next.1",
36
+ "@zag-js/types": "2.0.0-next.1",
37
+ "@zag-js/utils": "2.0.0-next.1"
35
38
  },
36
39
  "devDependencies": {
37
40
  "clean-package": "2.2.0"