@tamagui/tabs-headless 2.7.7 → 3.0.0-beta.1093.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.
@@ -3,18 +3,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
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;
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
13
  };
14
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);
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
16
  var index_exports = {};
19
17
  module.exports = __toCommonJS(index_exports);
20
- __reExport(index_exports, require("./useTabs.cjs"), module.exports);
18
+ __reExport(index_exports, require("./useTabs.cjs"), module.exports);
@@ -0,0 +1,20 @@
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", { value: true }), mod);
18
+ var index_exports = {};
19
+ module.exports = __toCommonJS(index_exports);
20
+ __reExport(index_exports, require("./useTabs.native.js"), module.exports);
@@ -5,19 +5,18 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
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;
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
15
  };
16
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);
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
18
  var index_exports = {};
21
19
  module.exports = __toCommonJS(index_exports);
22
20
  __reExport(index_exports, require("./useTabs.native.js"), module.exports);
21
+
23
22
  //# sourceMappingURL=index.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.native.js","names":[],"sources":["cjs/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":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,cAAc,QAAQ,KAAK,kBAAkB,YAAY,QAAQ,KAAK,SAAS,GAAG,gBAAgB,YAAY,cAAc,KAAK,SAAS;AAC9I,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,gBAAgB,CAAC;AACrB,OAAO,UAAU,aAAa,aAAa;AAC3C,WAAW,eAAe,QAAQ,qBAAW,GAAG,OAAO,OAAO"}
@@ -5,301 +5,134 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
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;
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
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
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var useTabs_exports = {};
35
28
  __export(useTabs_exports, {
36
- TabsProvider: () => TabsProvider,
37
- useTab: () => useTab,
38
- useTabContent: () => useTabContent,
39
- useTabs: () => useTabs,
40
- useTabsContext: () => useTabsContext
29
+ makeContentId: () => makeContentId,
30
+ makeTriggerId: () => makeTriggerId,
31
+ useTab: () => useTab,
32
+ useTabContent: () => useTabContent,
33
+ useTabs: () => useTabs,
34
+ useTabsList: () => useTabsList
41
35
  });
42
36
  module.exports = __toCommonJS(useTabs_exports);
43
- var import_helpers = require("@tamagui/helpers");
37
+ var import_constants = require("@tamagui/constants");
44
38
  var import_use_controllable_state = require("@tamagui/use-controllable-state");
45
39
  var import_use_direction = require("@tamagui/use-direction");
46
40
  var React = __toESM(require("react"), 1);
47
- var import_react = require("react");
41
+ function makeTriggerId(baseId, value) {
42
+ return `${baseId}-trigger-${value}`;
43
+ }
44
+ function makeContentId(baseId, value) {
45
+ return `${baseId}-content-${value}`;
46
+ }
48
47
  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
- };
48
+ const { value: valueProp, onValueChange, defaultValue, orientation = "horizontal", dir, activationMode = "automatic" } = props;
49
+ const direction = (0, import_use_direction.useDirection)(dir);
50
+ const baseId = React.useId();
51
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
52
+ prop: valueProp,
53
+ onChange: onValueChange,
54
+ defaultProp: defaultValue ?? ""
55
+ });
56
+ const [triggersCount, setTriggersCount] = React.useState(0);
57
+ const registerTrigger = React.useCallback(() => setTriggersCount((count) => count + 1), []);
58
+ const unregisterTrigger = React.useCallback(() => setTriggersCount((count) => count - 1), []);
59
+ return {
60
+ value,
61
+ setValue,
62
+ baseId,
63
+ direction,
64
+ orientation,
65
+ activationMode,
66
+ triggersCount,
67
+ registerTrigger,
68
+ unregisterTrigger,
69
+ tabsProps: { "data-orientation": orientation }
70
+ };
206
71
  }
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;
72
+ function useTabsList(props) {
73
+ const { orientation = "horizontal", disabled = false } = props;
74
+ return { listProps: {
75
+ role: "tablist",
76
+ "aria-orientation": orientation,
77
+ "aria-disabled": disabled || void 0,
78
+ "data-orientation": orientation,
79
+ "data-disabled": disabled ? "" : void 0
80
+ } };
215
81
  }
216
82
  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
- };
83
+ const { baseId, value, selectedValue, disabled = false, activationMode = "automatic", onChange } = props;
84
+ const isSelected = value === selectedValue;
85
+ const triggerId = makeTriggerId(baseId, value);
86
+ const contentId = makeContentId(baseId, value);
87
+ return {
88
+ isSelected,
89
+ triggerId,
90
+ contentId,
91
+ tabProps: {
92
+ role: "tab",
93
+ id: triggerId,
94
+ "aria-selected": isSelected,
95
+ "aria-controls": contentId,
96
+ "data-state": isSelected ? "active" : "inactive",
97
+ "data-disabled": disabled ? "" : void 0,
98
+ disabled,
99
+ onPress: (event) => {
100
+ const isPrimaryPointer = !import_constants.isWeb || event?.button === 0 && event?.ctrlKey === false;
101
+ if (!disabled && !isSelected && isPrimaryPointer) {
102
+ onChange(value);
103
+ }
104
+ },
105
+ ...import_constants.isWeb && {
106
+ onKeyDown: (event) => {
107
+ if (!disabled && [" ", "Enter"].includes(event.key)) {
108
+ onChange(value);
109
+ event.preventDefault();
110
+ }
111
+ },
112
+ onFocus: () => {
113
+ if (!isSelected && !disabled && activationMode !== "manual") {
114
+ onChange(value);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ };
271
120
  }
272
121
  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
- };
122
+ const { baseId, value, selectedValue, orientation = "horizontal", forceMount } = props;
123
+ const isSelected = value === selectedValue;
124
+ const shouldMount = Boolean(forceMount) || isSelected;
125
+ return {
126
+ isSelected,
127
+ shouldMount,
128
+ contentProps: {
129
+ role: "tabpanel",
130
+ id: makeContentId(baseId, value),
131
+ "aria-labelledby": makeTriggerId(baseId, value),
132
+ "data-state": isSelected ? "active" : "inactive",
133
+ "data-orientation": orientation,
134
+ hidden: !shouldMount,
135
+ tabIndex: 0
136
+ }
137
+ };
299
138
  }
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,149 @@
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var useTabs_exports = {};
30
+ __export(useTabs_exports, {
31
+ makeContentId: () => makeContentId,
32
+ makeTriggerId: () => makeTriggerId,
33
+ useTab: () => useTab,
34
+ useTabContent: () => useTabContent,
35
+ useTabs: () => useTabs,
36
+ useTabsList: () => useTabsList
37
+ });
38
+ module.exports = __toCommonJS(useTabs_exports);
39
+ var import_constants = require("@tamagui/constants");
40
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
41
+ var import_use_direction = require("@tamagui/use-direction");
42
+ var React = __toESM(require("react"), 1);
43
+ function makeTriggerId(baseId, value) {
44
+ return `${baseId}-trigger-${value}`;
45
+ }
46
+ function makeContentId(baseId, value) {
47
+ return `${baseId}-content-${value}`;
48
+ }
49
+ function useTabs() {
50
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
51
+ var { value: valueProp, onValueChange, defaultValue, orientation = "horizontal", dir, activationMode = "automatic" } = props;
52
+ var direction = (0, import_use_direction.useDirection)(dir);
53
+ var baseId = React.useId();
54
+ var [value, setValue] = (0, import_use_controllable_state.useControllableState)({
55
+ prop: valueProp,
56
+ onChange: onValueChange,
57
+ defaultProp: defaultValue !== null && defaultValue !== void 0 ? defaultValue : ""
58
+ });
59
+ var [triggersCount, setTriggersCount] = React.useState(0);
60
+ var registerTrigger = React.useCallback(function() {
61
+ return setTriggersCount(function(count) {
62
+ return count + 1;
63
+ });
64
+ }, []);
65
+ var unregisterTrigger = React.useCallback(function() {
66
+ return setTriggersCount(function(count) {
67
+ return count - 1;
68
+ });
69
+ }, []);
70
+ return {
71
+ value,
72
+ setValue,
73
+ baseId,
74
+ direction,
75
+ orientation,
76
+ activationMode,
77
+ triggersCount,
78
+ registerTrigger,
79
+ unregisterTrigger,
80
+ tabsProps: { "data-orientation": orientation }
81
+ };
82
+ }
83
+ function useTabsList(props) {
84
+ var { orientation = "horizontal", disabled = false } = props;
85
+ return { listProps: {
86
+ role: "tablist",
87
+ "aria-orientation": orientation,
88
+ "aria-disabled": disabled || void 0,
89
+ "data-orientation": orientation,
90
+ "data-disabled": disabled ? "" : void 0
91
+ } };
92
+ }
93
+ function useTab(props) {
94
+ var { baseId, value, selectedValue, disabled = false, activationMode = "automatic", onChange } = props;
95
+ var isSelected = value === selectedValue;
96
+ var triggerId = makeTriggerId(baseId, value);
97
+ var contentId = makeContentId(baseId, value);
98
+ return {
99
+ isSelected,
100
+ triggerId,
101
+ contentId,
102
+ tabProps: {
103
+ role: "tab",
104
+ id: triggerId,
105
+ "aria-selected": isSelected,
106
+ "aria-controls": contentId,
107
+ "data-state": isSelected ? "active" : "inactive",
108
+ "data-disabled": disabled ? "" : void 0,
109
+ disabled,
110
+ onPress: function(event) {
111
+ 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;
112
+ if (!disabled && !isSelected && isPrimaryPointer) {
113
+ onChange(value);
114
+ }
115
+ },
116
+ ...import_constants.isWeb && {
117
+ onKeyDown: function(event) {
118
+ if (!disabled && [" ", "Enter"].includes(event.key)) {
119
+ onChange(value);
120
+ event.preventDefault();
121
+ }
122
+ },
123
+ onFocus: function() {
124
+ if (!isSelected && !disabled && activationMode !== "manual") {
125
+ onChange(value);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ };
131
+ }
132
+ function useTabContent(props) {
133
+ var { baseId, value, selectedValue, orientation = "horizontal", forceMount } = props;
134
+ var isSelected = value === selectedValue;
135
+ var shouldMount = Boolean(forceMount) || isSelected;
136
+ return {
137
+ isSelected,
138
+ shouldMount,
139
+ contentProps: {
140
+ role: "tabpanel",
141
+ id: makeContentId(baseId, value),
142
+ "aria-labelledby": makeTriggerId(baseId, value),
143
+ "data-state": isSelected ? "active" : "inactive",
144
+ "data-orientation": orientation,
145
+ hidden: !shouldMount,
146
+ tabIndex: 0
147
+ }
148
+ };
149
+ }