@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
package/dist/cjs/index.cjs
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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);
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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,"
|
|
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"}
|
package/dist/cjs/useTabs.cjs
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
+
}
|