@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.
@@ -1,20 +1,19 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  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;
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
9
+ get: () => from[key],
10
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
11
+ });
12
+ }
13
+ return to;
13
14
  };
14
15
  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);
16
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
17
  var index_exports = {};
19
18
  module.exports = __toCommonJS(index_exports);
20
- __reExport(index_exports, require("./useTabs.cjs"), module.exports);
19
+ __reExport(index_exports, require("./useTabs.cjs"), module.exports);
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
+ get: () => from[key],
12
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
+ });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ module.exports = __toCommonJS(index_exports);
21
+ __reExport(index_exports, require("./useTabs.native.js"), module.exports);
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
 
3
+
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  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;
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
+ get: () => from[key],
12
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
+ });
14
+ }
15
+ return to;
15
16
  };
16
17
  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);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
19
  var index_exports = {};
21
20
  module.exports = __toCommonJS(index_exports);
22
21
  __reExport(index_exports, require("./useTabs.native.js"), module.exports);
22
+
23
23
  //# 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"}
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,301 +6,134 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  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;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
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
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var useTabs_exports = {};
35
29
  __export(useTabs_exports, {
36
- TabsProvider: () => TabsProvider,
37
- useTab: () => useTab,
38
- useTabContent: () => useTabContent,
39
- useTabs: () => useTabs,
40
- useTabsContext: () => useTabsContext
30
+ makeContentId: () => makeContentId,
31
+ makeTriggerId: () => makeTriggerId,
32
+ useTab: () => useTab,
33
+ useTabContent: () => useTabContent,
34
+ useTabs: () => useTabs,
35
+ useTabsList: () => useTabsList
41
36
  });
42
37
  module.exports = __toCommonJS(useTabs_exports);
43
- var import_helpers = require("@tamagui/helpers");
38
+ var import_constants = require("@tamagui/constants");
44
39
  var import_use_controllable_state = require("@tamagui/use-controllable-state");
45
40
  var import_use_direction = require("@tamagui/use-direction");
46
41
  var React = __toESM(require("react"), 1);
47
- var import_react = require("react");
42
+ function makeTriggerId(baseId, value) {
43
+ return `${baseId}-trigger-${value}`;
44
+ }
45
+ function makeContentId(baseId, value) {
46
+ return `${baseId}-content-${value}`;
47
+ }
48
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
- };
49
+ const { value: valueProp, onValueChange, defaultValue, orientation = "horizontal", dir, activationMode = "automatic" } = props;
50
+ const direction = (0, import_use_direction.useDirection)(dir);
51
+ const baseId = React.useId();
52
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
53
+ prop: valueProp,
54
+ onChange: onValueChange,
55
+ defaultProp: defaultValue ?? ""
56
+ });
57
+ const [triggersCount, setTriggersCount] = React.useState(0);
58
+ const registerTrigger = React.useCallback(() => setTriggersCount((count) => count + 1), []);
59
+ const unregisterTrigger = React.useCallback(() => setTriggersCount((count) => count - 1), []);
60
+ return {
61
+ value,
62
+ setValue,
63
+ baseId,
64
+ direction,
65
+ orientation,
66
+ activationMode,
67
+ triggersCount,
68
+ registerTrigger,
69
+ unregisterTrigger,
70
+ tabsProps: { "data-orientation": orientation }
71
+ };
206
72
  }
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;
73
+ function useTabsList(props) {
74
+ const { orientation = "horizontal", disabled = false } = props;
75
+ return { listProps: {
76
+ role: "tablist",
77
+ "aria-orientation": orientation,
78
+ "aria-disabled": disabled || void 0,
79
+ "data-orientation": orientation,
80
+ "data-disabled": disabled ? "" : void 0
81
+ } };
215
82
  }
216
83
  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
- };
84
+ const { baseId, value, selectedValue, disabled = false, activationMode = "automatic", onChange } = props;
85
+ const isSelected = value === selectedValue;
86
+ const triggerId = makeTriggerId(baseId, value);
87
+ const contentId = makeContentId(baseId, value);
88
+ return {
89
+ isSelected,
90
+ triggerId,
91
+ contentId,
92
+ tabProps: {
93
+ role: "tab",
94
+ id: triggerId,
95
+ "aria-selected": isSelected,
96
+ "aria-controls": contentId,
97
+ "data-state": isSelected ? "active" : "inactive",
98
+ "data-disabled": disabled ? "" : void 0,
99
+ disabled,
100
+ onPress: (event) => {
101
+ const isPrimaryPointer = !import_constants.isWeb || event?.button === 0 && event?.ctrlKey === false;
102
+ if (!disabled && !isSelected && isPrimaryPointer) {
103
+ onChange(value);
104
+ }
105
+ },
106
+ ...import_constants.isWeb && {
107
+ onKeyDown: (event) => {
108
+ if (!disabled && [" ", "Enter"].includes(event.key)) {
109
+ onChange(value);
110
+ event.preventDefault();
111
+ }
112
+ },
113
+ onFocus: () => {
114
+ if (!isSelected && !disabled && activationMode !== "manual") {
115
+ onChange(value);
116
+ }
117
+ }
118
+ }
119
+ }
120
+ };
271
121
  }
272
122
  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
- };
123
+ const { baseId, value, selectedValue, orientation = "horizontal", forceMount } = props;
124
+ const isSelected = value === selectedValue;
125
+ const shouldMount = Boolean(forceMount) || isSelected;
126
+ return {
127
+ isSelected,
128
+ shouldMount,
129
+ contentProps: {
130
+ role: "tabpanel",
131
+ id: makeContentId(baseId, value),
132
+ "aria-labelledby": makeTriggerId(baseId, value),
133
+ "data-state": isSelected ? "active" : "inactive",
134
+ "data-orientation": orientation,
135
+ hidden: !shouldMount,
136
+ tabIndex: 0
137
+ }
138
+ };
299
139
  }
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,150 @@
1
+ "use strict";
2
+
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
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;
24
+ };
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
28
+ }) : target, mod));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var useTabs_exports = {};
31
+ __export(useTabs_exports, {
32
+ makeContentId: () => makeContentId,
33
+ makeTriggerId: () => makeTriggerId,
34
+ useTab: () => useTab,
35
+ useTabContent: () => useTabContent,
36
+ useTabs: () => useTabs,
37
+ useTabsList: () => useTabsList
38
+ });
39
+ module.exports = __toCommonJS(useTabs_exports);
40
+ var import_constants = require("@tamagui/constants");
41
+ var import_use_controllable_state = require("@tamagui/use-controllable-state");
42
+ var import_use_direction = require("@tamagui/use-direction");
43
+ var React = __toESM(require("react"), 1);
44
+ function makeTriggerId(baseId, value) {
45
+ return `${baseId}-trigger-${value}`;
46
+ }
47
+ function makeContentId(baseId, value) {
48
+ return `${baseId}-content-${value}`;
49
+ }
50
+ function useTabs() {
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
+ };
83
+ }
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
+ } };
93
+ }
94
+ function useTab(props) {
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
+ };
132
+ }
133
+ function useTabContent(props) {
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
+ };
150
+ }