@zag-js/tabs 1.35.3 → 1.36.0
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/tabs.connect.js +10 -5
- package/dist/tabs.connect.mjs +10 -5
- package/dist/tabs.machine.js +27 -2
- package/dist/tabs.machine.mjs +27 -2
- package/dist/tabs.types.d.mts +2 -0
- package/dist/tabs.types.d.ts +2 -0
- package/package.json +6 -6
package/dist/tabs.connect.js
CHANGED
|
@@ -200,13 +200,17 @@ function connect(service, normalize) {
|
|
|
200
200
|
},
|
|
201
201
|
getIndicatorProps() {
|
|
202
202
|
const rect = context.get("indicatorRect");
|
|
203
|
-
const
|
|
203
|
+
const animateIndicator = context.get("animateIndicator");
|
|
204
204
|
return normalize.element({
|
|
205
205
|
id: dom.getIndicatorId(scope),
|
|
206
206
|
...import_tabs.parts.indicator.attrs,
|
|
207
207
|
dir: prop("dir"),
|
|
208
208
|
"data-orientation": prop("orientation"),
|
|
209
|
-
hidden:
|
|
209
|
+
hidden: isRectEmpty(rect),
|
|
210
|
+
onTransitionEnd(event) {
|
|
211
|
+
if ((0, import_dom_query.getEventTarget)(event) !== event.currentTarget) return;
|
|
212
|
+
send({ type: "INDICATOR_TRANSITION_END" });
|
|
213
|
+
},
|
|
210
214
|
style: {
|
|
211
215
|
"--transition-property": "left, right, top, bottom, width, height",
|
|
212
216
|
"--left": (0, import_utils.toPx)(rect?.x),
|
|
@@ -214,9 +218,9 @@ function connect(service, normalize) {
|
|
|
214
218
|
"--width": (0, import_utils.toPx)(rect?.width),
|
|
215
219
|
"--height": (0, import_utils.toPx)(rect?.height),
|
|
216
220
|
position: "absolute",
|
|
217
|
-
willChange: "var(--transition-property)",
|
|
218
|
-
transitionProperty: "var(--transition-property)",
|
|
219
|
-
transitionDuration: "var(--transition-duration, 150ms)",
|
|
221
|
+
willChange: animateIndicator ? "var(--transition-property)" : "auto",
|
|
222
|
+
transitionProperty: animateIndicator ? "var(--transition-property)" : "none",
|
|
223
|
+
transitionDuration: animateIndicator ? "var(--transition-duration, 150ms)" : "0ms",
|
|
220
224
|
transitionTimingFunction: "var(--transition-timing-function)",
|
|
221
225
|
[isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
|
|
222
226
|
}
|
|
@@ -224,6 +228,7 @@ function connect(service, normalize) {
|
|
|
224
228
|
}
|
|
225
229
|
};
|
|
226
230
|
}
|
|
231
|
+
var isRectEmpty = (rect) => rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
|
|
227
232
|
// Annotate the CommonJS export names for ESM import in node:
|
|
228
233
|
0 && (module.exports = {
|
|
229
234
|
connect
|
package/dist/tabs.connect.mjs
CHANGED
|
@@ -174,13 +174,17 @@ function connect(service, normalize) {
|
|
|
174
174
|
},
|
|
175
175
|
getIndicatorProps() {
|
|
176
176
|
const rect = context.get("indicatorRect");
|
|
177
|
-
const
|
|
177
|
+
const animateIndicator = context.get("animateIndicator");
|
|
178
178
|
return normalize.element({
|
|
179
179
|
id: dom.getIndicatorId(scope),
|
|
180
180
|
...parts.indicator.attrs,
|
|
181
181
|
dir: prop("dir"),
|
|
182
182
|
"data-orientation": prop("orientation"),
|
|
183
|
-
hidden:
|
|
183
|
+
hidden: isRectEmpty(rect),
|
|
184
|
+
onTransitionEnd(event) {
|
|
185
|
+
if (getEventTarget(event) !== event.currentTarget) return;
|
|
186
|
+
send({ type: "INDICATOR_TRANSITION_END" });
|
|
187
|
+
},
|
|
184
188
|
style: {
|
|
185
189
|
"--transition-property": "left, right, top, bottom, width, height",
|
|
186
190
|
"--left": toPx(rect?.x),
|
|
@@ -188,9 +192,9 @@ function connect(service, normalize) {
|
|
|
188
192
|
"--width": toPx(rect?.width),
|
|
189
193
|
"--height": toPx(rect?.height),
|
|
190
194
|
position: "absolute",
|
|
191
|
-
willChange: "var(--transition-property)",
|
|
192
|
-
transitionProperty: "var(--transition-property)",
|
|
193
|
-
transitionDuration: "var(--transition-duration, 150ms)",
|
|
195
|
+
willChange: animateIndicator ? "var(--transition-property)" : "auto",
|
|
196
|
+
transitionProperty: animateIndicator ? "var(--transition-property)" : "none",
|
|
197
|
+
transitionDuration: animateIndicator ? "var(--transition-duration, 150ms)" : "0ms",
|
|
194
198
|
transitionTimingFunction: "var(--transition-timing-function)",
|
|
195
199
|
[isHorizontal ? "left" : "top"]: isHorizontal ? "var(--left)" : "var(--top)"
|
|
196
200
|
}
|
|
@@ -198,6 +202,7 @@ function connect(service, normalize) {
|
|
|
198
202
|
}
|
|
199
203
|
};
|
|
200
204
|
}
|
|
205
|
+
var isRectEmpty = (rect) => rect == null || rect.width === 0 && rect.height === 0 && rect.x === 0 && rect.y === 0;
|
|
201
206
|
export {
|
|
202
207
|
connect
|
|
203
208
|
};
|
package/dist/tabs.machine.js
CHANGED
|
@@ -75,12 +75,21 @@ var machine = createMachine({
|
|
|
75
75
|
ssr: bindable(() => ({ defaultValue: true })),
|
|
76
76
|
indicatorRect: bindable(() => ({
|
|
77
77
|
defaultValue: null
|
|
78
|
+
})),
|
|
79
|
+
animateIndicator: bindable(() => ({
|
|
80
|
+
defaultValue: false
|
|
78
81
|
}))
|
|
79
82
|
};
|
|
80
83
|
},
|
|
84
|
+
refs() {
|
|
85
|
+
return {
|
|
86
|
+
indicatorCleanup: null,
|
|
87
|
+
prevValue: null
|
|
88
|
+
};
|
|
89
|
+
},
|
|
81
90
|
watch({ context, prop, track, action }) {
|
|
82
91
|
track([() => context.get("value")], () => {
|
|
83
|
-
action(["syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"]);
|
|
92
|
+
action(["syncIndicatorAnimation", "syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"]);
|
|
84
93
|
});
|
|
85
94
|
track([() => prop("dir"), () => prop("orientation")], () => {
|
|
86
95
|
action(["syncIndicatorRect"]);
|
|
@@ -98,9 +107,12 @@ var machine = createMachine({
|
|
|
98
107
|
},
|
|
99
108
|
SYNC_TAB_INDEX: {
|
|
100
109
|
actions: ["syncTabIndex"]
|
|
110
|
+
},
|
|
111
|
+
INDICATOR_TRANSITION_END: {
|
|
112
|
+
actions: ["clearIndicatorAnimation"]
|
|
101
113
|
}
|
|
102
114
|
},
|
|
103
|
-
entry: ["syncIndicatorRect", "syncTabIndex", "syncSsr"],
|
|
115
|
+
entry: ["syncPrevValue", "syncIndicatorRect", "syncTabIndex", "syncSsr"],
|
|
104
116
|
exit: ["cleanupObserver"],
|
|
105
117
|
states: {
|
|
106
118
|
idle: {
|
|
@@ -266,6 +278,19 @@ var machine = createMachine({
|
|
|
266
278
|
syncSsr({ context }) {
|
|
267
279
|
context.set("ssr", false);
|
|
268
280
|
},
|
|
281
|
+
syncPrevValue({ context, refs }) {
|
|
282
|
+
refs.set("prevValue", context.get("value"));
|
|
283
|
+
},
|
|
284
|
+
syncIndicatorAnimation({ context, refs }) {
|
|
285
|
+
const prevValue = refs.get("prevValue");
|
|
286
|
+
const nextValue = context.get("value");
|
|
287
|
+
const animate = prevValue != null && nextValue != null && prevValue !== nextValue;
|
|
288
|
+
context.set("animateIndicator", animate);
|
|
289
|
+
refs.set("prevValue", nextValue);
|
|
290
|
+
},
|
|
291
|
+
clearIndicatorAnimation({ context }) {
|
|
292
|
+
context.set("animateIndicator", false);
|
|
293
|
+
},
|
|
269
294
|
syncIndicatorRect({ context, refs, scope }) {
|
|
270
295
|
const cleanup = refs.get("indicatorCleanup");
|
|
271
296
|
if (cleanup) cleanup();
|
package/dist/tabs.machine.mjs
CHANGED
|
@@ -41,12 +41,21 @@ var machine = createMachine({
|
|
|
41
41
|
ssr: bindable(() => ({ defaultValue: true })),
|
|
42
42
|
indicatorRect: bindable(() => ({
|
|
43
43
|
defaultValue: null
|
|
44
|
+
})),
|
|
45
|
+
animateIndicator: bindable(() => ({
|
|
46
|
+
defaultValue: false
|
|
44
47
|
}))
|
|
45
48
|
};
|
|
46
49
|
},
|
|
50
|
+
refs() {
|
|
51
|
+
return {
|
|
52
|
+
indicatorCleanup: null,
|
|
53
|
+
prevValue: null
|
|
54
|
+
};
|
|
55
|
+
},
|
|
47
56
|
watch({ context, prop, track, action }) {
|
|
48
57
|
track([() => context.get("value")], () => {
|
|
49
|
-
action(["syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"]);
|
|
58
|
+
action(["syncIndicatorAnimation", "syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"]);
|
|
50
59
|
});
|
|
51
60
|
track([() => prop("dir"), () => prop("orientation")], () => {
|
|
52
61
|
action(["syncIndicatorRect"]);
|
|
@@ -64,9 +73,12 @@ var machine = createMachine({
|
|
|
64
73
|
},
|
|
65
74
|
SYNC_TAB_INDEX: {
|
|
66
75
|
actions: ["syncTabIndex"]
|
|
76
|
+
},
|
|
77
|
+
INDICATOR_TRANSITION_END: {
|
|
78
|
+
actions: ["clearIndicatorAnimation"]
|
|
67
79
|
}
|
|
68
80
|
},
|
|
69
|
-
entry: ["syncIndicatorRect", "syncTabIndex", "syncSsr"],
|
|
81
|
+
entry: ["syncPrevValue", "syncIndicatorRect", "syncTabIndex", "syncSsr"],
|
|
70
82
|
exit: ["cleanupObserver"],
|
|
71
83
|
states: {
|
|
72
84
|
idle: {
|
|
@@ -232,6 +244,19 @@ var machine = createMachine({
|
|
|
232
244
|
syncSsr({ context }) {
|
|
233
245
|
context.set("ssr", false);
|
|
234
246
|
},
|
|
247
|
+
syncPrevValue({ context, refs }) {
|
|
248
|
+
refs.set("prevValue", context.get("value"));
|
|
249
|
+
},
|
|
250
|
+
syncIndicatorAnimation({ context, refs }) {
|
|
251
|
+
const prevValue = refs.get("prevValue");
|
|
252
|
+
const nextValue = context.get("value");
|
|
253
|
+
const animate = prevValue != null && nextValue != null && prevValue !== nextValue;
|
|
254
|
+
context.set("animateIndicator", animate);
|
|
255
|
+
refs.set("prevValue", nextValue);
|
|
256
|
+
},
|
|
257
|
+
clearIndicatorAnimation({ context }) {
|
|
258
|
+
context.set("animateIndicator", false);
|
|
259
|
+
},
|
|
235
260
|
syncIndicatorRect({ context, refs, scope }) {
|
|
236
261
|
const cleanup = refs.get("indicatorCleanup");
|
|
237
262
|
if (cleanup) cleanup();
|
package/dist/tabs.types.d.mts
CHANGED
|
@@ -92,9 +92,11 @@ type TabsSchema = {
|
|
|
92
92
|
value: string | null;
|
|
93
93
|
focusedValue: string | null;
|
|
94
94
|
indicatorRect: Rect | null;
|
|
95
|
+
animateIndicator: boolean;
|
|
95
96
|
};
|
|
96
97
|
refs: {
|
|
97
98
|
indicatorCleanup: VoidFunction | null | undefined;
|
|
99
|
+
prevValue: string | null;
|
|
98
100
|
};
|
|
99
101
|
computed: {
|
|
100
102
|
focused: boolean;
|
package/dist/tabs.types.d.ts
CHANGED
|
@@ -92,9 +92,11 @@ type TabsSchema = {
|
|
|
92
92
|
value: string | null;
|
|
93
93
|
focusedValue: string | null;
|
|
94
94
|
indicatorRect: Rect | null;
|
|
95
|
+
animateIndicator: boolean;
|
|
95
96
|
};
|
|
96
97
|
refs: {
|
|
97
98
|
indicatorCleanup: VoidFunction | null | undefined;
|
|
99
|
+
prevValue: string | null;
|
|
98
100
|
};
|
|
99
101
|
computed: {
|
|
100
102
|
focused: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/tabs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.0",
|
|
4
4
|
"description": "Core logic for the tabs widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@zag-js/anatomy": "1.
|
|
30
|
-
"@zag-js/dom-query": "1.
|
|
31
|
-
"@zag-js/utils": "1.
|
|
32
|
-
"@zag-js/core": "1.
|
|
33
|
-
"@zag-js/types": "1.
|
|
29
|
+
"@zag-js/anatomy": "1.36.0",
|
|
30
|
+
"@zag-js/dom-query": "1.36.0",
|
|
31
|
+
"@zag-js/utils": "1.36.0",
|
|
32
|
+
"@zag-js/core": "1.36.0",
|
|
33
|
+
"@zag-js/types": "1.36.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"clean-package": "2.2.0"
|