@hanzogui/tabs-headless 7.0.0 → 7.3.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.
@@ -0,0 +1,20 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
+ get: () => from[key],
9
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
+ });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
+ value: true
17
+ }), mod);
18
+ var index_exports = {};
19
+ module.exports = __toCommonJS(index_exports);
20
+ __reExport(index_exports, require("./useTabs.cjs"), module.exports);
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
+ get: () => from[key],
11
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
+ });
13
+ }
14
+ return to;
15
+ };
16
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
18
+ value: true
19
+ }), mod);
20
+ var index_exports = {};
21
+ module.exports = __toCommonJS(index_exports);
22
+ __reExport(index_exports, require("./useTabs.native.js"), module.exports);
23
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__copyProps","to","from","except","desc","key","call","get","enumerable","__reExport","target","mod","secondTarget","__toCommonJS","value","index_exports","module","exports","require"],"sources":["index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, \"default\"), secondTarget && __copyProps(secondTarget, mod, \"default\"));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\nmodule.exports = __toCommonJS(index_exports);\n__reExport(index_exports, require(\"./useTabs\"), module.exports);\n//# sourceMappingURL=index.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;IAClE,KAAK,IAAIG,GAAG,IAAIV,iBAAiB,CAACO,IAAI,CAAC,EACrC,IAAI,CAACL,YAAY,CAACS,IAAI,CAACL,EAAE,EAAEI,GAAG,CAAC,IAAIA,GAAG,KAAKF,MAAM,EAC/Cb,SAAS,CAACW,EAAE,EAAEI,GAAG,EAAE;MAAEE,GAAG,EAAEA,CAAA,KAAML,IAAI,CAACG,GAAG,CAAC;MAAEG,UAAU,EAAE,EAAEJ,IAAI,GAAGX,gBAAgB,CAACS,IAAI,EAAEG,GAAG,CAAC,CAAC,IAAID,IAAI,CAACI;IAAW,CAAC,CAAC;EACxH;EACA,OAAOP,EAAE;AACX,CAAC;AACD,IAAIQ,UAAU,GAAGA,CAACC,MAAM,EAAEC,GAAG,EAAEC,YAAY,MAAMZ,WAAW,CAACU,MAAM,EAAEC,GAAG,EAAE,SAAS,CAAC,EAAEC,YAAY,IAAIZ,WAAW,CAACY,YAAY,EAAED,GAAG,EAAE,SAAS,CAAC,CAAC;AAChJ,IAAIE,YAAY,GAAIF,GAAG,IAAKX,WAAW,CAACV,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE;EAAEwB,KAAK,EAAE;AAAK,CAAC,CAAC,EAAEH,GAAG,CAAC;AAC1F,IAAII,aAAa,GAAG,CAAC,CAAC;AACtBC,MAAM,CAACC,OAAO,GAAGJ,YAAY,CAACE,aAAa,CAAC;AAC5CN,UAAU,CAACM,aAAa,EAAEG,OAAO,CAAC,qBAAW,CAAC,EAAEF,MAAM,CAACC,OAAO,CAAC","ignoreList":[]}
@@ -0,0 +1,305 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
34
+ var useTabs_exports = {};
35
+ __export(useTabs_exports, {
36
+ TabsProvider: () => TabsProvider,
37
+ useTab: () => useTab,
38
+ useTabContent: () => useTabContent,
39
+ useTabs: () => useTabs,
40
+ useTabsContext: () => useTabsContext
41
+ });
42
+ module.exports = __toCommonJS(useTabs_exports);
43
+ var import_helpers = require("@hanzogui/helpers");
44
+ var import_use_controllable_state = require("@hanzogui/use-controllable-state");
45
+ var import_use_direction = require("@hanzogui/use-direction");
46
+ var React = __toESM(require("react"), 1);
47
+ var import_react = require("react");
48
+ function useTabs(props = {}) {
49
+ const {
50
+ value: valueProp,
51
+ onValueChange,
52
+ defaultValue = "",
53
+ orientation = "horizontal",
54
+ dir,
55
+ activationMode = "automatic",
56
+ loop = true
57
+ } = props;
58
+ const direction = (0, import_use_direction.useDirection)(dir);
59
+ const baseId = (0, import_react.useId)();
60
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
61
+ prop: valueProp,
62
+ onChange: onValueChange,
63
+ defaultProp: defaultValue
64
+ });
65
+ const tabRefs = (0, import_react.useRef)(/* @__PURE__ */new Map());
66
+ const [tabValues, setTabValues] = (0, import_react.useState)([]);
67
+ const registerTab = (0, import_react.useCallback)((tabValue, element) => {
68
+ if (element) {
69
+ tabRefs.current.set(tabValue, element);
70
+ setTabValues(prev => prev.includes(tabValue) ? prev : [...prev, tabValue]);
71
+ } else {
72
+ tabRefs.current.delete(tabValue);
73
+ setTabValues(prev => prev.filter(v => v !== tabValue));
74
+ }
75
+ }, []);
76
+ const focusTab = (0, import_react.useCallback)(tabValue => {
77
+ const element = tabRefs.current.get(tabValue);
78
+ element?.focus();
79
+ }, []);
80
+ const getNextTab = (0, import_react.useCallback)((currentValue, direction2) => {
81
+ const currentIndex = tabValues.indexOf(currentValue);
82
+ if (currentIndex === -1) return null;
83
+ let nextIndex = currentIndex + direction2;
84
+ if (loop) {
85
+ nextIndex = (nextIndex + tabValues.length) % tabValues.length;
86
+ } else {
87
+ if (nextIndex < 0 || nextIndex >= tabValues.length) return null;
88
+ }
89
+ return tabValues[nextIndex] ?? null;
90
+ }, [tabValues, loop]);
91
+ const handleKeyDown = (0, import_react.useCallback)(tabValue => event => {
92
+ const isHorizontal = orientation === "horizontal";
93
+ const isRtl = direction === "rtl";
94
+ let nextTab = null;
95
+ switch (event.key) {
96
+ case "ArrowRight":
97
+ if (isHorizontal) {
98
+ nextTab = getNextTab(tabValue, isRtl ? -1 : 1);
99
+ }
100
+ break;
101
+ case "ArrowLeft":
102
+ if (isHorizontal) {
103
+ nextTab = getNextTab(tabValue, isRtl ? 1 : -1);
104
+ }
105
+ break;
106
+ case "ArrowDown":
107
+ if (!isHorizontal) {
108
+ nextTab = getNextTab(tabValue, 1);
109
+ }
110
+ break;
111
+ case "ArrowUp":
112
+ if (!isHorizontal) {
113
+ nextTab = getNextTab(tabValue, -1);
114
+ }
115
+ break;
116
+ case "Home":
117
+ nextTab = tabValues[0] ?? null;
118
+ break;
119
+ case "End":
120
+ nextTab = tabValues[tabValues.length - 1] ?? null;
121
+ break;
122
+ case " ":
123
+ case "Enter":
124
+ if (activationMode === "manual") {
125
+ setValue(tabValue);
126
+ event.preventDefault();
127
+ }
128
+ return;
129
+ }
130
+ if (nextTab) {
131
+ event.preventDefault();
132
+ focusTab(nextTab);
133
+ if (activationMode === "automatic") {
134
+ setValue(nextTab);
135
+ }
136
+ }
137
+ }, [orientation, direction, getNextTab, tabValues, activationMode, setValue, focusTab]);
138
+ const getTabProps = (0, import_react.useCallback)((tabValue, disabled) => {
139
+ const isSelected = value === tabValue;
140
+ const triggerId = makeTriggerId(baseId, tabValue);
141
+ const contentId = makeContentId(baseId, tabValue);
142
+ return {
143
+ role: "tab",
144
+ id: triggerId,
145
+ "aria-selected": isSelected,
146
+ "aria-controls": contentId,
147
+ "data-state": isSelected ? "active" : "inactive",
148
+ ...(disabled && {
149
+ "data-disabled": ""
150
+ }),
151
+ disabled,
152
+ tabIndex: isSelected ? 0 : -1,
153
+ onKeyDown: disabled ? () => {} : handleKeyDown(tabValue),
154
+ onClick: event => {
155
+ if (!disabled && !isSelected) {
156
+ setValue(tabValue);
157
+ }
158
+ },
159
+ onFocus: event => {
160
+ registerTab(tabValue, event.currentTarget);
161
+ if (!disabled && !isSelected && activationMode === "automatic") {
162
+ setValue(tabValue);
163
+ }
164
+ }
165
+ };
166
+ }, [value, baseId, handleKeyDown, setValue, activationMode, registerTab]);
167
+ const getContentProps = (0, import_react.useCallback)(tabValue => {
168
+ const isSelected = value === tabValue;
169
+ const triggerId = makeTriggerId(baseId, tabValue);
170
+ const contentId = makeContentId(baseId, tabValue);
171
+ return {
172
+ role: "tabpanel",
173
+ id: contentId,
174
+ "aria-labelledby": triggerId,
175
+ "data-state": isSelected ? "active" : "inactive",
176
+ "data-orientation": orientation,
177
+ hidden: !isSelected,
178
+ tabIndex: 0
179
+ };
180
+ }, [value, baseId, orientation]);
181
+ const contextValue = {
182
+ baseId,
183
+ value,
184
+ setValue,
185
+ orientation,
186
+ direction,
187
+ activationMode,
188
+ loop
189
+ };
190
+ return {
191
+ value,
192
+ setValue,
193
+ direction,
194
+ tabsProps: {
195
+ "data-orientation": orientation,
196
+ dir: direction
197
+ },
198
+ listProps: {
199
+ role: "tablist",
200
+ "aria-orientation": orientation
201
+ },
202
+ getTabProps,
203
+ getContentProps,
204
+ contextValue
205
+ };
206
+ }
207
+ const TabsContext = React.createContext(null);
208
+ const TabsProvider = TabsContext.Provider;
209
+ function useTabsContext() {
210
+ const context = React.useContext(TabsContext);
211
+ if (!context) {
212
+ throw new Error("useTabsContext must be used within a TabsProvider");
213
+ }
214
+ return context;
215
+ }
216
+ function useTab(props) {
217
+ const {
218
+ value: tabValue,
219
+ disabled,
220
+ onPress,
221
+ onKeyDown,
222
+ onFocus
223
+ } = props;
224
+ const context = useTabsContext();
225
+ const {
226
+ value,
227
+ setValue,
228
+ baseId,
229
+ activationMode,
230
+ orientation,
231
+ direction,
232
+ loop
233
+ } = context;
234
+ const isSelected = value === tabValue;
235
+ const triggerId = makeTriggerId(baseId, tabValue);
236
+ const contentId = makeContentId(baseId, tabValue);
237
+ const ref = (0, import_react.useRef)(null);
238
+ return {
239
+ isSelected,
240
+ tabProps: {
241
+ ref,
242
+ role: "tab",
243
+ id: triggerId,
244
+ "aria-selected": isSelected,
245
+ "aria-controls": contentId,
246
+ "data-state": isSelected ? "active" : "inactive",
247
+ ...(disabled && {
248
+ "data-disabled": ""
249
+ }),
250
+ disabled,
251
+ tabIndex: isSelected ? 0 : -1,
252
+ onKeyDown: (0, import_helpers.composeEventHandlers)(onKeyDown, event => {
253
+ if (disabled) return;
254
+ if ([" ", "Enter"].includes(event.key)) {
255
+ setValue(tabValue);
256
+ event.preventDefault();
257
+ }
258
+ }),
259
+ onPress: (0, import_helpers.composeEventHandlers)(onPress, () => {
260
+ if (!disabled && !isSelected) {
261
+ setValue(tabValue);
262
+ }
263
+ }),
264
+ onFocus: (0, import_helpers.composeEventHandlers)(onFocus, () => {
265
+ if (!disabled && !isSelected && activationMode === "automatic") {
266
+ setValue(tabValue);
267
+ }
268
+ })
269
+ }
270
+ };
271
+ }
272
+ function useTabContent(props) {
273
+ const {
274
+ value: tabValue,
275
+ forceMount
276
+ } = props;
277
+ const context = useTabsContext();
278
+ const {
279
+ value,
280
+ baseId,
281
+ orientation
282
+ } = context;
283
+ const isSelected = value === tabValue;
284
+ const triggerId = makeTriggerId(baseId, tabValue);
285
+ const contentId = makeContentId(baseId, tabValue);
286
+ return {
287
+ isSelected,
288
+ shouldMount: forceMount || isSelected,
289
+ contentProps: {
290
+ role: "tabpanel",
291
+ id: contentId,
292
+ "aria-labelledby": triggerId,
293
+ "data-state": isSelected ? "active" : "inactive",
294
+ "data-orientation": orientation,
295
+ hidden: !isSelected,
296
+ tabIndex: 0
297
+ }
298
+ };
299
+ }
300
+ function makeTriggerId(baseId, value) {
301
+ return `${baseId}-trigger-${value}`;
302
+ }
303
+ function makeContentId(baseId, value) {
304
+ return `${baseId}-content-${value}`;
305
+ }
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
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
32
+ }) : target, mod));
33
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
+ value: true
35
+ }), mod);
36
+ var useTabs_exports = {};
37
+ __export(useTabs_exports, {
38
+ TabsProvider: () => TabsProvider,
39
+ useTab: () => useTab,
40
+ useTabContent: () => useTabContent,
41
+ useTabs: () => useTabs,
42
+ useTabsContext: () => useTabsContext
43
+ });
44
+ module.exports = __toCommonJS(useTabs_exports);
45
+ var import_helpers = require("@hanzogui/helpers");
46
+ var import_use_controllable_state = require("@hanzogui/use-controllable-state");
47
+ var import_use_direction = require("@hanzogui/use-direction");
48
+ var React = __toESM(require("react"), 1);
49
+ var import_react = require("react");
50
+ function useTabs() {
51
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
52
+ var {
53
+ value: valueProp,
54
+ onValueChange,
55
+ defaultValue = "",
56
+ orientation = "horizontal",
57
+ dir,
58
+ activationMode = "automatic",
59
+ loop = true
60
+ } = props;
61
+ var direction = (0, import_use_direction.useDirection)(dir);
62
+ var baseId = (0, import_react.useId)();
63
+ var [value, setValue] = (0, import_use_controllable_state.useControllableState)({
64
+ prop: valueProp,
65
+ onChange: onValueChange,
66
+ defaultProp: defaultValue
67
+ });
68
+ var tabRefs = (0, import_react.useRef)(/* @__PURE__ */new Map());
69
+ var [tabValues, setTabValues] = (0, import_react.useState)([]);
70
+ var registerTab = (0, import_react.useCallback)(function (tabValue, element) {
71
+ if (element) {
72
+ tabRefs.current.set(tabValue, element);
73
+ setTabValues(function (prev) {
74
+ return prev.includes(tabValue) ? prev : [...prev, tabValue];
75
+ });
76
+ } else {
77
+ tabRefs.current.delete(tabValue);
78
+ setTabValues(function (prev) {
79
+ return prev.filter(function (v) {
80
+ return v !== tabValue;
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
+ };
220
+ }
221
+ var TabsContext = /* @__PURE__ */React.createContext(null);
222
+ var TabsProvider = TabsContext.Provider;
223
+ function useTabsContext() {
224
+ var context = React.useContext(TabsContext);
225
+ if (!context) {
226
+ throw new Error("useTabsContext must be used within a TabsProvider");
227
+ }
228
+ return context;
229
+ }
230
+ function useTab(props) {
231
+ var {
232
+ value: tabValue,
233
+ disabled,
234
+ onPress,
235
+ onKeyDown,
236
+ onFocus
237
+ } = props;
238
+ var context = useTabsContext();
239
+ var {
240
+ value,
241
+ setValue,
242
+ baseId,
243
+ activationMode,
244
+ orientation,
245
+ direction,
246
+ loop
247
+ } = context;
248
+ var isSelected = value === tabValue;
249
+ var triggerId = makeTriggerId(baseId, tabValue);
250
+ var contentId = makeContentId(baseId, tabValue);
251
+ var ref = (0, import_react.useRef)(null);
252
+ return {
253
+ isSelected,
254
+ tabProps: {
255
+ ref,
256
+ role: "tab",
257
+ id: triggerId,
258
+ "aria-selected": isSelected,
259
+ "aria-controls": contentId,
260
+ "data-state": isSelected ? "active" : "inactive",
261
+ ...(disabled && {
262
+ "data-disabled": ""
263
+ }),
264
+ disabled,
265
+ tabIndex: isSelected ? 0 : -1,
266
+ onKeyDown: (0, import_helpers.composeEventHandlers)(onKeyDown, function (event) {
267
+ if (disabled) return;
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
+ };
285
+ }
286
+ function useTabContent(props) {
287
+ var {
288
+ value: tabValue,
289
+ forceMount
290
+ } = props;
291
+ var context = useTabsContext();
292
+ var {
293
+ value,
294
+ baseId,
295
+ orientation
296
+ } = context;
297
+ var isSelected = value === tabValue;
298
+ var triggerId = makeTriggerId(baseId, tabValue);
299
+ var contentId = makeContentId(baseId, tabValue);
300
+ return {
301
+ isSelected,
302
+ shouldMount: forceMount || isSelected,
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}`;
319
+ }
320
+ //# sourceMappingURL=useTabs.native.js.map