@tamagui/tabs 1.27.2 → 1.27.3
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/package.json +10 -10
- package/dist/esm/Tabs.mjs +0 -331
- package/dist/esm/index.mjs +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/tabs",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.3",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tamagui/create-context": "1.27.
|
|
29
|
-
"@tamagui/get-button-sized": "1.27.
|
|
30
|
-
"@tamagui/group": "1.27.
|
|
31
|
-
"@tamagui/roving-focus": "1.27.
|
|
32
|
-
"@tamagui/stacks": "1.27.
|
|
33
|
-
"@tamagui/use-controllable-state": "1.27.
|
|
34
|
-
"@tamagui/use-direction": "1.27.
|
|
35
|
-
"@tamagui/web": "1.27.
|
|
28
|
+
"@tamagui/create-context": "1.27.3",
|
|
29
|
+
"@tamagui/get-button-sized": "1.27.3",
|
|
30
|
+
"@tamagui/group": "1.27.3",
|
|
31
|
+
"@tamagui/roving-focus": "1.27.3",
|
|
32
|
+
"@tamagui/stacks": "1.27.3",
|
|
33
|
+
"@tamagui/use-controllable-state": "1.27.3",
|
|
34
|
+
"@tamagui/use-direction": "1.27.3",
|
|
35
|
+
"@tamagui/web": "1.27.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "*",
|
|
39
39
|
"react-dom": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.27.
|
|
42
|
+
"@tamagui/build": "1.27.3",
|
|
43
43
|
"react": "^18.2.0",
|
|
44
44
|
"react-dom": "^18.2.0"
|
|
45
45
|
},
|
package/dist/esm/Tabs.mjs
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContextScope } from "@tamagui/create-context";
|
|
3
|
-
import { getButtonSized } from "@tamagui/get-button-sized";
|
|
4
|
-
import { Group, useGroupItem } from "@tamagui/group";
|
|
5
|
-
import { RovingFocusGroup, createRovingFocusGroupScope } from "@tamagui/roving-focus";
|
|
6
|
-
import { SizableStack, ThemeableStack } from "@tamagui/stacks";
|
|
7
|
-
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
8
|
-
import { useDirection } from "@tamagui/use-direction";
|
|
9
|
-
import {
|
|
10
|
-
Theme,
|
|
11
|
-
composeEventHandlers,
|
|
12
|
-
composeRefs,
|
|
13
|
-
isWeb,
|
|
14
|
-
styled,
|
|
15
|
-
useEvent,
|
|
16
|
-
withStaticProperties
|
|
17
|
-
} from "@tamagui/web";
|
|
18
|
-
import * as React from "react";
|
|
19
|
-
const TAB_LIST_NAME = "TabsList";
|
|
20
|
-
const TabsListFrame = styled(Group, {
|
|
21
|
-
name: TAB_LIST_NAME,
|
|
22
|
-
focusable: true
|
|
23
|
-
});
|
|
24
|
-
const TabsList = TabsListFrame.extractable(
|
|
25
|
-
React.forwardRef(
|
|
26
|
-
(props, forwardedRef) => {
|
|
27
|
-
const { __scopeTabs, loop = true, children, ...listProps } = props;
|
|
28
|
-
const context = useTabsContext(TAB_LIST_NAME, __scopeTabs);
|
|
29
|
-
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeTabs);
|
|
30
|
-
return /* @__PURE__ */ jsx(
|
|
31
|
-
RovingFocusGroup,
|
|
32
|
-
{
|
|
33
|
-
asChild: true,
|
|
34
|
-
orientation: context.orientation,
|
|
35
|
-
dir: context.dir,
|
|
36
|
-
loop,
|
|
37
|
-
...rovingFocusGroupScope,
|
|
38
|
-
children: /* @__PURE__ */ jsx(
|
|
39
|
-
TabsListFrame,
|
|
40
|
-
{
|
|
41
|
-
role: "tablist",
|
|
42
|
-
"aria-orientation": context.orientation,
|
|
43
|
-
ref: forwardedRef,
|
|
44
|
-
axis: context.orientation,
|
|
45
|
-
...listProps,
|
|
46
|
-
children
|
|
47
|
-
}
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
TabsList.displayName = TAB_LIST_NAME;
|
|
55
|
-
const TRIGGER_NAME = "TabsTrigger";
|
|
56
|
-
const TabsTriggerFrame = styled(ThemeableStack, {
|
|
57
|
-
name: TRIGGER_NAME,
|
|
58
|
-
justifyContent: "center",
|
|
59
|
-
alignItems: "center",
|
|
60
|
-
flexWrap: "nowrap",
|
|
61
|
-
flexDirection: "row",
|
|
62
|
-
cursor: "pointer",
|
|
63
|
-
focusable: true,
|
|
64
|
-
variants: {
|
|
65
|
-
size: {
|
|
66
|
-
"...size": getButtonSized
|
|
67
|
-
},
|
|
68
|
-
disabled: {
|
|
69
|
-
true: {
|
|
70
|
-
pointerEvents: "none"
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
unstyled: {
|
|
74
|
-
false: {
|
|
75
|
-
backgroundColor: "$background",
|
|
76
|
-
pressStyle: {
|
|
77
|
-
backgroundColor: "$backgroundPress"
|
|
78
|
-
},
|
|
79
|
-
hoverStyle: {
|
|
80
|
-
backgroundColor: "$backgroundHover"
|
|
81
|
-
},
|
|
82
|
-
focusStyle: {
|
|
83
|
-
backgroundColor: "$backgroundFocus"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
defaultVariants: {
|
|
89
|
-
unstyled: false
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
const TabsTrigger = TabsTriggerFrame.extractable(
|
|
93
|
-
React.forwardRef(
|
|
94
|
-
(props, forwardedRef) => {
|
|
95
|
-
const {
|
|
96
|
-
__scopeTabs,
|
|
97
|
-
value,
|
|
98
|
-
disabled = false,
|
|
99
|
-
onInteraction,
|
|
100
|
-
...triggerProps
|
|
101
|
-
} = props;
|
|
102
|
-
const context = useTabsContext(TRIGGER_NAME, __scopeTabs);
|
|
103
|
-
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeTabs);
|
|
104
|
-
const triggerId = makeTriggerId(context.baseId, value);
|
|
105
|
-
const contentId = makeContentId(context.baseId, value);
|
|
106
|
-
const isSelected = value === context.value;
|
|
107
|
-
const [layout, setLayout] = React.useState(null);
|
|
108
|
-
const triggerRef = React.useRef(null);
|
|
109
|
-
const groupItemProps = useGroupItem({ disabled });
|
|
110
|
-
React.useEffect(() => {
|
|
111
|
-
context.registerTrigger();
|
|
112
|
-
return () => context.unregisterTrigger();
|
|
113
|
-
}, []);
|
|
114
|
-
React.useEffect(() => {
|
|
115
|
-
if (!triggerRef.current || !isWeb)
|
|
116
|
-
return;
|
|
117
|
-
function getTriggerSize() {
|
|
118
|
-
if (!triggerRef.current)
|
|
119
|
-
return;
|
|
120
|
-
setLayout({
|
|
121
|
-
width: triggerRef.current.offsetWidth,
|
|
122
|
-
height: triggerRef.current.offsetHeight,
|
|
123
|
-
x: triggerRef.current.offsetLeft,
|
|
124
|
-
y: triggerRef.current.offsetTop
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
getTriggerSize();
|
|
128
|
-
const observer = new ResizeObserver(getTriggerSize);
|
|
129
|
-
observer.observe(triggerRef.current);
|
|
130
|
-
return () => {
|
|
131
|
-
if (!triggerRef.current)
|
|
132
|
-
return;
|
|
133
|
-
observer.unobserve(triggerRef.current);
|
|
134
|
-
};
|
|
135
|
-
}, [context.triggersCount]);
|
|
136
|
-
React.useEffect(() => {
|
|
137
|
-
if (isSelected && layout) {
|
|
138
|
-
onInteraction == null ? void 0 : onInteraction("select", layout);
|
|
139
|
-
}
|
|
140
|
-
}, [isSelected, value, layout]);
|
|
141
|
-
return /* @__PURE__ */ jsx(Theme, { name: isSelected ? "active" : null, children: /* @__PURE__ */ jsx(
|
|
142
|
-
RovingFocusGroup.Item,
|
|
143
|
-
{
|
|
144
|
-
asChild: true,
|
|
145
|
-
...rovingFocusGroupScope,
|
|
146
|
-
focusable: !disabled,
|
|
147
|
-
active: isSelected,
|
|
148
|
-
children: /* @__PURE__ */ jsx(
|
|
149
|
-
TabsTriggerFrame,
|
|
150
|
-
{
|
|
151
|
-
onLayout: (event) => {
|
|
152
|
-
if (!isWeb) {
|
|
153
|
-
setLayout(event.nativeEvent.layout);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
onHoverIn: composeEventHandlers(props.onHoverIn, () => {
|
|
157
|
-
if (layout) {
|
|
158
|
-
onInteraction == null ? void 0 : onInteraction("hover", layout);
|
|
159
|
-
}
|
|
160
|
-
}),
|
|
161
|
-
onHoverOut: composeEventHandlers(props.onHoverOut, () => {
|
|
162
|
-
onInteraction == null ? void 0 : onInteraction("hover", null);
|
|
163
|
-
}),
|
|
164
|
-
role: "tab",
|
|
165
|
-
"aria-selected": isSelected,
|
|
166
|
-
"aria-controls": contentId,
|
|
167
|
-
"data-state": isSelected ? "active" : "inactive",
|
|
168
|
-
"data-disabled": disabled ? "" : void 0,
|
|
169
|
-
disabled,
|
|
170
|
-
id: triggerId,
|
|
171
|
-
size: context.size,
|
|
172
|
-
...triggerProps,
|
|
173
|
-
ref: composeRefs(forwardedRef, triggerRef),
|
|
174
|
-
onPress: composeEventHandlers(props.onPress ?? void 0, (event) => {
|
|
175
|
-
const webChecks = !isWeb || event.button === 0 && event.ctrlKey === false;
|
|
176
|
-
if (!disabled && !isSelected && webChecks) {
|
|
177
|
-
context.onChange(value);
|
|
178
|
-
} else {
|
|
179
|
-
event.preventDefault();
|
|
180
|
-
}
|
|
181
|
-
}),
|
|
182
|
-
...isWeb && {
|
|
183
|
-
type: "button",
|
|
184
|
-
onKeyDown: composeEventHandlers(
|
|
185
|
-
props.onKeyDown,
|
|
186
|
-
(event) => {
|
|
187
|
-
if ([" ", "Enter"].includes(event.key)) {
|
|
188
|
-
context.onChange(value);
|
|
189
|
-
event.preventDefault();
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
),
|
|
193
|
-
onFocus: composeEventHandlers(props.onFocus, (event) => {
|
|
194
|
-
if (layout) {
|
|
195
|
-
onInteraction == null ? void 0 : onInteraction("focus", layout);
|
|
196
|
-
}
|
|
197
|
-
const isAutomaticActivation = context.activationMode !== "manual";
|
|
198
|
-
if (!isSelected && !disabled && isAutomaticActivation) {
|
|
199
|
-
context.onChange(value);
|
|
200
|
-
}
|
|
201
|
-
}),
|
|
202
|
-
onBlur: composeEventHandlers(props.onFocus, () => {
|
|
203
|
-
onInteraction == null ? void 0 : onInteraction("focus", null);
|
|
204
|
-
})
|
|
205
|
-
},
|
|
206
|
-
...groupItemProps
|
|
207
|
-
}
|
|
208
|
-
)
|
|
209
|
-
}
|
|
210
|
-
) });
|
|
211
|
-
}
|
|
212
|
-
)
|
|
213
|
-
);
|
|
214
|
-
TabsTrigger.displayName = TRIGGER_NAME;
|
|
215
|
-
const CONTENT_NAME = "TabsContent";
|
|
216
|
-
const TabsContentFrame = styled(ThemeableStack, {
|
|
217
|
-
name: CONTENT_NAME
|
|
218
|
-
});
|
|
219
|
-
const TabsContent = TabsContentFrame.extractable(
|
|
220
|
-
React.forwardRef(
|
|
221
|
-
(props, forwardedRef) => {
|
|
222
|
-
const { __scopeTabs, value, forceMount, children, ...contentProps } = props;
|
|
223
|
-
const context = useTabsContext(CONTENT_NAME, __scopeTabs);
|
|
224
|
-
const isSelected = value === context.value;
|
|
225
|
-
const show = forceMount || isSelected;
|
|
226
|
-
const triggerId = makeTriggerId(context.baseId, value);
|
|
227
|
-
const contentId = makeContentId(context.baseId, value);
|
|
228
|
-
if (!show)
|
|
229
|
-
return null;
|
|
230
|
-
return /* @__PURE__ */ jsx(
|
|
231
|
-
TabsContentFrame,
|
|
232
|
-
{
|
|
233
|
-
"data-state": isSelected ? "active" : "inactive",
|
|
234
|
-
"data-orientation": context.orientation,
|
|
235
|
-
role: "tabpanel",
|
|
236
|
-
"aria-labelledby": triggerId,
|
|
237
|
-
hidden: !show,
|
|
238
|
-
id: contentId,
|
|
239
|
-
tabIndex: 0,
|
|
240
|
-
...contentProps,
|
|
241
|
-
ref: forwardedRef,
|
|
242
|
-
children
|
|
243
|
-
},
|
|
244
|
-
value
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
)
|
|
248
|
-
);
|
|
249
|
-
TabsContent.displayName = CONTENT_NAME;
|
|
250
|
-
const TABS_NAME = "Tabs";
|
|
251
|
-
const [createTabsContext, createTabsScope] = createContextScope(TABS_NAME, [
|
|
252
|
-
createRovingFocusGroupScope
|
|
253
|
-
]);
|
|
254
|
-
const useRovingFocusGroupScope = createRovingFocusGroupScope();
|
|
255
|
-
const [TabsProvider, useTabsContext] = createTabsContext(TABS_NAME);
|
|
256
|
-
const TabsFrame = styled(SizableStack, {
|
|
257
|
-
name: TABS_NAME
|
|
258
|
-
});
|
|
259
|
-
const Tabs = withStaticProperties(
|
|
260
|
-
TabsFrame.extractable(
|
|
261
|
-
React.forwardRef(
|
|
262
|
-
(props, forwardedRef) => {
|
|
263
|
-
const {
|
|
264
|
-
__scopeTabs,
|
|
265
|
-
value: valueProp,
|
|
266
|
-
onValueChange,
|
|
267
|
-
defaultValue,
|
|
268
|
-
orientation = "horizontal",
|
|
269
|
-
dir,
|
|
270
|
-
activationMode = "automatic",
|
|
271
|
-
size = "$true",
|
|
272
|
-
...tabsProps
|
|
273
|
-
} = props;
|
|
274
|
-
const direction = useDirection(dir);
|
|
275
|
-
const [value, setValue] = useControllableState({
|
|
276
|
-
prop: valueProp,
|
|
277
|
-
onChange: onValueChange,
|
|
278
|
-
defaultProp: defaultValue ?? ""
|
|
279
|
-
});
|
|
280
|
-
const [triggersCount, setTriggersCount] = React.useState(0);
|
|
281
|
-
const registerTrigger = useEvent(() => setTriggersCount((v) => v + 1));
|
|
282
|
-
const unregisterTrigger = useEvent(() => setTriggersCount((v) => v - 1));
|
|
283
|
-
return /* @__PURE__ */ jsx(
|
|
284
|
-
TabsProvider,
|
|
285
|
-
{
|
|
286
|
-
scope: __scopeTabs,
|
|
287
|
-
baseId: React.useId(),
|
|
288
|
-
value,
|
|
289
|
-
onChange: setValue,
|
|
290
|
-
orientation,
|
|
291
|
-
dir: direction,
|
|
292
|
-
activationMode,
|
|
293
|
-
size,
|
|
294
|
-
registerTrigger,
|
|
295
|
-
triggersCount,
|
|
296
|
-
unregisterTrigger,
|
|
297
|
-
children: /* @__PURE__ */ jsx(
|
|
298
|
-
TabsFrame,
|
|
299
|
-
{
|
|
300
|
-
direction,
|
|
301
|
-
"data-orientation": orientation,
|
|
302
|
-
...tabsProps,
|
|
303
|
-
ref: forwardedRef
|
|
304
|
-
}
|
|
305
|
-
)
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
)
|
|
310
|
-
),
|
|
311
|
-
{
|
|
312
|
-
List: TabsList,
|
|
313
|
-
/**
|
|
314
|
-
* @deprecated Use Tabs.Tab instead
|
|
315
|
-
*/
|
|
316
|
-
Trigger: TabsTrigger,
|
|
317
|
-
Tab: TabsTrigger,
|
|
318
|
-
Content: TabsContent
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
Tabs.displayName = TABS_NAME;
|
|
322
|
-
function makeTriggerId(baseId, value) {
|
|
323
|
-
return `${baseId}-trigger-${value}`;
|
|
324
|
-
}
|
|
325
|
-
function makeContentId(baseId, value) {
|
|
326
|
-
return `${baseId}-content-${value}`;
|
|
327
|
-
}
|
|
328
|
-
export {
|
|
329
|
-
Tabs
|
|
330
|
-
};
|
|
331
|
-
//# sourceMappingURL=Tabs.mjs.map
|
package/dist/esm/index.mjs
DELETED