@tamagui/tabs-headless 2.7.7 → 3.0.0-beta.643.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/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useTabs.cjs +114 -280
- package/dist/cjs/useTabs.native.cjs +150 -0
- package/dist/cjs/useTabs.native.js +124 -292
- package/dist/cjs/useTabs.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/esm/useTabs.mjs +95 -254
- package/dist/esm/useTabs.mjs.map +1 -1
- package/dist/esm/useTabs.native.js +104 -266
- package/dist/esm/useTabs.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/useTabs.mjs +95 -254
- package/dist/jsx/useTabs.mjs.map +1 -1
- package/dist/jsx/useTabs.native.cjs +150 -0
- package/dist/jsx/useTabs.native.js +124 -292
- package/dist/jsx/useTabs.native.js.map +1 -1
- package/package.json +5 -5
- package/src/useTabs.tsx +112 -296
- package/types/useTabs.d.ts +54 -75
- package/types/useTabs.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,314 +8,145 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
14
15
|
};
|
|
15
16
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
23
24
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
32
28
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
30
|
var useTabs_exports = {};
|
|
37
31
|
__export(useTabs_exports, {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
makeContentId: () => makeContentId,
|
|
33
|
+
makeTriggerId: () => makeTriggerId,
|
|
34
|
+
useTab: () => useTab,
|
|
35
|
+
useTabContent: () => useTabContent,
|
|
36
|
+
useTabs: () => useTabs,
|
|
37
|
+
useTabsList: () => useTabsList
|
|
43
38
|
});
|
|
44
39
|
module.exports = __toCommonJS(useTabs_exports);
|
|
45
|
-
var
|
|
40
|
+
var import_constants = require("@tamagui/constants");
|
|
46
41
|
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
47
42
|
var import_use_direction = require("@tamagui/use-direction");
|
|
48
43
|
var React = __toESM(require("react"), 1);
|
|
49
|
-
|
|
44
|
+
function makeTriggerId(baseId, value) {
|
|
45
|
+
return `${baseId}-trigger-${value}`;
|
|
46
|
+
}
|
|
47
|
+
function makeContentId(baseId, value) {
|
|
48
|
+
return `${baseId}-content-${value}`;
|
|
49
|
+
}
|
|
50
50
|
function useTabs() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}, []);
|
|
85
|
-
var focusTab = (0, import_react.useCallback)(function (tabValue) {
|
|
86
|
-
var element = tabRefs.current.get(tabValue);
|
|
87
|
-
element === null || element === void 0 ? void 0 : element.focus();
|
|
88
|
-
}, []);
|
|
89
|
-
var getNextTab = (0, import_react.useCallback)(function (currentValue, direction2) {
|
|
90
|
-
var currentIndex = tabValues.indexOf(currentValue);
|
|
91
|
-
if (currentIndex === -1) return null;
|
|
92
|
-
var nextIndex = currentIndex + direction2;
|
|
93
|
-
if (loop) {
|
|
94
|
-
nextIndex = (nextIndex + tabValues.length) % tabValues.length;
|
|
95
|
-
} else {
|
|
96
|
-
if (nextIndex < 0 || nextIndex >= tabValues.length) return null;
|
|
97
|
-
}
|
|
98
|
-
var _tabValues_nextIndex;
|
|
99
|
-
return (_tabValues_nextIndex = tabValues[nextIndex]) !== null && _tabValues_nextIndex !== void 0 ? _tabValues_nextIndex : null;
|
|
100
|
-
}, [tabValues, loop]);
|
|
101
|
-
var handleKeyDown = (0, import_react.useCallback)(function (tabValue) {
|
|
102
|
-
return function (event) {
|
|
103
|
-
var isHorizontal = orientation === "horizontal";
|
|
104
|
-
var isRtl = direction === "rtl";
|
|
105
|
-
var nextTab = null;
|
|
106
|
-
switch (event.key) {
|
|
107
|
-
case "ArrowRight":
|
|
108
|
-
if (isHorizontal) {
|
|
109
|
-
nextTab = getNextTab(tabValue, isRtl ? -1 : 1);
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
case "ArrowLeft":
|
|
113
|
-
if (isHorizontal) {
|
|
114
|
-
nextTab = getNextTab(tabValue, isRtl ? 1 : -1);
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
case "ArrowDown":
|
|
118
|
-
if (!isHorizontal) {
|
|
119
|
-
nextTab = getNextTab(tabValue, 1);
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case "ArrowUp":
|
|
123
|
-
if (!isHorizontal) {
|
|
124
|
-
nextTab = getNextTab(tabValue, -1);
|
|
125
|
-
}
|
|
126
|
-
break;
|
|
127
|
-
case "Home":
|
|
128
|
-
var _tabValues_;
|
|
129
|
-
nextTab = (_tabValues_ = tabValues[0]) !== null && _tabValues_ !== void 0 ? _tabValues_ : null;
|
|
130
|
-
break;
|
|
131
|
-
case "End":
|
|
132
|
-
var _tabValues_1;
|
|
133
|
-
nextTab = (_tabValues_1 = tabValues[tabValues.length - 1]) !== null && _tabValues_1 !== void 0 ? _tabValues_1 : null;
|
|
134
|
-
break;
|
|
135
|
-
case " ":
|
|
136
|
-
case "Enter":
|
|
137
|
-
if (activationMode === "manual") {
|
|
138
|
-
setValue(tabValue);
|
|
139
|
-
event.preventDefault();
|
|
140
|
-
}
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (nextTab) {
|
|
144
|
-
event.preventDefault();
|
|
145
|
-
focusTab(nextTab);
|
|
146
|
-
if (activationMode === "automatic") {
|
|
147
|
-
setValue(nextTab);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
}, [orientation, direction, getNextTab, tabValues, activationMode, setValue, focusTab]);
|
|
152
|
-
var getTabProps = (0, import_react.useCallback)(function (tabValue, disabled) {
|
|
153
|
-
var isSelected = value === tabValue;
|
|
154
|
-
var triggerId = makeTriggerId(baseId, tabValue);
|
|
155
|
-
var contentId = makeContentId(baseId, tabValue);
|
|
156
|
-
return {
|
|
157
|
-
role: "tab",
|
|
158
|
-
id: triggerId,
|
|
159
|
-
"aria-selected": isSelected,
|
|
160
|
-
"aria-controls": contentId,
|
|
161
|
-
"data-state": isSelected ? "active" : "inactive",
|
|
162
|
-
...(disabled && {
|
|
163
|
-
"data-disabled": ""
|
|
164
|
-
}),
|
|
165
|
-
disabled,
|
|
166
|
-
tabIndex: isSelected ? 0 : -1,
|
|
167
|
-
onKeyDown: disabled ? function () {} : handleKeyDown(tabValue),
|
|
168
|
-
onClick: function (event) {
|
|
169
|
-
if (!disabled && !isSelected) {
|
|
170
|
-
setValue(tabValue);
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
onFocus: function (event) {
|
|
174
|
-
registerTab(tabValue, event.currentTarget);
|
|
175
|
-
if (!disabled && !isSelected && activationMode === "automatic") {
|
|
176
|
-
setValue(tabValue);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
}, [value, baseId, handleKeyDown, setValue, activationMode, registerTab]);
|
|
181
|
-
var getContentProps = (0, import_react.useCallback)(function (tabValue) {
|
|
182
|
-
var isSelected = value === tabValue;
|
|
183
|
-
var triggerId = makeTriggerId(baseId, tabValue);
|
|
184
|
-
var contentId = makeContentId(baseId, tabValue);
|
|
185
|
-
return {
|
|
186
|
-
role: "tabpanel",
|
|
187
|
-
id: contentId,
|
|
188
|
-
"aria-labelledby": triggerId,
|
|
189
|
-
"data-state": isSelected ? "active" : "inactive",
|
|
190
|
-
"data-orientation": orientation,
|
|
191
|
-
hidden: !isSelected,
|
|
192
|
-
tabIndex: 0
|
|
193
|
-
};
|
|
194
|
-
}, [value, baseId, orientation]);
|
|
195
|
-
var contextValue = {
|
|
196
|
-
baseId,
|
|
197
|
-
value,
|
|
198
|
-
setValue,
|
|
199
|
-
orientation,
|
|
200
|
-
direction,
|
|
201
|
-
activationMode,
|
|
202
|
-
loop
|
|
203
|
-
};
|
|
204
|
-
return {
|
|
205
|
-
value,
|
|
206
|
-
setValue,
|
|
207
|
-
direction,
|
|
208
|
-
tabsProps: {
|
|
209
|
-
"data-orientation": orientation,
|
|
210
|
-
dir: direction
|
|
211
|
-
},
|
|
212
|
-
listProps: {
|
|
213
|
-
role: "tablist",
|
|
214
|
-
"aria-orientation": orientation
|
|
215
|
-
},
|
|
216
|
-
getTabProps,
|
|
217
|
-
getContentProps,
|
|
218
|
-
contextValue
|
|
219
|
-
};
|
|
51
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
52
|
+
var { value: valueProp, onValueChange, defaultValue, orientation = "horizontal", dir, activationMode = "automatic" } = props;
|
|
53
|
+
var direction = (0, import_use_direction.useDirection)(dir);
|
|
54
|
+
var baseId = React.useId();
|
|
55
|
+
var [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
56
|
+
prop: valueProp,
|
|
57
|
+
onChange: onValueChange,
|
|
58
|
+
defaultProp: defaultValue !== null && defaultValue !== void 0 ? defaultValue : ""
|
|
59
|
+
});
|
|
60
|
+
var [triggersCount, setTriggersCount] = React.useState(0);
|
|
61
|
+
var registerTrigger = React.useCallback(function() {
|
|
62
|
+
return setTriggersCount(function(count) {
|
|
63
|
+
return count + 1;
|
|
64
|
+
});
|
|
65
|
+
}, []);
|
|
66
|
+
var unregisterTrigger = React.useCallback(function() {
|
|
67
|
+
return setTriggersCount(function(count) {
|
|
68
|
+
return count - 1;
|
|
69
|
+
});
|
|
70
|
+
}, []);
|
|
71
|
+
return {
|
|
72
|
+
value,
|
|
73
|
+
setValue,
|
|
74
|
+
baseId,
|
|
75
|
+
direction,
|
|
76
|
+
orientation,
|
|
77
|
+
activationMode,
|
|
78
|
+
triggersCount,
|
|
79
|
+
registerTrigger,
|
|
80
|
+
unregisterTrigger,
|
|
81
|
+
tabsProps: { "data-orientation": orientation }
|
|
82
|
+
};
|
|
220
83
|
}
|
|
221
|
-
|
|
222
|
-
var
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
84
|
+
function useTabsList(props) {
|
|
85
|
+
var { orientation = "horizontal", disabled = false } = props;
|
|
86
|
+
return { listProps: {
|
|
87
|
+
role: "tablist",
|
|
88
|
+
"aria-orientation": orientation,
|
|
89
|
+
"aria-disabled": disabled || void 0,
|
|
90
|
+
"data-orientation": orientation,
|
|
91
|
+
"data-disabled": disabled ? "" : void 0
|
|
92
|
+
} };
|
|
229
93
|
}
|
|
230
94
|
function useTab(props) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if ([" ", "Enter"].includes(event.key)) {
|
|
269
|
-
setValue(tabValue);
|
|
270
|
-
event.preventDefault();
|
|
271
|
-
}
|
|
272
|
-
}),
|
|
273
|
-
onPress: (0, import_helpers.composeEventHandlers)(onPress, function () {
|
|
274
|
-
if (!disabled && !isSelected) {
|
|
275
|
-
setValue(tabValue);
|
|
276
|
-
}
|
|
277
|
-
}),
|
|
278
|
-
onFocus: (0, import_helpers.composeEventHandlers)(onFocus, function () {
|
|
279
|
-
if (!disabled && !isSelected && activationMode === "automatic") {
|
|
280
|
-
setValue(tabValue);
|
|
281
|
-
}
|
|
282
|
-
})
|
|
283
|
-
}
|
|
284
|
-
};
|
|
95
|
+
var { baseId, value, selectedValue, disabled = false, activationMode = "automatic", onChange } = props;
|
|
96
|
+
var isSelected = value === selectedValue;
|
|
97
|
+
var triggerId = makeTriggerId(baseId, value);
|
|
98
|
+
var contentId = makeContentId(baseId, value);
|
|
99
|
+
return {
|
|
100
|
+
isSelected,
|
|
101
|
+
triggerId,
|
|
102
|
+
contentId,
|
|
103
|
+
tabProps: {
|
|
104
|
+
role: "tab",
|
|
105
|
+
id: triggerId,
|
|
106
|
+
"aria-selected": isSelected,
|
|
107
|
+
"aria-controls": contentId,
|
|
108
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
109
|
+
"data-disabled": disabled ? "" : void 0,
|
|
110
|
+
disabled,
|
|
111
|
+
onPress: function(event) {
|
|
112
|
+
var isPrimaryPointer = !import_constants.isWeb || (event === null || event === void 0 ? void 0 : event.button) === 0 && (event === null || event === void 0 ? void 0 : event.ctrlKey) === false;
|
|
113
|
+
if (!disabled && !isSelected && isPrimaryPointer) {
|
|
114
|
+
onChange(value);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
...import_constants.isWeb && {
|
|
118
|
+
onKeyDown: function(event) {
|
|
119
|
+
if (!disabled && [" ", "Enter"].includes(event.key)) {
|
|
120
|
+
onChange(value);
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
onFocus: function() {
|
|
125
|
+
if (!isSelected && !disabled && activationMode !== "manual") {
|
|
126
|
+
onChange(value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
285
132
|
}
|
|
286
133
|
function useTabContent(props) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
contentProps: {
|
|
304
|
-
role: "tabpanel",
|
|
305
|
-
id: contentId,
|
|
306
|
-
"aria-labelledby": triggerId,
|
|
307
|
-
"data-state": isSelected ? "active" : "inactive",
|
|
308
|
-
"data-orientation": orientation,
|
|
309
|
-
hidden: !isSelected,
|
|
310
|
-
tabIndex: 0
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function makeTriggerId(baseId, value) {
|
|
315
|
-
return `${baseId}-trigger-${value}`;
|
|
316
|
-
}
|
|
317
|
-
function makeContentId(baseId, value) {
|
|
318
|
-
return `${baseId}-content-${value}`;
|
|
134
|
+
var { baseId, value, selectedValue, orientation = "horizontal", forceMount } = props;
|
|
135
|
+
var isSelected = value === selectedValue;
|
|
136
|
+
var shouldMount = Boolean(forceMount) || isSelected;
|
|
137
|
+
return {
|
|
138
|
+
isSelected,
|
|
139
|
+
shouldMount,
|
|
140
|
+
contentProps: {
|
|
141
|
+
role: "tabpanel",
|
|
142
|
+
id: makeContentId(baseId, value),
|
|
143
|
+
"aria-labelledby": makeTriggerId(baseId, value),
|
|
144
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
145
|
+
"data-orientation": orientation,
|
|
146
|
+
hidden: !shouldMount,
|
|
147
|
+
tabIndex: 0
|
|
148
|
+
}
|
|
149
|
+
};
|
|
319
150
|
}
|
|
151
|
+
|
|
320
152
|
//# sourceMappingURL=useTabs.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useTabs.native.js","names":[],"sources":["cjs/useTabs.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useTabs_exports = {};\n__export(useTabs_exports, {\n makeContentId: () => makeContentId,\n makeTriggerId: () => makeTriggerId,\n useTab: () => useTab,\n useTabContent: () => useTabContent,\n useTabs: () => useTabs,\n useTabsList: () => useTabsList\n});\nmodule.exports = __toCommonJS(useTabs_exports);\nvar import_constants = require(\"@tamagui/constants\");\nvar import_use_controllable_state = require(\"@tamagui/use-controllable-state\");\nvar import_use_direction = require(\"@tamagui/use-direction\");\nvar React = __toESM(require(\"react\"), 1);\nfunction makeTriggerId(baseId, value) {\n return `${baseId}-trigger-${value}`;\n}\nfunction makeContentId(baseId, value) {\n return `${baseId}-content-${value}`;\n}\nfunction useTabs() {\n var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};\n var { value: valueProp, onValueChange, defaultValue, orientation = \"horizontal\", dir, activationMode = \"automatic\" } = props;\n var direction = (0, import_use_direction.useDirection)(dir);\n var baseId = React.useId();\n var [value, setValue] = (0, import_use_controllable_state.useControllableState)({\n prop: valueProp,\n onChange: onValueChange,\n defaultProp: defaultValue !== null && defaultValue !== void 0 ? defaultValue : \"\"\n });\n var [triggersCount, setTriggersCount] = React.useState(0);\n var registerTrigger = React.useCallback(function() {\n return setTriggersCount(function(count) {\n return count + 1;\n });\n }, []);\n var unregisterTrigger = React.useCallback(function() {\n return setTriggersCount(function(count) {\n return count - 1;\n });\n }, []);\n return {\n value,\n setValue,\n baseId,\n direction,\n orientation,\n activationMode,\n triggersCount,\n registerTrigger,\n unregisterTrigger,\n tabsProps: {\n \"data-orientation\": orientation\n }\n };\n}\nfunction useTabsList(props) {\n var { orientation = \"horizontal\", disabled = false } = props;\n return {\n listProps: {\n role: \"tablist\",\n \"aria-orientation\": orientation,\n \"aria-disabled\": disabled || void 0,\n \"data-orientation\": orientation,\n \"data-disabled\": disabled ? \"\" : void 0\n }\n };\n}\nfunction useTab(props) {\n var { baseId, value, selectedValue, disabled = false, activationMode = \"automatic\", onChange } = props;\n var isSelected = value === selectedValue;\n var triggerId = makeTriggerId(baseId, value);\n var contentId = makeContentId(baseId, value);\n return {\n isSelected,\n triggerId,\n contentId,\n tabProps: {\n role: \"tab\",\n id: triggerId,\n \"aria-selected\": isSelected,\n \"aria-controls\": contentId,\n \"data-state\": isSelected ? \"active\" : \"inactive\",\n \"data-disabled\": disabled ? \"\" : void 0,\n disabled,\n onPress: function(event) {\n var isPrimaryPointer = !import_constants.isWeb || (event === null || event === void 0 ? void 0 : event.button) === 0 && (event === null || event === void 0 ? void 0 : event.ctrlKey) === false;\n if (!disabled && !isSelected && isPrimaryPointer) {\n onChange(value);\n }\n },\n ...import_constants.isWeb && {\n onKeyDown: function(event) {\n if (!disabled && [\n \" \",\n \"Enter\"\n ].includes(event.key)) {\n onChange(value);\n event.preventDefault();\n }\n },\n onFocus: function() {\n if (!isSelected && !disabled && activationMode !== \"manual\") {\n onChange(value);\n }\n }\n }\n }\n };\n}\nfunction useTabContent(props) {\n var { baseId, value, selectedValue, orientation = \"horizontal\", forceMount } = props;\n var isSelected = value === selectedValue;\n var shouldMount = Boolean(forceMount) || isSelected;\n return {\n isSelected,\n shouldMount,\n contentProps: {\n role: \"tabpanel\",\n id: makeContentId(baseId, value),\n \"aria-labelledby\": makeTriggerId(baseId, value),\n \"data-state\": isSelected ? \"active\" : \"inactive\",\n \"data-orientation\": orientation,\n hidden: !shouldMount,\n tabIndex: 0\n }\n };\n}\n//# sourceMappingURL=useTabs.js.map\n"],"mappings":";;;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ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AAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,YAAY,MAAM,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,aAAa;IAC1L,IAAI,CAAC,YAAY,CAAC,cAAc,kBAAkB;KAChD,SAAS,KAAK;IAChB;GACF;GACA,GAAG,iBAAiB,SAAS;IAC3B,WAAW,SAAS,OAAO;KACzB,IAAI,CAAC,YAAY,CACf,KACA,OACF,EAAE,SAAS,MAAM,GAAG,GAAG;MACrB,SAAS,KAAK;MACd,MAAM,eAAe;KACvB;IACF;IACA,SAAS,WAAW;KAClB,IAAI,CAAC,cAAc,CAAC,YAAY,mBAAmB,UAAU;MAC3D,SAAS,KAAK;KAChB;IACF;GACF;EACF;CACF;AACF;AACA,SAAS,cAAc,OAAO;CAC5B,IAAI,EAAE,QAAQ,OAAO,eAAe,cAAc,cAAc,eAAe;CAC/E,IAAI,aAAa,UAAU;CAC3B,IAAI,cAAc,QAAQ,UAAU,KAAK;CACzC,OAAO;EACL;EACA;EACA,cAAc;GACZ,MAAM;GACN,IAAI,cAAc,QAAQ,KAAK;GAC/B,mBAAmB,cAAc,QAAQ,KAAK;GAC9C,cAAc,aAAa,WAAW;GACtC,oBAAoB;GACpB,QAAQ,CAAC;GACT,UAAU;EACZ;CACF;AACF"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./useTabs.mjs"
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./useTabs.mjs"
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./useTabs.mjs"
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from "./useTabs.mjs"
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./useTabs.native.js"
|
|
2
|
-
//# sourceMappingURL=index.native.js.map
|
|
1
|
+
export * from "./useTabs.native.js"
|