@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
@@ -0,0 +1,257 @@
1
+ // src/toast-group.machine.ts
2
+ import { setup } from "@zag-js/core";
3
+ import { trackDismissableBranch } from "@zag-js/dismissable";
4
+ import { addDomEvent, AnimationFrame } from "@zag-js/dom-query";
5
+ import { uuid } from "@zag-js/utils";
6
+ import * as dom from "./toast.dom.mjs";
7
+ var { guards, createMachine } = setup();
8
+ var { and } = guards;
9
+ var groupMachine = createMachine({
10
+ props({ props }) {
11
+ return {
12
+ dir: "ltr",
13
+ id: uuid(),
14
+ ...props,
15
+ store: props.store
16
+ };
17
+ },
18
+ initialState({ prop }) {
19
+ return prop("store").attrs.overlap ? "overlap" : "stack";
20
+ },
21
+ refs() {
22
+ return {
23
+ lastFocusedEl: null,
24
+ isFocusWithin: false,
25
+ isPointerWithin: false,
26
+ ignoreMouseTimer: AnimationFrame.create(),
27
+ dismissableCleanup: void 0
28
+ };
29
+ },
30
+ context({ bindable }) {
31
+ return {
32
+ toasts: bindable(() => ({
33
+ defaultValue: [],
34
+ sync: true,
35
+ hash: (toasts) => toasts.map((t) => t.id).join(",")
36
+ })),
37
+ heights: bindable(() => ({
38
+ defaultValue: [],
39
+ sync: true
40
+ }))
41
+ };
42
+ },
43
+ computed: {
44
+ count: ({ context }) => context.get("toasts").length,
45
+ overlap: ({ prop }) => prop("store").attrs.overlap,
46
+ placement: ({ prop }) => prop("store").attrs.placement
47
+ },
48
+ effects: ["subscribeToStore", "trackDocumentVisibility", "trackHotKeyPress"],
49
+ watch({ track, context, action }) {
50
+ track([() => context.hash("toasts")], () => {
51
+ queueMicrotask(() => {
52
+ action(["collapsedIfEmpty", "setDismissableBranch"]);
53
+ });
54
+ });
55
+ },
56
+ exit: ["clearDismissableBranch", "clearLastFocusedEl", "clearMouseEventTimer"],
57
+ on: {
58
+ "DOC.HOTKEY": {
59
+ actions: ["focusRegionEl"]
60
+ },
61
+ "REGION.BLUR": [
62
+ {
63
+ guard: and("isOverlapping", "isPointerOut"),
64
+ target: "overlap",
65
+ actions: ["collapseToasts", "resumeToasts", "restoreFocusIfPointerOut"]
66
+ },
67
+ {
68
+ guard: "isPointerOut",
69
+ target: "stack",
70
+ actions: ["resumeToasts", "restoreFocusIfPointerOut"]
71
+ },
72
+ {
73
+ actions: ["clearFocusWithin"]
74
+ }
75
+ ],
76
+ "TOAST.REMOVE": {
77
+ actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
78
+ },
79
+ "TOAST.PAUSE": {
80
+ actions: ["pauseToasts"]
81
+ }
82
+ },
83
+ states: {
84
+ stack: {
85
+ on: {
86
+ "REGION.POINTER_LEAVE": [
87
+ {
88
+ guard: "isOverlapping",
89
+ target: "overlap",
90
+ actions: ["clearPointerWithin", "resumeToasts", "collapseToasts"]
91
+ },
92
+ {
93
+ actions: ["clearPointerWithin", "resumeToasts"]
94
+ }
95
+ ],
96
+ "REGION.OVERLAP": {
97
+ target: "overlap",
98
+ actions: ["collapseToasts"]
99
+ },
100
+ "REGION.FOCUS": {
101
+ actions: ["setLastFocusedEl", "pauseToasts"]
102
+ },
103
+ "REGION.POINTER_ENTER": {
104
+ actions: ["setPointerWithin", "pauseToasts"]
105
+ }
106
+ }
107
+ },
108
+ overlap: {
109
+ on: {
110
+ "REGION.STACK": {
111
+ target: "stack",
112
+ actions: ["expandToasts"]
113
+ },
114
+ "REGION.POINTER_ENTER": {
115
+ target: "stack",
116
+ actions: ["setPointerWithin", "pauseToasts", "expandToasts"]
117
+ },
118
+ "REGION.FOCUS": {
119
+ target: "stack",
120
+ actions: ["setLastFocusedEl", "pauseToasts", "expandToasts"]
121
+ }
122
+ }
123
+ }
124
+ },
125
+ implementations: {
126
+ guards: {
127
+ isOverlapping: ({ computed }) => computed("overlap"),
128
+ isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
129
+ },
130
+ effects: {
131
+ subscribeToStore({ context, prop }) {
132
+ const store = prop("store");
133
+ context.set("toasts", store.getVisibleToasts());
134
+ return store.subscribe((toast) => {
135
+ if (toast.dismiss) {
136
+ context.set("toasts", (prev) => prev.filter((t) => t.id !== toast.id));
137
+ return;
138
+ }
139
+ context.set("toasts", (prev) => {
140
+ const index = prev.findIndex((t) => t.id === toast.id);
141
+ if (index !== -1) {
142
+ return [...prev.slice(0, index), { ...prev[index], ...toast }, ...prev.slice(index + 1)];
143
+ }
144
+ return [toast, ...prev];
145
+ });
146
+ });
147
+ },
148
+ trackHotKeyPress({ prop, send }) {
149
+ const handleKeyDown = (event) => {
150
+ const { hotkey } = prop("store").attrs;
151
+ const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
152
+ if (!isHotkeyPressed) return;
153
+ send({ type: "DOC.HOTKEY" });
154
+ };
155
+ return addDomEvent(document, "keydown", handleKeyDown, { capture: true });
156
+ },
157
+ trackDocumentVisibility({ prop, send, scope }) {
158
+ const { pauseOnPageIdle } = prop("store").attrs;
159
+ if (!pauseOnPageIdle) return;
160
+ const doc = scope.getDoc();
161
+ return addDomEvent(doc, "visibilitychange", () => {
162
+ const isHidden = doc.visibilityState === "hidden";
163
+ send({ type: isHidden ? "PAUSE_ALL" : "RESUME_ALL" });
164
+ });
165
+ }
166
+ },
167
+ actions: {
168
+ setDismissableBranch({ refs, context, computed, scope }) {
169
+ const toasts = context.get("toasts");
170
+ const placement = computed("placement");
171
+ const hasToasts = toasts.length > 0;
172
+ if (!hasToasts) {
173
+ refs.get("dismissableCleanup")?.();
174
+ return;
175
+ }
176
+ if (hasToasts && refs.get("dismissableCleanup")) {
177
+ return;
178
+ }
179
+ const groupEl = () => dom.getRegionEl(scope, placement);
180
+ const cleanup = trackDismissableBranch(groupEl, { defer: true });
181
+ refs.set("dismissableCleanup", cleanup);
182
+ },
183
+ clearDismissableBranch({ refs }) {
184
+ refs.get("dismissableCleanup")?.();
185
+ },
186
+ focusRegionEl({ scope, computed }) {
187
+ queueMicrotask(() => {
188
+ dom.getRegionEl(scope, computed("placement"))?.focus();
189
+ });
190
+ },
191
+ pauseToasts({ prop }) {
192
+ prop("store").pause();
193
+ },
194
+ resumeToasts({ prop }) {
195
+ prop("store").resume();
196
+ },
197
+ expandToasts({ prop }) {
198
+ prop("store").expand();
199
+ },
200
+ collapseToasts({ prop }) {
201
+ prop("store").collapse();
202
+ },
203
+ removeToast({ prop, event }) {
204
+ prop("store").remove(event.id);
205
+ },
206
+ removeHeight({ event, context }) {
207
+ if (event?.id == null) return;
208
+ queueMicrotask(() => {
209
+ context.set("heights", (heights) => heights.filter((height) => height.id !== event.id));
210
+ });
211
+ },
212
+ collapsedIfEmpty({ send, computed }) {
213
+ if (!computed("overlap") || computed("count") > 1) return;
214
+ send({ type: "REGION.OVERLAP" });
215
+ },
216
+ setLastFocusedEl({ refs, event }) {
217
+ if (refs.get("isFocusWithin") || !event.target) return;
218
+ refs.set("isFocusWithin", true);
219
+ refs.set("lastFocusedEl", event.target);
220
+ },
221
+ restoreFocusIfPointerOut({ refs }) {
222
+ if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
223
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
224
+ refs.set("lastFocusedEl", null);
225
+ refs.set("isFocusWithin", false);
226
+ },
227
+ setPointerWithin({ refs }) {
228
+ refs.set("isPointerWithin", true);
229
+ },
230
+ clearPointerWithin({ refs }) {
231
+ refs.set("isPointerWithin", false);
232
+ if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
233
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
234
+ refs.set("lastFocusedEl", null);
235
+ }
236
+ },
237
+ clearFocusWithin({ refs }) {
238
+ refs.set("isFocusWithin", false);
239
+ },
240
+ clearLastFocusedEl({ refs }) {
241
+ if (!refs.get("lastFocusedEl")) return;
242
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
243
+ refs.set("lastFocusedEl", null);
244
+ refs.set("isFocusWithin", false);
245
+ },
246
+ ignoreMouseEventsTemporarily({ refs }) {
247
+ refs.get("ignoreMouseTimer").request();
248
+ },
249
+ clearMouseEventTimer({ refs }) {
250
+ refs.get("ignoreMouseTimer").cancel();
251
+ }
252
+ }
253
+ }
254
+ });
255
+ export {
256
+ groupMachine
257
+ };
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger">;
4
+ declare const parts: Record<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger">;
4
+ declare const parts: Record<"group" | "title" | "root" | "description" | "actionTrigger" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/toast.anatomy.ts
21
+ var toast_anatomy_exports = {};
22
+ __export(toast_anatomy_exports, {
23
+ anatomy: () => anatomy,
24
+ parts: () => parts
25
+ });
26
+ module.exports = __toCommonJS(toast_anatomy_exports);
27
+ var import_anatomy = require("@zag-js/anatomy");
28
+ var anatomy = (0, import_anatomy.createAnatomy)("toast").parts(
29
+ "group",
30
+ "root",
31
+ "title",
32
+ "description",
33
+ "actionTrigger",
34
+ "closeTrigger"
35
+ );
36
+ var parts = anatomy.build();
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ anatomy,
40
+ parts
41
+ });
@@ -0,0 +1,15 @@
1
+ // src/toast.anatomy.ts
2
+ import { createAnatomy } from "@zag-js/anatomy";
3
+ var anatomy = createAnatomy("toast").parts(
4
+ "group",
5
+ "root",
6
+ "title",
7
+ "description",
8
+ "actionTrigger",
9
+ "closeTrigger"
10
+ );
11
+ var parts = anatomy.build();
12
+ export {
13
+ anatomy,
14
+ parts
15
+ };
@@ -0,0 +1,8 @@
1
+ import { Service } from '@zag-js/core';
2
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import { ToastSchema, ToastApi } from './toast.types.mjs';
4
+ import '@zag-js/dom-query';
5
+
6
+ declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
7
+
8
+ export { connect };
@@ -0,0 +1,8 @@
1
+ import { Service } from '@zag-js/core';
2
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import { ToastSchema, ToastApi } from './toast.types.js';
4
+ import '@zag-js/dom-query';
5
+
6
+ declare function connect<T extends PropTypes, O>(service: Service<ToastSchema<O>>, normalize: NormalizeProps<T>): ToastApi<T, O>;
7
+
8
+ export { connect };
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/toast.connect.ts
31
+ var toast_connect_exports = {};
32
+ __export(toast_connect_exports, {
33
+ connect: () => connect
34
+ });
35
+ module.exports = __toCommonJS(toast_connect_exports);
36
+ var import_dom_query = require("@zag-js/dom-query");
37
+ var import_toast = require("./toast.anatomy.cjs");
38
+ var dom = __toESM(require("./toast.dom.cjs"));
39
+ var import_toast2 = require("./toast.utils.cjs");
40
+ function connect(service, normalize) {
41
+ const { state, send, prop, scope, context, computed } = service;
42
+ const visible = state.hasTag("visible");
43
+ const paused = state.hasTag("paused");
44
+ const mounted = context.get("mounted");
45
+ const frontmost = computed("frontmost");
46
+ const placement = prop("parent").computed("placement");
47
+ const type = prop("type");
48
+ const stacked = prop("stacked");
49
+ const title = prop("title");
50
+ const description = prop("description");
51
+ const action = prop("action");
52
+ const [side, align = "center"] = placement.split("-");
53
+ return {
54
+ type,
55
+ title,
56
+ description,
57
+ placement,
58
+ visible,
59
+ paused,
60
+ closable: !!prop("closable"),
61
+ pause() {
62
+ send({ type: "PAUSE" });
63
+ },
64
+ resume() {
65
+ send({ type: "RESUME" });
66
+ },
67
+ dismiss() {
68
+ send({ type: "DISMISS", src: "programmatic" });
69
+ },
70
+ getRootProps() {
71
+ return normalize.element({
72
+ ...import_toast.parts.root.attrs,
73
+ dir: prop("dir"),
74
+ id: dom.getRootId(scope),
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),
86
+ role: "status",
87
+ "aria-atomic": "true",
88
+ "aria-describedby": description ? dom.getDescriptionId(scope) : void 0,
89
+ "aria-labelledby": title ? dom.getTitleId(scope) : void 0,
90
+ tabIndex: 0,
91
+ style: (0, import_toast2.getPlacementStyle)(service, visible),
92
+ onKeyDown(event) {
93
+ if (event.defaultPrevented) return;
94
+ if (event.key == "Escape") {
95
+ send({ type: "DISMISS", src: "keyboard" });
96
+ event.preventDefault();
97
+ }
98
+ }
99
+ });
100
+ },
101
+ /* Leave a ghost div to avoid setting hover to false when transitioning out */
102
+ getGhostBeforeProps() {
103
+ return normalize.element({
104
+ "data-ghost": "before",
105
+ style: (0, import_toast2.getGhostBeforeStyle)(service, visible)
106
+ });
107
+ },
108
+ /* Needed to avoid setting hover to false when in between toasts */
109
+ getGhostAfterProps() {
110
+ return normalize.element({
111
+ "data-ghost": "after",
112
+ style: (0, import_toast2.getGhostAfterStyle)()
113
+ });
114
+ },
115
+ getTitleProps() {
116
+ return normalize.element({
117
+ ...import_toast.parts.title.attrs,
118
+ id: dom.getTitleId(scope)
119
+ });
120
+ },
121
+ getDescriptionProps() {
122
+ return normalize.element({
123
+ ...import_toast.parts.description.attrs,
124
+ id: dom.getDescriptionId(scope)
125
+ });
126
+ },
127
+ getActionTriggerProps() {
128
+ return normalize.button({
129
+ ...import_toast.parts.actionTrigger.attrs,
130
+ type: "button",
131
+ onClick(event) {
132
+ if (event.defaultPrevented) return;
133
+ action?.onClick?.();
134
+ send({ type: "DISMISS", src: "user" });
135
+ }
136
+ });
137
+ },
138
+ getCloseTriggerProps() {
139
+ return normalize.button({
140
+ id: dom.getCloseTriggerId(scope),
141
+ ...import_toast.parts.closeTrigger.attrs,
142
+ type: "button",
143
+ "aria-label": "Dismiss notification",
144
+ onClick(event) {
145
+ if (event.defaultPrevented) return;
146
+ send({ type: "DISMISS", src: "user" });
147
+ }
148
+ });
149
+ }
150
+ };
151
+ }
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ connect
155
+ });
@@ -0,0 +1,120 @@
1
+ // src/toast.connect.ts
2
+ import { dataAttr } from "@zag-js/dom-query";
3
+ import { parts } from "./toast.anatomy.mjs";
4
+ import * as dom from "./toast.dom.mjs";
5
+ import { getGhostAfterStyle, getGhostBeforeStyle, getPlacementStyle } from "./toast.utils.mjs";
6
+ function connect(service, normalize) {
7
+ const { state, send, prop, scope, context, computed } = service;
8
+ const visible = state.hasTag("visible");
9
+ const paused = state.hasTag("paused");
10
+ const mounted = context.get("mounted");
11
+ const frontmost = computed("frontmost");
12
+ const placement = prop("parent").computed("placement");
13
+ const type = prop("type");
14
+ const stacked = prop("stacked");
15
+ const title = prop("title");
16
+ const description = prop("description");
17
+ const action = prop("action");
18
+ const [side, align = "center"] = placement.split("-");
19
+ return {
20
+ type,
21
+ title,
22
+ description,
23
+ placement,
24
+ visible,
25
+ paused,
26
+ closable: !!prop("closable"),
27
+ pause() {
28
+ send({ type: "PAUSE" });
29
+ },
30
+ resume() {
31
+ send({ type: "RESUME" });
32
+ },
33
+ dismiss() {
34
+ send({ type: "DISMISS", src: "programmatic" });
35
+ },
36
+ getRootProps() {
37
+ return normalize.element({
38
+ ...parts.root.attrs,
39
+ dir: prop("dir"),
40
+ id: dom.getRootId(scope),
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),
52
+ role: "status",
53
+ "aria-atomic": "true",
54
+ "aria-describedby": description ? dom.getDescriptionId(scope) : void 0,
55
+ "aria-labelledby": title ? dom.getTitleId(scope) : void 0,
56
+ tabIndex: 0,
57
+ style: getPlacementStyle(service, visible),
58
+ onKeyDown(event) {
59
+ if (event.defaultPrevented) return;
60
+ if (event.key == "Escape") {
61
+ send({ type: "DISMISS", src: "keyboard" });
62
+ event.preventDefault();
63
+ }
64
+ }
65
+ });
66
+ },
67
+ /* Leave a ghost div to avoid setting hover to false when transitioning out */
68
+ getGhostBeforeProps() {
69
+ return normalize.element({
70
+ "data-ghost": "before",
71
+ style: getGhostBeforeStyle(service, visible)
72
+ });
73
+ },
74
+ /* Needed to avoid setting hover to false when in between toasts */
75
+ getGhostAfterProps() {
76
+ return normalize.element({
77
+ "data-ghost": "after",
78
+ style: getGhostAfterStyle()
79
+ });
80
+ },
81
+ getTitleProps() {
82
+ return normalize.element({
83
+ ...parts.title.attrs,
84
+ id: dom.getTitleId(scope)
85
+ });
86
+ },
87
+ getDescriptionProps() {
88
+ return normalize.element({
89
+ ...parts.description.attrs,
90
+ id: dom.getDescriptionId(scope)
91
+ });
92
+ },
93
+ getActionTriggerProps() {
94
+ return normalize.button({
95
+ ...parts.actionTrigger.attrs,
96
+ type: "button",
97
+ onClick(event) {
98
+ if (event.defaultPrevented) return;
99
+ action?.onClick?.();
100
+ send({ type: "DISMISS", src: "user" });
101
+ }
102
+ });
103
+ },
104
+ getCloseTriggerProps() {
105
+ return normalize.button({
106
+ id: dom.getCloseTriggerId(scope),
107
+ ...parts.closeTrigger.attrs,
108
+ type: "button",
109
+ "aria-label": "Dismiss notification",
110
+ onClick(event) {
111
+ if (event.defaultPrevented) return;
112
+ send({ type: "DISMISS", src: "user" });
113
+ }
114
+ });
115
+ }
116
+ };
117
+ }
118
+ export {
119
+ connect
120
+ };
@@ -0,0 +1,14 @@
1
+ import { Scope } from '@zag-js/core';
2
+ import { Placement } from './toast.types.mjs';
3
+ import '@zag-js/types';
4
+ import '@zag-js/dom-query';
5
+
6
+ declare const getRegionId: (placement: Placement) => string;
7
+ declare const getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
8
+ declare const getRootId: (ctx: Scope) => string;
9
+ declare const getRootEl: (ctx: Scope) => HTMLElement | null;
10
+ declare const getTitleId: (ctx: Scope) => string;
11
+ declare const getDescriptionId: (ctx: Scope) => string;
12
+ declare const getCloseTriggerId: (ctx: Scope) => string;
13
+
14
+ export { getCloseTriggerId, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleId };
@@ -0,0 +1,14 @@
1
+ import { Scope } from '@zag-js/core';
2
+ import { Placement } from './toast.types.js';
3
+ import '@zag-js/types';
4
+ import '@zag-js/dom-query';
5
+
6
+ declare const getRegionId: (placement: Placement) => string;
7
+ declare const getRegionEl: (ctx: Scope, placement: Placement) => HTMLElement | null;
8
+ declare const getRootId: (ctx: Scope) => string;
9
+ declare const getRootEl: (ctx: Scope) => HTMLElement | null;
10
+ declare const getTitleId: (ctx: Scope) => string;
11
+ declare const getDescriptionId: (ctx: Scope) => string;
12
+ declare const getCloseTriggerId: (ctx: Scope) => string;
13
+
14
+ export { getCloseTriggerId, getDescriptionId, getRegionEl, getRegionId, getRootEl, getRootId, getTitleId };