@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.
- package/dist/index.d.mts +11 -365
- package/dist/index.d.ts +11 -365
- package/dist/index.js +40 -1084
- package/dist/index.mjs +13 -1080
- package/dist/toast-group.connect.d.mts +8 -0
- package/dist/toast-group.connect.d.ts +8 -0
- package/dist/toast-group.connect.js +98 -0
- package/dist/toast-group.connect.mjs +63 -0
- package/dist/toast-group.machine.d.mts +8 -0
- package/dist/toast-group.machine.d.ts +8 -0
- package/dist/toast-group.machine.js +292 -0
- package/dist/toast-group.machine.mjs +257 -0
- package/dist/toast.anatomy.d.mts +6 -0
- package/dist/toast.anatomy.d.ts +6 -0
- package/dist/toast.anatomy.js +41 -0
- package/dist/toast.anatomy.mjs +15 -0
- package/dist/toast.connect.d.mts +8 -0
- package/dist/toast.connect.d.ts +8 -0
- package/dist/toast.connect.js +155 -0
- package/dist/toast.connect.mjs +120 -0
- package/dist/toast.dom.d.mts +14 -0
- package/dist/toast.dom.d.ts +14 -0
- package/dist/toast.dom.js +48 -0
- package/dist/toast.dom.mjs +17 -0
- package/dist/toast.machine.d.mts +8 -0
- package/dist/toast.machine.d.ts +8 -0
- package/dist/toast.machine.js +291 -0
- package/dist/toast.machine.mjs +256 -0
- package/dist/toast.store.d.mts +8 -0
- package/dist/toast.store.d.ts +8 -0
- package/dist/toast.store.js +249 -0
- package/dist/toast.store.mjs +224 -0
- package/dist/toast.types.d.mts +371 -0
- package/dist/toast.types.d.ts +371 -0
- package/dist/toast.types.js +18 -0
- package/dist/toast.types.mjs +0 -0
- package/dist/toast.utils.d.mts +13 -0
- package/dist/toast.utils.d.ts +13 -0
- package/dist/toast.utils.js +209 -0
- package/dist/toast.utils.mjs +179 -0
- package/package.json +18 -8
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// src/toast.utils.ts
|
|
2
|
+
import { MAX_Z_INDEX } from "@zag-js/dom-query";
|
|
3
|
+
var defaultTimeouts = {
|
|
4
|
+
info: 5e3,
|
|
5
|
+
error: 5e3,
|
|
6
|
+
success: 2e3,
|
|
7
|
+
loading: Infinity,
|
|
8
|
+
DEFAULT: 5e3
|
|
9
|
+
};
|
|
10
|
+
function getToastDuration(duration, type) {
|
|
11
|
+
return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
|
|
12
|
+
}
|
|
13
|
+
var getOffsets = (offsets) => typeof offsets === "string" ? { left: offsets, right: offsets, bottom: offsets, top: offsets } : offsets;
|
|
14
|
+
function getGroupPlacementStyle(service, placement) {
|
|
15
|
+
const { prop, computed, context } = service;
|
|
16
|
+
const { offsets, gap } = prop("store").attrs;
|
|
17
|
+
const heights = context.get("heights");
|
|
18
|
+
const computedOffset = getOffsets(offsets);
|
|
19
|
+
const rtl = prop("dir") === "rtl";
|
|
20
|
+
const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
|
|
21
|
+
const isRighty = computedPlacement.includes("right");
|
|
22
|
+
const isLefty = computedPlacement.includes("left");
|
|
23
|
+
const styles = {
|
|
24
|
+
position: "fixed",
|
|
25
|
+
pointerEvents: computed("count") > 0 ? void 0 : "none",
|
|
26
|
+
display: "flex",
|
|
27
|
+
flexDirection: "column",
|
|
28
|
+
"--gap": `${gap}px`,
|
|
29
|
+
"--first-height": `${heights[0]?.height || 0}px`,
|
|
30
|
+
"--viewport-offset-left": computedOffset.left,
|
|
31
|
+
"--viewport-offset-right": computedOffset.right,
|
|
32
|
+
"--viewport-offset-top": computedOffset.top,
|
|
33
|
+
"--viewport-offset-bottom": computedOffset.bottom,
|
|
34
|
+
zIndex: MAX_Z_INDEX
|
|
35
|
+
};
|
|
36
|
+
let alignItems = "center";
|
|
37
|
+
if (isRighty) alignItems = "flex-end";
|
|
38
|
+
if (isLefty) alignItems = "flex-start";
|
|
39
|
+
styles.alignItems = alignItems;
|
|
40
|
+
if (computedPlacement.includes("top")) {
|
|
41
|
+
const offset = computedOffset.top;
|
|
42
|
+
styles.top = `max(env(safe-area-inset-top, 0px), ${offset})`;
|
|
43
|
+
}
|
|
44
|
+
if (computedPlacement.includes("bottom")) {
|
|
45
|
+
const offset = computedOffset.bottom;
|
|
46
|
+
styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${offset})`;
|
|
47
|
+
}
|
|
48
|
+
if (!computedPlacement.includes("left")) {
|
|
49
|
+
const offset = computedOffset.right;
|
|
50
|
+
styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${offset})`;
|
|
51
|
+
}
|
|
52
|
+
if (!computedPlacement.includes("right")) {
|
|
53
|
+
const offset = computedOffset.left;
|
|
54
|
+
styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${offset})`;
|
|
55
|
+
}
|
|
56
|
+
return styles;
|
|
57
|
+
}
|
|
58
|
+
function getPlacementStyle(service, visible) {
|
|
59
|
+
const { prop, context, computed } = service;
|
|
60
|
+
const parent = prop("parent");
|
|
61
|
+
const placement = parent.computed("placement");
|
|
62
|
+
const { gap } = parent.prop("store").attrs;
|
|
63
|
+
const [side] = placement.split("-");
|
|
64
|
+
const mounted = context.get("mounted");
|
|
65
|
+
const remainingTime = context.get("remainingTime");
|
|
66
|
+
const height = computed("height");
|
|
67
|
+
const frontmost = computed("frontmost");
|
|
68
|
+
const sibling = !frontmost;
|
|
69
|
+
const overlap = !prop("stacked");
|
|
70
|
+
const stacked = prop("stacked");
|
|
71
|
+
const type = prop("type");
|
|
72
|
+
const duration = type === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
|
|
73
|
+
const offset = computed("heightIndex") * gap + computed("heightBefore");
|
|
74
|
+
const styles = {
|
|
75
|
+
position: "absolute",
|
|
76
|
+
pointerEvents: "auto",
|
|
77
|
+
"--opacity": "0",
|
|
78
|
+
"--remove-delay": `${prop("removeDelay")}ms`,
|
|
79
|
+
"--duration": `${duration}ms`,
|
|
80
|
+
"--initial-height": `${height}px`,
|
|
81
|
+
"--offset": `${offset}px`,
|
|
82
|
+
"--index": prop("index"),
|
|
83
|
+
"--z-index": computed("zIndex"),
|
|
84
|
+
"--lift-amount": "calc(var(--lift) * var(--gap))",
|
|
85
|
+
"--y": "100%",
|
|
86
|
+
"--x": "0"
|
|
87
|
+
};
|
|
88
|
+
const assign = (overrides) => Object.assign(styles, overrides);
|
|
89
|
+
if (side === "top") {
|
|
90
|
+
assign({
|
|
91
|
+
top: "0",
|
|
92
|
+
"--sign": "-1",
|
|
93
|
+
"--y": "-100%",
|
|
94
|
+
"--lift": "1"
|
|
95
|
+
});
|
|
96
|
+
} else if (side === "bottom") {
|
|
97
|
+
assign({
|
|
98
|
+
bottom: "0",
|
|
99
|
+
"--sign": "1",
|
|
100
|
+
"--y": "100%",
|
|
101
|
+
"--lift": "-1"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (mounted) {
|
|
105
|
+
assign({
|
|
106
|
+
"--y": "0",
|
|
107
|
+
"--opacity": "1"
|
|
108
|
+
});
|
|
109
|
+
if (stacked) {
|
|
110
|
+
assign({
|
|
111
|
+
"--y": "calc(var(--lift) * var(--offset))",
|
|
112
|
+
"--height": "var(--initial-height)"
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!visible) {
|
|
117
|
+
assign({
|
|
118
|
+
"--opacity": "0",
|
|
119
|
+
pointerEvents: "none"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (sibling && overlap) {
|
|
123
|
+
assign({
|
|
124
|
+
"--base-scale": "var(--index) * 0.05 + 1",
|
|
125
|
+
"--y": "calc(var(--lift-amount) * var(--index))",
|
|
126
|
+
"--scale": "calc(-1 * var(--base-scale))",
|
|
127
|
+
"--height": "var(--first-height)"
|
|
128
|
+
});
|
|
129
|
+
if (!visible) {
|
|
130
|
+
assign({
|
|
131
|
+
"--y": "calc(var(--sign) * 40%)"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (sibling && stacked && !visible) {
|
|
136
|
+
assign({
|
|
137
|
+
"--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)"
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (frontmost && !visible) {
|
|
141
|
+
assign({
|
|
142
|
+
"--y": "calc(var(--lift) * -100%)"
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return styles;
|
|
146
|
+
}
|
|
147
|
+
function getGhostBeforeStyle(service, visible) {
|
|
148
|
+
const { computed } = service;
|
|
149
|
+
const styles = {
|
|
150
|
+
position: "absolute",
|
|
151
|
+
inset: "0",
|
|
152
|
+
scale: "1 2",
|
|
153
|
+
pointerEvents: visible ? "none" : "auto"
|
|
154
|
+
};
|
|
155
|
+
const assign = (overrides) => Object.assign(styles, overrides);
|
|
156
|
+
if (computed("frontmost") && !visible) {
|
|
157
|
+
assign({
|
|
158
|
+
height: "calc(var(--initial-height) + 80%)"
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return styles;
|
|
162
|
+
}
|
|
163
|
+
function getGhostAfterStyle() {
|
|
164
|
+
return {
|
|
165
|
+
position: "absolute",
|
|
166
|
+
left: "0",
|
|
167
|
+
height: "calc(var(--gap) + 2px)",
|
|
168
|
+
bottom: "100%",
|
|
169
|
+
width: "100%"
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
defaultTimeouts,
|
|
174
|
+
getGhostAfterStyle,
|
|
175
|
+
getGhostBeforeStyle,
|
|
176
|
+
getGroupPlacementStyle,
|
|
177
|
+
getPlacementStyle,
|
|
178
|
+
getToastDuration
|
|
179
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/toast",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.1",
|
|
4
4
|
"description": "Core logic for the toast widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@zag-js/anatomy": "1.
|
|
30
|
-
"@zag-js/core": "1.
|
|
31
|
-
"@zag-js/
|
|
32
|
-
"@zag-js/
|
|
33
|
-
"@zag-js/utils": "1.
|
|
34
|
-
"@zag-js/types": "1.
|
|
29
|
+
"@zag-js/anatomy": "1.35.1",
|
|
30
|
+
"@zag-js/core": "1.35.1",
|
|
31
|
+
"@zag-js/dismissable": "1.35.1",
|
|
32
|
+
"@zag-js/dom-query": "1.35.1",
|
|
33
|
+
"@zag-js/utils": "1.35.1",
|
|
34
|
+
"@zag-js/types": "1.35.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"clean-package": "2.2.0"
|
|
38
38
|
},
|
|
39
|
-
"clean-package": "
|
|
39
|
+
"clean-package": "./clean-package.config.json",
|
|
40
40
|
"main": "dist/index.js",
|
|
41
41
|
"module": "dist/index.mjs",
|
|
42
42
|
"types": "dist/index.d.ts",
|
|
@@ -51,6 +51,16 @@
|
|
|
51
51
|
"default": "./dist/index.js"
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
|
+
"./anatomy": {
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./dist/toast.anatomy.d.mts",
|
|
57
|
+
"default": "./dist/toast.anatomy.mjs"
|
|
58
|
+
},
|
|
59
|
+
"require": {
|
|
60
|
+
"types": "./dist/toast.anatomy.d.ts",
|
|
61
|
+
"default": "./dist/toast.anatomy.js"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
54
64
|
"./package.json": "./package.json"
|
|
55
65
|
},
|
|
56
66
|
"scripts": {
|