@zag-js/tabs 1.34.0 → 1.35.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/index.d.mts +8 -203
- package/dist/index.d.ts +8 -203
- package/dist/index.js +35 -512
- package/dist/index.mjs +9 -505
- package/dist/tabs.anatomy.d.mts +6 -0
- package/dist/tabs.anatomy.d.ts +6 -0
- package/dist/tabs.anatomy.js +34 -0
- package/dist/tabs.anatomy.mjs +8 -0
- package/dist/tabs.connect.d.mts +7 -0
- package/dist/tabs.connect.d.ts +7 -0
- package/dist/tabs.connect.js +230 -0
- package/dist/tabs.connect.mjs +203 -0
- package/dist/tabs.dom.d.mts +36 -0
- package/dist/tabs.dom.d.ts +36 -0
- package/dist/tabs.dom.js +89 -0
- package/dist/tabs.dom.mjs +49 -0
- package/dist/tabs.machine.d.mts +7 -0
- package/dist/tabs.machine.d.ts +7 -0
- package/dist/tabs.machine.js +299 -0
- package/dist/tabs.machine.mjs +264 -0
- package/dist/tabs.props.d.mts +12 -0
- package/dist/tabs.props.d.ts +12 -0
- package/dist/tabs.props.js +63 -0
- package/dist/tabs.props.mjs +33 -0
- package/dist/tabs.types.d.mts +188 -0
- package/dist/tabs.types.d.ts +188 -0
- package/dist/tabs.types.js +18 -0
- package/dist/tabs.types.mjs +0 -0
- package/package.json +17 -7
|
@@ -0,0 +1,299 @@
|
|
|
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/tabs.machine.ts
|
|
31
|
+
var tabs_machine_exports = {};
|
|
32
|
+
__export(tabs_machine_exports, {
|
|
33
|
+
machine: () => machine
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(tabs_machine_exports);
|
|
36
|
+
var import_core = require("@zag-js/core");
|
|
37
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
38
|
+
var import_utils = require("@zag-js/utils");
|
|
39
|
+
var dom = __toESM(require("./tabs.dom.cjs"));
|
|
40
|
+
var { createMachine } = (0, import_core.setup)();
|
|
41
|
+
var machine = createMachine({
|
|
42
|
+
props({ props }) {
|
|
43
|
+
return {
|
|
44
|
+
dir: "ltr",
|
|
45
|
+
orientation: "horizontal",
|
|
46
|
+
activationMode: "automatic",
|
|
47
|
+
loopFocus: true,
|
|
48
|
+
composite: true,
|
|
49
|
+
navigate(details) {
|
|
50
|
+
(0, import_dom_query.clickIfLink)(details.node);
|
|
51
|
+
},
|
|
52
|
+
defaultValue: null,
|
|
53
|
+
...props
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
initialState() {
|
|
57
|
+
return "idle";
|
|
58
|
+
},
|
|
59
|
+
context({ prop, bindable }) {
|
|
60
|
+
return {
|
|
61
|
+
value: bindable(() => ({
|
|
62
|
+
defaultValue: prop("defaultValue"),
|
|
63
|
+
value: prop("value"),
|
|
64
|
+
onChange(value) {
|
|
65
|
+
prop("onValueChange")?.({ value });
|
|
66
|
+
}
|
|
67
|
+
})),
|
|
68
|
+
focusedValue: bindable(() => ({
|
|
69
|
+
defaultValue: prop("value") || prop("defaultValue"),
|
|
70
|
+
sync: true,
|
|
71
|
+
onChange(value) {
|
|
72
|
+
prop("onFocusChange")?.({ focusedValue: value });
|
|
73
|
+
}
|
|
74
|
+
})),
|
|
75
|
+
ssr: bindable(() => ({ defaultValue: true })),
|
|
76
|
+
indicatorRect: bindable(() => ({
|
|
77
|
+
defaultValue: null
|
|
78
|
+
}))
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
watch({ context, prop, track, action }) {
|
|
82
|
+
track([() => context.get("value")], () => {
|
|
83
|
+
action(["syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"]);
|
|
84
|
+
});
|
|
85
|
+
track([() => prop("dir"), () => prop("orientation")], () => {
|
|
86
|
+
action(["syncIndicatorRect"]);
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
on: {
|
|
90
|
+
SET_VALUE: {
|
|
91
|
+
actions: ["setValue"]
|
|
92
|
+
},
|
|
93
|
+
CLEAR_VALUE: {
|
|
94
|
+
actions: ["clearValue"]
|
|
95
|
+
},
|
|
96
|
+
SET_INDICATOR_RECT: {
|
|
97
|
+
actions: ["setIndicatorRect"]
|
|
98
|
+
},
|
|
99
|
+
SYNC_TAB_INDEX: {
|
|
100
|
+
actions: ["syncTabIndex"]
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
entry: ["syncIndicatorRect", "syncTabIndex", "syncSsr"],
|
|
104
|
+
exit: ["cleanupObserver"],
|
|
105
|
+
states: {
|
|
106
|
+
idle: {
|
|
107
|
+
on: {
|
|
108
|
+
TAB_FOCUS: {
|
|
109
|
+
target: "focused",
|
|
110
|
+
actions: ["setFocusedValue"]
|
|
111
|
+
},
|
|
112
|
+
TAB_CLICK: {
|
|
113
|
+
target: "focused",
|
|
114
|
+
actions: ["setFocusedValue", "setValue"]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
focused: {
|
|
119
|
+
on: {
|
|
120
|
+
TAB_CLICK: {
|
|
121
|
+
actions: ["setFocusedValue", "setValue"]
|
|
122
|
+
},
|
|
123
|
+
ARROW_PREV: [
|
|
124
|
+
{
|
|
125
|
+
guard: "selectOnFocus",
|
|
126
|
+
actions: ["focusPrevTab", "selectFocusedTab"]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
actions: ["focusPrevTab"]
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
ARROW_NEXT: [
|
|
133
|
+
{
|
|
134
|
+
guard: "selectOnFocus",
|
|
135
|
+
actions: ["focusNextTab", "selectFocusedTab"]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
actions: ["focusNextTab"]
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
HOME: [
|
|
142
|
+
{
|
|
143
|
+
guard: "selectOnFocus",
|
|
144
|
+
actions: ["focusFirstTab", "selectFocusedTab"]
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
actions: ["focusFirstTab"]
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
END: [
|
|
151
|
+
{
|
|
152
|
+
guard: "selectOnFocus",
|
|
153
|
+
actions: ["focusLastTab", "selectFocusedTab"]
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
actions: ["focusLastTab"]
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
TAB_FOCUS: {
|
|
160
|
+
actions: ["setFocusedValue"]
|
|
161
|
+
},
|
|
162
|
+
TAB_BLUR: {
|
|
163
|
+
target: "idle",
|
|
164
|
+
actions: ["clearFocusedValue"]
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
implementations: {
|
|
170
|
+
guards: {
|
|
171
|
+
selectOnFocus: ({ prop }) => prop("activationMode") === "automatic"
|
|
172
|
+
},
|
|
173
|
+
actions: {
|
|
174
|
+
selectFocusedTab({ context, prop }) {
|
|
175
|
+
(0, import_dom_query.raf)(() => {
|
|
176
|
+
const focusedValue = context.get("focusedValue");
|
|
177
|
+
if (!focusedValue) return;
|
|
178
|
+
const nullable = prop("deselectable") && context.get("value") === focusedValue;
|
|
179
|
+
const value = nullable ? null : focusedValue;
|
|
180
|
+
context.set("value", value);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
setFocusedValue({ context, event, flush }) {
|
|
184
|
+
if (event.value == null) return;
|
|
185
|
+
flush(() => {
|
|
186
|
+
context.set("focusedValue", event.value);
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
clearFocusedValue({ context }) {
|
|
190
|
+
context.set("focusedValue", null);
|
|
191
|
+
},
|
|
192
|
+
setValue({ context, event, prop }) {
|
|
193
|
+
const nullable = prop("deselectable") && context.get("value") === context.get("focusedValue");
|
|
194
|
+
context.set("value", nullable ? null : event.value);
|
|
195
|
+
},
|
|
196
|
+
clearValue({ context }) {
|
|
197
|
+
context.set("value", null);
|
|
198
|
+
},
|
|
199
|
+
focusFirstTab({ scope }) {
|
|
200
|
+
(0, import_dom_query.raf)(() => {
|
|
201
|
+
dom.getFirstTriggerEl(scope)?.focus();
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
focusLastTab({ scope }) {
|
|
205
|
+
(0, import_dom_query.raf)(() => {
|
|
206
|
+
dom.getLastTriggerEl(scope)?.focus();
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
focusNextTab({ context, prop, scope, event }) {
|
|
210
|
+
const focusedValue = event.value ?? context.get("focusedValue");
|
|
211
|
+
if (!focusedValue) return;
|
|
212
|
+
const triggerEl = dom.getNextTriggerEl(scope, {
|
|
213
|
+
value: focusedValue,
|
|
214
|
+
loopFocus: prop("loopFocus")
|
|
215
|
+
});
|
|
216
|
+
(0, import_dom_query.raf)(() => {
|
|
217
|
+
if (prop("composite")) {
|
|
218
|
+
triggerEl?.focus();
|
|
219
|
+
} else if (triggerEl?.dataset.value != null) {
|
|
220
|
+
context.set("focusedValue", triggerEl.dataset.value);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
focusPrevTab({ context, prop, scope, event }) {
|
|
225
|
+
const focusedValue = event.value ?? context.get("focusedValue");
|
|
226
|
+
if (!focusedValue) return;
|
|
227
|
+
const triggerEl = dom.getPrevTriggerEl(scope, {
|
|
228
|
+
value: focusedValue,
|
|
229
|
+
loopFocus: prop("loopFocus")
|
|
230
|
+
});
|
|
231
|
+
(0, import_dom_query.raf)(() => {
|
|
232
|
+
if (prop("composite")) {
|
|
233
|
+
triggerEl?.focus();
|
|
234
|
+
} else if (triggerEl?.dataset.value != null) {
|
|
235
|
+
context.set("focusedValue", triggerEl.dataset.value);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
syncTabIndex({ context, scope }) {
|
|
240
|
+
(0, import_dom_query.raf)(() => {
|
|
241
|
+
const value = context.get("value");
|
|
242
|
+
if (!value) return;
|
|
243
|
+
const contentEl = dom.getContentEl(scope, value);
|
|
244
|
+
if (!contentEl) return;
|
|
245
|
+
const focusables = (0, import_dom_query.getFocusables)(contentEl);
|
|
246
|
+
if (focusables.length > 0) {
|
|
247
|
+
contentEl.removeAttribute("tabindex");
|
|
248
|
+
} else {
|
|
249
|
+
contentEl.setAttribute("tabindex", "0");
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
cleanupObserver({ refs }) {
|
|
254
|
+
const cleanup = refs.get("indicatorCleanup");
|
|
255
|
+
if (cleanup) cleanup();
|
|
256
|
+
},
|
|
257
|
+
setIndicatorRect({ context, event, scope }) {
|
|
258
|
+
const value = event.id ?? context.get("value");
|
|
259
|
+
const indicatorEl = dom.getIndicatorEl(scope);
|
|
260
|
+
if (!indicatorEl) return;
|
|
261
|
+
if (!value) return;
|
|
262
|
+
const triggerEl = dom.getTriggerEl(scope, value);
|
|
263
|
+
if (!triggerEl) return;
|
|
264
|
+
context.set("indicatorRect", dom.getRectByValue(scope, value));
|
|
265
|
+
},
|
|
266
|
+
syncSsr({ context }) {
|
|
267
|
+
context.set("ssr", false);
|
|
268
|
+
},
|
|
269
|
+
syncIndicatorRect({ context, refs, scope }) {
|
|
270
|
+
const cleanup = refs.get("indicatorCleanup");
|
|
271
|
+
if (cleanup) cleanup();
|
|
272
|
+
const indicatorEl = dom.getIndicatorEl(scope);
|
|
273
|
+
if (!indicatorEl) return;
|
|
274
|
+
const exec = () => {
|
|
275
|
+
const triggerEl = dom.getTriggerEl(scope, context.get("value"));
|
|
276
|
+
if (!triggerEl) return;
|
|
277
|
+
const rect = dom.getOffsetRect(triggerEl);
|
|
278
|
+
context.set("indicatorRect", (prev) => (0, import_utils.isEqual)(prev, rect) ? prev : rect);
|
|
279
|
+
};
|
|
280
|
+
exec();
|
|
281
|
+
const triggerEls = dom.getElements(scope);
|
|
282
|
+
const indicatorCleanup = (0, import_utils.callAll)(...triggerEls.map((el) => import_dom_query.resizeObserverBorderBox.observe(el, exec)));
|
|
283
|
+
refs.set("indicatorCleanup", indicatorCleanup);
|
|
284
|
+
},
|
|
285
|
+
navigateIfNeeded({ context, prop, scope }) {
|
|
286
|
+
const value = context.get("value");
|
|
287
|
+
if (!value) return;
|
|
288
|
+
const triggerEl = dom.getTriggerEl(scope, value);
|
|
289
|
+
if ((0, import_dom_query.isAnchorElement)(triggerEl)) {
|
|
290
|
+
prop("navigate")?.({ value, node: triggerEl, href: triggerEl.href });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
297
|
+
0 && (module.exports = {
|
|
298
|
+
machine
|
|
299
|
+
});
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// src/tabs.machine.ts
|
|
2
|
+
import { setup } from "@zag-js/core";
|
|
3
|
+
import { clickIfLink, getFocusables, isAnchorElement, raf, resizeObserverBorderBox } from "@zag-js/dom-query";
|
|
4
|
+
import { callAll, isEqual } from "@zag-js/utils";
|
|
5
|
+
import * as dom from "./tabs.dom.mjs";
|
|
6
|
+
var { createMachine } = setup();
|
|
7
|
+
var machine = createMachine({
|
|
8
|
+
props({ props }) {
|
|
9
|
+
return {
|
|
10
|
+
dir: "ltr",
|
|
11
|
+
orientation: "horizontal",
|
|
12
|
+
activationMode: "automatic",
|
|
13
|
+
loopFocus: true,
|
|
14
|
+
composite: true,
|
|
15
|
+
navigate(details) {
|
|
16
|
+
clickIfLink(details.node);
|
|
17
|
+
},
|
|
18
|
+
defaultValue: null,
|
|
19
|
+
...props
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
initialState() {
|
|
23
|
+
return "idle";
|
|
24
|
+
},
|
|
25
|
+
context({ prop, bindable }) {
|
|
26
|
+
return {
|
|
27
|
+
value: bindable(() => ({
|
|
28
|
+
defaultValue: prop("defaultValue"),
|
|
29
|
+
value: prop("value"),
|
|
30
|
+
onChange(value) {
|
|
31
|
+
prop("onValueChange")?.({ value });
|
|
32
|
+
}
|
|
33
|
+
})),
|
|
34
|
+
focusedValue: bindable(() => ({
|
|
35
|
+
defaultValue: prop("value") || prop("defaultValue"),
|
|
36
|
+
sync: true,
|
|
37
|
+
onChange(value) {
|
|
38
|
+
prop("onFocusChange")?.({ focusedValue: value });
|
|
39
|
+
}
|
|
40
|
+
})),
|
|
41
|
+
ssr: bindable(() => ({ defaultValue: true })),
|
|
42
|
+
indicatorRect: bindable(() => ({
|
|
43
|
+
defaultValue: null
|
|
44
|
+
}))
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
watch({ context, prop, track, action }) {
|
|
48
|
+
track([() => context.get("value")], () => {
|
|
49
|
+
action(["syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"]);
|
|
50
|
+
});
|
|
51
|
+
track([() => prop("dir"), () => prop("orientation")], () => {
|
|
52
|
+
action(["syncIndicatorRect"]);
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
on: {
|
|
56
|
+
SET_VALUE: {
|
|
57
|
+
actions: ["setValue"]
|
|
58
|
+
},
|
|
59
|
+
CLEAR_VALUE: {
|
|
60
|
+
actions: ["clearValue"]
|
|
61
|
+
},
|
|
62
|
+
SET_INDICATOR_RECT: {
|
|
63
|
+
actions: ["setIndicatorRect"]
|
|
64
|
+
},
|
|
65
|
+
SYNC_TAB_INDEX: {
|
|
66
|
+
actions: ["syncTabIndex"]
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
entry: ["syncIndicatorRect", "syncTabIndex", "syncSsr"],
|
|
70
|
+
exit: ["cleanupObserver"],
|
|
71
|
+
states: {
|
|
72
|
+
idle: {
|
|
73
|
+
on: {
|
|
74
|
+
TAB_FOCUS: {
|
|
75
|
+
target: "focused",
|
|
76
|
+
actions: ["setFocusedValue"]
|
|
77
|
+
},
|
|
78
|
+
TAB_CLICK: {
|
|
79
|
+
target: "focused",
|
|
80
|
+
actions: ["setFocusedValue", "setValue"]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
focused: {
|
|
85
|
+
on: {
|
|
86
|
+
TAB_CLICK: {
|
|
87
|
+
actions: ["setFocusedValue", "setValue"]
|
|
88
|
+
},
|
|
89
|
+
ARROW_PREV: [
|
|
90
|
+
{
|
|
91
|
+
guard: "selectOnFocus",
|
|
92
|
+
actions: ["focusPrevTab", "selectFocusedTab"]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
actions: ["focusPrevTab"]
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
ARROW_NEXT: [
|
|
99
|
+
{
|
|
100
|
+
guard: "selectOnFocus",
|
|
101
|
+
actions: ["focusNextTab", "selectFocusedTab"]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
actions: ["focusNextTab"]
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
HOME: [
|
|
108
|
+
{
|
|
109
|
+
guard: "selectOnFocus",
|
|
110
|
+
actions: ["focusFirstTab", "selectFocusedTab"]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
actions: ["focusFirstTab"]
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
END: [
|
|
117
|
+
{
|
|
118
|
+
guard: "selectOnFocus",
|
|
119
|
+
actions: ["focusLastTab", "selectFocusedTab"]
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
actions: ["focusLastTab"]
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
TAB_FOCUS: {
|
|
126
|
+
actions: ["setFocusedValue"]
|
|
127
|
+
},
|
|
128
|
+
TAB_BLUR: {
|
|
129
|
+
target: "idle",
|
|
130
|
+
actions: ["clearFocusedValue"]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
implementations: {
|
|
136
|
+
guards: {
|
|
137
|
+
selectOnFocus: ({ prop }) => prop("activationMode") === "automatic"
|
|
138
|
+
},
|
|
139
|
+
actions: {
|
|
140
|
+
selectFocusedTab({ context, prop }) {
|
|
141
|
+
raf(() => {
|
|
142
|
+
const focusedValue = context.get("focusedValue");
|
|
143
|
+
if (!focusedValue) return;
|
|
144
|
+
const nullable = prop("deselectable") && context.get("value") === focusedValue;
|
|
145
|
+
const value = nullable ? null : focusedValue;
|
|
146
|
+
context.set("value", value);
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
setFocusedValue({ context, event, flush }) {
|
|
150
|
+
if (event.value == null) return;
|
|
151
|
+
flush(() => {
|
|
152
|
+
context.set("focusedValue", event.value);
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
clearFocusedValue({ context }) {
|
|
156
|
+
context.set("focusedValue", null);
|
|
157
|
+
},
|
|
158
|
+
setValue({ context, event, prop }) {
|
|
159
|
+
const nullable = prop("deselectable") && context.get("value") === context.get("focusedValue");
|
|
160
|
+
context.set("value", nullable ? null : event.value);
|
|
161
|
+
},
|
|
162
|
+
clearValue({ context }) {
|
|
163
|
+
context.set("value", null);
|
|
164
|
+
},
|
|
165
|
+
focusFirstTab({ scope }) {
|
|
166
|
+
raf(() => {
|
|
167
|
+
dom.getFirstTriggerEl(scope)?.focus();
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
focusLastTab({ scope }) {
|
|
171
|
+
raf(() => {
|
|
172
|
+
dom.getLastTriggerEl(scope)?.focus();
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
focusNextTab({ context, prop, scope, event }) {
|
|
176
|
+
const focusedValue = event.value ?? context.get("focusedValue");
|
|
177
|
+
if (!focusedValue) return;
|
|
178
|
+
const triggerEl = dom.getNextTriggerEl(scope, {
|
|
179
|
+
value: focusedValue,
|
|
180
|
+
loopFocus: prop("loopFocus")
|
|
181
|
+
});
|
|
182
|
+
raf(() => {
|
|
183
|
+
if (prop("composite")) {
|
|
184
|
+
triggerEl?.focus();
|
|
185
|
+
} else if (triggerEl?.dataset.value != null) {
|
|
186
|
+
context.set("focusedValue", triggerEl.dataset.value);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
focusPrevTab({ context, prop, scope, event }) {
|
|
191
|
+
const focusedValue = event.value ?? context.get("focusedValue");
|
|
192
|
+
if (!focusedValue) return;
|
|
193
|
+
const triggerEl = dom.getPrevTriggerEl(scope, {
|
|
194
|
+
value: focusedValue,
|
|
195
|
+
loopFocus: prop("loopFocus")
|
|
196
|
+
});
|
|
197
|
+
raf(() => {
|
|
198
|
+
if (prop("composite")) {
|
|
199
|
+
triggerEl?.focus();
|
|
200
|
+
} else if (triggerEl?.dataset.value != null) {
|
|
201
|
+
context.set("focusedValue", triggerEl.dataset.value);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
syncTabIndex({ context, scope }) {
|
|
206
|
+
raf(() => {
|
|
207
|
+
const value = context.get("value");
|
|
208
|
+
if (!value) return;
|
|
209
|
+
const contentEl = dom.getContentEl(scope, value);
|
|
210
|
+
if (!contentEl) return;
|
|
211
|
+
const focusables = getFocusables(contentEl);
|
|
212
|
+
if (focusables.length > 0) {
|
|
213
|
+
contentEl.removeAttribute("tabindex");
|
|
214
|
+
} else {
|
|
215
|
+
contentEl.setAttribute("tabindex", "0");
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
cleanupObserver({ refs }) {
|
|
220
|
+
const cleanup = refs.get("indicatorCleanup");
|
|
221
|
+
if (cleanup) cleanup();
|
|
222
|
+
},
|
|
223
|
+
setIndicatorRect({ context, event, scope }) {
|
|
224
|
+
const value = event.id ?? context.get("value");
|
|
225
|
+
const indicatorEl = dom.getIndicatorEl(scope);
|
|
226
|
+
if (!indicatorEl) return;
|
|
227
|
+
if (!value) return;
|
|
228
|
+
const triggerEl = dom.getTriggerEl(scope, value);
|
|
229
|
+
if (!triggerEl) return;
|
|
230
|
+
context.set("indicatorRect", dom.getRectByValue(scope, value));
|
|
231
|
+
},
|
|
232
|
+
syncSsr({ context }) {
|
|
233
|
+
context.set("ssr", false);
|
|
234
|
+
},
|
|
235
|
+
syncIndicatorRect({ context, refs, scope }) {
|
|
236
|
+
const cleanup = refs.get("indicatorCleanup");
|
|
237
|
+
if (cleanup) cleanup();
|
|
238
|
+
const indicatorEl = dom.getIndicatorEl(scope);
|
|
239
|
+
if (!indicatorEl) return;
|
|
240
|
+
const exec = () => {
|
|
241
|
+
const triggerEl = dom.getTriggerEl(scope, context.get("value"));
|
|
242
|
+
if (!triggerEl) return;
|
|
243
|
+
const rect = dom.getOffsetRect(triggerEl);
|
|
244
|
+
context.set("indicatorRect", (prev) => isEqual(prev, rect) ? prev : rect);
|
|
245
|
+
};
|
|
246
|
+
exec();
|
|
247
|
+
const triggerEls = dom.getElements(scope);
|
|
248
|
+
const indicatorCleanup = callAll(...triggerEls.map((el) => resizeObserverBorderBox.observe(el, exec)));
|
|
249
|
+
refs.set("indicatorCleanup", indicatorCleanup);
|
|
250
|
+
},
|
|
251
|
+
navigateIfNeeded({ context, prop, scope }) {
|
|
252
|
+
const value = context.get("value");
|
|
253
|
+
if (!value) return;
|
|
254
|
+
const triggerEl = dom.getTriggerEl(scope, value);
|
|
255
|
+
if (isAnchorElement(triggerEl)) {
|
|
256
|
+
prop("navigate")?.({ value, node: triggerEl, href: triggerEl.href });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
export {
|
|
263
|
+
machine
|
|
264
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TabsProps, ContentProps, TriggerProps } from './tabs.types.mjs';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const props: (keyof TabsProps)[];
|
|
6
|
+
declare const splitProps: <Props extends Partial<TabsProps>>(props: Props) => [Partial<TabsProps>, Omit<Props, keyof TabsProps>];
|
|
7
|
+
declare const triggerProps: (keyof TriggerProps)[];
|
|
8
|
+
declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
|
|
9
|
+
declare const contentProps: "value"[];
|
|
10
|
+
declare const splitContentProps: <Props extends ContentProps>(props: Props) => [ContentProps, Omit<Props, "value">];
|
|
11
|
+
|
|
12
|
+
export { contentProps, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TabsProps, ContentProps, TriggerProps } from './tabs.types.js';
|
|
2
|
+
import '@zag-js/core';
|
|
3
|
+
import '@zag-js/types';
|
|
4
|
+
|
|
5
|
+
declare const props: (keyof TabsProps)[];
|
|
6
|
+
declare const splitProps: <Props extends Partial<TabsProps>>(props: Props) => [Partial<TabsProps>, Omit<Props, keyof TabsProps>];
|
|
7
|
+
declare const triggerProps: (keyof TriggerProps)[];
|
|
8
|
+
declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
|
|
9
|
+
declare const contentProps: "value"[];
|
|
10
|
+
declare const splitContentProps: <Props extends ContentProps>(props: Props) => [ContentProps, Omit<Props, "value">];
|
|
11
|
+
|
|
12
|
+
export { contentProps, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
|
|
@@ -0,0 +1,63 @@
|
|
|
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/tabs.props.ts
|
|
21
|
+
var tabs_props_exports = {};
|
|
22
|
+
__export(tabs_props_exports, {
|
|
23
|
+
contentProps: () => contentProps,
|
|
24
|
+
props: () => props,
|
|
25
|
+
splitContentProps: () => splitContentProps,
|
|
26
|
+
splitProps: () => splitProps,
|
|
27
|
+
splitTriggerProps: () => splitTriggerProps,
|
|
28
|
+
triggerProps: () => triggerProps
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(tabs_props_exports);
|
|
31
|
+
var import_types = require("@zag-js/types");
|
|
32
|
+
var import_utils = require("@zag-js/utils");
|
|
33
|
+
var props = (0, import_types.createProps)()([
|
|
34
|
+
"activationMode",
|
|
35
|
+
"composite",
|
|
36
|
+
"deselectable",
|
|
37
|
+
"dir",
|
|
38
|
+
"getRootNode",
|
|
39
|
+
"id",
|
|
40
|
+
"ids",
|
|
41
|
+
"loopFocus",
|
|
42
|
+
"navigate",
|
|
43
|
+
"onFocusChange",
|
|
44
|
+
"onValueChange",
|
|
45
|
+
"orientation",
|
|
46
|
+
"translations",
|
|
47
|
+
"value",
|
|
48
|
+
"defaultValue"
|
|
49
|
+
]);
|
|
50
|
+
var splitProps = (0, import_utils.createSplitProps)(props);
|
|
51
|
+
var triggerProps = (0, import_types.createProps)()(["disabled", "value"]);
|
|
52
|
+
var splitTriggerProps = (0, import_utils.createSplitProps)(triggerProps);
|
|
53
|
+
var contentProps = (0, import_types.createProps)()(["value"]);
|
|
54
|
+
var splitContentProps = (0, import_utils.createSplitProps)(contentProps);
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
contentProps,
|
|
58
|
+
props,
|
|
59
|
+
splitContentProps,
|
|
60
|
+
splitProps,
|
|
61
|
+
splitTriggerProps,
|
|
62
|
+
triggerProps
|
|
63
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/tabs.props.ts
|
|
2
|
+
import { createProps } from "@zag-js/types";
|
|
3
|
+
import { createSplitProps } from "@zag-js/utils";
|
|
4
|
+
var props = createProps()([
|
|
5
|
+
"activationMode",
|
|
6
|
+
"composite",
|
|
7
|
+
"deselectable",
|
|
8
|
+
"dir",
|
|
9
|
+
"getRootNode",
|
|
10
|
+
"id",
|
|
11
|
+
"ids",
|
|
12
|
+
"loopFocus",
|
|
13
|
+
"navigate",
|
|
14
|
+
"onFocusChange",
|
|
15
|
+
"onValueChange",
|
|
16
|
+
"orientation",
|
|
17
|
+
"translations",
|
|
18
|
+
"value",
|
|
19
|
+
"defaultValue"
|
|
20
|
+
]);
|
|
21
|
+
var splitProps = createSplitProps(props);
|
|
22
|
+
var triggerProps = createProps()(["disabled", "value"]);
|
|
23
|
+
var splitTriggerProps = createSplitProps(triggerProps);
|
|
24
|
+
var contentProps = createProps()(["value"]);
|
|
25
|
+
var splitContentProps = createSplitProps(contentProps);
|
|
26
|
+
export {
|
|
27
|
+
contentProps,
|
|
28
|
+
props,
|
|
29
|
+
splitContentProps,
|
|
30
|
+
splitProps,
|
|
31
|
+
splitTriggerProps,
|
|
32
|
+
triggerProps
|
|
33
|
+
};
|