@tamagui/tabs 1.116.0 → 1.116.2
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/Tabs.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
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, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var Tabs_exports = {};
|
|
24
|
+
__export(Tabs_exports, {
|
|
25
|
+
Tabs: () => Tabs,
|
|
26
|
+
useTabsContext: () => useTabsContext
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(Tabs_exports);
|
|
29
|
+
var import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_get_button_sized = require("@tamagui/get-button-sized"), import_group = require("@tamagui/group"), import_helpers = require("@tamagui/helpers"), import_roving_focus = require("@tamagui/roving-focus"), import_stacks = require("@tamagui/stacks"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_use_direction = require("@tamagui/use-direction"), import_web = require("@tamagui/web"), React = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
const TABS_CONTEXT = "TabsContext", TAB_LIST_NAME = "TabsList", TabsList = React.forwardRef(
|
|
31
|
+
(props, forwardedRef) => {
|
|
32
|
+
const { __scopeTabs, loop = !0, children, ...listProps } = props, context = useTabsContext(__scopeTabs);
|
|
33
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
34
|
+
import_roving_focus.RovingFocusGroup,
|
|
35
|
+
{
|
|
36
|
+
__scopeRovingFocusGroup: __scopeTabs || TABS_CONTEXT,
|
|
37
|
+
orientation: context.orientation,
|
|
38
|
+
dir: context.dir,
|
|
39
|
+
loop,
|
|
40
|
+
asChild: !0,
|
|
41
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
42
|
+
import_group.Group,
|
|
43
|
+
{
|
|
44
|
+
role: "tablist",
|
|
45
|
+
componentName: TAB_LIST_NAME,
|
|
46
|
+
"aria-orientation": context.orientation,
|
|
47
|
+
ref: forwardedRef,
|
|
48
|
+
orientation: context.orientation,
|
|
49
|
+
...listProps,
|
|
50
|
+
children
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
TabsList.displayName = TAB_LIST_NAME;
|
|
58
|
+
const TRIGGER_NAME = "TabsTrigger", TabsTriggerFrame = (0, import_web.styled)(import_stacks.ThemeableStack, {
|
|
59
|
+
name: TRIGGER_NAME,
|
|
60
|
+
tag: "button",
|
|
61
|
+
justifyContent: "center",
|
|
62
|
+
alignItems: "center",
|
|
63
|
+
flexWrap: "nowrap",
|
|
64
|
+
flexDirection: "row",
|
|
65
|
+
cursor: "pointer",
|
|
66
|
+
userSelect: "none",
|
|
67
|
+
variants: {
|
|
68
|
+
size: {
|
|
69
|
+
"...size": import_get_button_sized.getButtonSized
|
|
70
|
+
},
|
|
71
|
+
disabled: {
|
|
72
|
+
true: {
|
|
73
|
+
pointerEvents: "none"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
active: {
|
|
77
|
+
true: {
|
|
78
|
+
hoverStyle: {
|
|
79
|
+
backgroundColor: "$background"
|
|
80
|
+
},
|
|
81
|
+
focusStyle: {
|
|
82
|
+
backgroundColor: "$background"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
unstyled: {
|
|
87
|
+
false: {
|
|
88
|
+
backgroundColor: "$background",
|
|
89
|
+
pressStyle: {
|
|
90
|
+
backgroundColor: "$backgroundPress"
|
|
91
|
+
},
|
|
92
|
+
hoverStyle: {
|
|
93
|
+
backgroundColor: "$backgroundHover"
|
|
94
|
+
},
|
|
95
|
+
focusStyle: {
|
|
96
|
+
backgroundColor: "$backgroundFocus"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
defaultVariants: {
|
|
102
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
103
|
+
}
|
|
104
|
+
}), TabsTrigger = TabsTriggerFrame.styleable(
|
|
105
|
+
(props, forwardedRef) => {
|
|
106
|
+
const {
|
|
107
|
+
__scopeTabs,
|
|
108
|
+
value,
|
|
109
|
+
disabled = !1,
|
|
110
|
+
onInteraction,
|
|
111
|
+
disableActiveTheme,
|
|
112
|
+
...triggerProps
|
|
113
|
+
} = props, context = useTabsContext(__scopeTabs), triggerId = makeTriggerId(context.baseId, value), contentId = makeContentId(context.baseId, value), isSelected = value === context.value, [layout, setLayout] = React.useState(null), triggerRef = React.useRef(null), groupItemProps = (0, import_group.useGroupItem)({ disabled: !!disabled });
|
|
114
|
+
return React.useEffect(() => (context.registerTrigger(), () => context.unregisterTrigger()), []), React.useEffect(() => {
|
|
115
|
+
if (!triggerRef.current || !import_constants.isWeb) return;
|
|
116
|
+
function getTriggerSize() {
|
|
117
|
+
triggerRef.current && setLayout({
|
|
118
|
+
width: triggerRef.current.offsetWidth,
|
|
119
|
+
height: triggerRef.current.offsetHeight,
|
|
120
|
+
x: triggerRef.current.offsetLeft,
|
|
121
|
+
y: triggerRef.current.offsetTop
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
getTriggerSize();
|
|
125
|
+
const observer = new ResizeObserver(getTriggerSize);
|
|
126
|
+
return observer.observe(triggerRef.current), () => {
|
|
127
|
+
triggerRef.current && observer.unobserve(triggerRef.current);
|
|
128
|
+
};
|
|
129
|
+
}, [context.triggersCount]), React.useEffect(() => {
|
|
130
|
+
isSelected && layout && onInteraction?.("select", layout);
|
|
131
|
+
}, [isSelected, value, layout]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_web.Theme, { name: isSelected && !disableActiveTheme ? "active" : null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
132
|
+
import_roving_focus.RovingFocusGroup.Item,
|
|
133
|
+
{
|
|
134
|
+
__scopeRovingFocusGroup: __scopeTabs || TABS_CONTEXT,
|
|
135
|
+
asChild: !0,
|
|
136
|
+
focusable: !disabled,
|
|
137
|
+
active: isSelected,
|
|
138
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
139
|
+
TabsTriggerFrame,
|
|
140
|
+
{
|
|
141
|
+
onLayout: (event) => {
|
|
142
|
+
import_constants.isWeb || setLayout(event.nativeEvent.layout);
|
|
143
|
+
},
|
|
144
|
+
onHoverIn: (0, import_helpers.composeEventHandlers)(props.onHoverIn, () => {
|
|
145
|
+
layout && onInteraction?.("hover", layout);
|
|
146
|
+
}),
|
|
147
|
+
onHoverOut: (0, import_helpers.composeEventHandlers)(props.onHoverOut, () => {
|
|
148
|
+
onInteraction?.("hover", null);
|
|
149
|
+
}),
|
|
150
|
+
role: "tab",
|
|
151
|
+
"aria-selected": isSelected,
|
|
152
|
+
"aria-controls": contentId,
|
|
153
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
154
|
+
"data-disabled": disabled ? "" : void 0,
|
|
155
|
+
disabled,
|
|
156
|
+
id: triggerId,
|
|
157
|
+
...!props.unstyled && {
|
|
158
|
+
size: context.size
|
|
159
|
+
},
|
|
160
|
+
...groupItemProps,
|
|
161
|
+
...triggerProps,
|
|
162
|
+
ref: (0, import_compose_refs.composeRefs)(forwardedRef, triggerRef),
|
|
163
|
+
onPress: (0, import_helpers.composeEventHandlers)(props.onPress ?? void 0, (event) => {
|
|
164
|
+
const webChecks = !import_constants.isWeb || event.button === 0 && event.ctrlKey === !1;
|
|
165
|
+
!disabled && !isSelected && webChecks ? context.onChange(value) : event.preventDefault();
|
|
166
|
+
}),
|
|
167
|
+
...import_constants.isWeb && {
|
|
168
|
+
type: "button",
|
|
169
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(
|
|
170
|
+
props.onKeyDown,
|
|
171
|
+
(event) => {
|
|
172
|
+
[" ", "Enter"].includes(event.key) && (context.onChange(value), event.preventDefault());
|
|
173
|
+
}
|
|
174
|
+
),
|
|
175
|
+
onFocus: (0, import_helpers.composeEventHandlers)(props.onFocus, (event) => {
|
|
176
|
+
layout && onInteraction?.("focus", layout);
|
|
177
|
+
const isAutomaticActivation = context.activationMode !== "manual";
|
|
178
|
+
!isSelected && !disabled && isAutomaticActivation && context.onChange(value);
|
|
179
|
+
}),
|
|
180
|
+
onBlur: (0, import_helpers.composeEventHandlers)(props.onFocus, () => {
|
|
181
|
+
onInteraction?.("focus", null);
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
) });
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
TabsTrigger.displayName = TRIGGER_NAME;
|
|
191
|
+
const CONTENT_NAME = "TabsContent", TabsContentFrame = (0, import_web.styled)(import_stacks.ThemeableStack, {
|
|
192
|
+
name: CONTENT_NAME
|
|
193
|
+
}), TabsContent = TabsContentFrame.styleable(
|
|
194
|
+
function(props, forwardedRef) {
|
|
195
|
+
const { __scopeTabs, value, forceMount, children, ...contentProps } = props, context = useTabsContext(__scopeTabs), isSelected = value === context.value, show = forceMount || isSelected, triggerId = makeTriggerId(context.baseId, value), contentId = makeContentId(context.baseId, value);
|
|
196
|
+
return show ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
197
|
+
TabsContentFrame,
|
|
198
|
+
{
|
|
199
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
200
|
+
"data-orientation": context.orientation,
|
|
201
|
+
role: "tabpanel",
|
|
202
|
+
"aria-labelledby": triggerId,
|
|
203
|
+
hidden: !show,
|
|
204
|
+
id: contentId,
|
|
205
|
+
tabIndex: 0,
|
|
206
|
+
...contentProps,
|
|
207
|
+
ref: forwardedRef,
|
|
208
|
+
children
|
|
209
|
+
},
|
|
210
|
+
value
|
|
211
|
+
) : null;
|
|
212
|
+
}
|
|
213
|
+
), TABS_NAME = "Tabs", { Provider: TabsProvider, useStyledContext: useTabsContext } = (0, import_web.createStyledContext)(), TabsFrame = (0, import_web.styled)(import_stacks.SizableStack, {
|
|
214
|
+
name: TABS_NAME
|
|
215
|
+
}), TabsComponent = TabsFrame.styleable(
|
|
216
|
+
(props, forwardedRef) => {
|
|
217
|
+
const {
|
|
218
|
+
__scopeTabs,
|
|
219
|
+
value: valueProp,
|
|
220
|
+
onValueChange,
|
|
221
|
+
defaultValue,
|
|
222
|
+
orientation = "horizontal",
|
|
223
|
+
dir,
|
|
224
|
+
activationMode = "automatic",
|
|
225
|
+
size = "$true",
|
|
226
|
+
...tabsProps
|
|
227
|
+
} = props, direction = (0, import_use_direction.useDirection)(dir), [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
228
|
+
prop: valueProp,
|
|
229
|
+
onChange: onValueChange,
|
|
230
|
+
defaultProp: defaultValue ?? ""
|
|
231
|
+
}), [triggersCount, setTriggersCount] = React.useState(0), registerTrigger = (0, import_web.useEvent)(() => setTriggersCount((v) => v + 1)), unregisterTrigger = (0, import_web.useEvent)(() => setTriggersCount((v) => v - 1));
|
|
232
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
233
|
+
TabsProvider,
|
|
234
|
+
{
|
|
235
|
+
scope: __scopeTabs,
|
|
236
|
+
baseId: React.useId(),
|
|
237
|
+
value,
|
|
238
|
+
onChange: setValue,
|
|
239
|
+
orientation,
|
|
240
|
+
dir: direction,
|
|
241
|
+
activationMode,
|
|
242
|
+
size,
|
|
243
|
+
registerTrigger,
|
|
244
|
+
triggersCount,
|
|
245
|
+
unregisterTrigger,
|
|
246
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
247
|
+
TabsFrame,
|
|
248
|
+
{
|
|
249
|
+
direction,
|
|
250
|
+
"data-orientation": orientation,
|
|
251
|
+
...tabsProps,
|
|
252
|
+
ref: forwardedRef
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
), Tabs = (0, import_helpers.withStaticProperties)(TabsComponent, {
|
|
259
|
+
List: TabsList,
|
|
260
|
+
/**
|
|
261
|
+
* @deprecated Use Tabs.Tab instead
|
|
262
|
+
*/
|
|
263
|
+
Trigger: TabsTrigger,
|
|
264
|
+
Tab: TabsTrigger,
|
|
265
|
+
Content: TabsContent
|
|
266
|
+
});
|
|
267
|
+
Tabs.displayName = TABS_NAME;
|
|
268
|
+
function makeTriggerId(baseId, value) {
|
|
269
|
+
return `${baseId}-trigger-${value}`;
|
|
270
|
+
}
|
|
271
|
+
function makeContentId(baseId, value) {
|
|
272
|
+
return `${baseId}-content-${value}`;
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=Tabs.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
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))
|
|
8
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
+
return to;
|
|
10
|
+
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
+
var src_exports = {};
|
|
13
|
+
module.exports = __toCommonJS(src_exports);
|
|
14
|
+
__reExport(src_exports, require("./Tabs"), module.exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/tabs",
|
|
3
|
-
"version": "1.116.
|
|
3
|
+
"version": "1.116.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -32,23 +32,23 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@tamagui/compose-refs": "1.116.
|
|
36
|
-
"@tamagui/constants": "1.116.
|
|
37
|
-
"@tamagui/create-context": "1.116.
|
|
38
|
-
"@tamagui/get-button-sized": "1.116.
|
|
39
|
-
"@tamagui/group": "1.116.
|
|
40
|
-
"@tamagui/helpers": "1.116.
|
|
41
|
-
"@tamagui/roving-focus": "1.116.
|
|
42
|
-
"@tamagui/stacks": "1.116.
|
|
43
|
-
"@tamagui/use-controllable-state": "1.116.
|
|
44
|
-
"@tamagui/use-direction": "1.116.
|
|
45
|
-
"@tamagui/web": "1.116.
|
|
35
|
+
"@tamagui/compose-refs": "1.116.2",
|
|
36
|
+
"@tamagui/constants": "1.116.2",
|
|
37
|
+
"@tamagui/create-context": "1.116.2",
|
|
38
|
+
"@tamagui/get-button-sized": "1.116.2",
|
|
39
|
+
"@tamagui/group": "1.116.2",
|
|
40
|
+
"@tamagui/helpers": "1.116.2",
|
|
41
|
+
"@tamagui/roving-focus": "1.116.2",
|
|
42
|
+
"@tamagui/stacks": "1.116.2",
|
|
43
|
+
"@tamagui/use-controllable-state": "1.116.2",
|
|
44
|
+
"@tamagui/use-direction": "1.116.2",
|
|
45
|
+
"@tamagui/web": "1.116.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": "*"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@tamagui/build": "1.116.
|
|
51
|
+
"@tamagui/build": "1.116.2",
|
|
52
52
|
"react": "^18.2.0 || ^19.0.0",
|
|
53
53
|
"react-dom": "^18.2.0 || ^19.0.0"
|
|
54
54
|
},
|
|
File without changes
|
|
File without changes
|