@xaui/native 0.0.21 → 0.0.24
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/README.md +195 -2
- package/dist/alert/index.js +1 -2
- package/dist/app-bar/index.cjs +217 -0
- package/dist/app-bar/index.d.cts +52 -0
- package/dist/app-bar/index.d.ts +52 -0
- package/dist/app-bar/index.js +142 -0
- package/dist/autocomplete/index.js +48 -36
- package/dist/avatar/index.js +1 -2
- package/dist/badge/index.js +1 -2
- package/dist/bottom-sheet/index.js +1 -2
- package/dist/bottom-tab-bar/index.cjs +571 -0
- package/dist/bottom-tab-bar/index.d.cts +211 -0
- package/dist/bottom-tab-bar/index.d.ts +211 -0
- package/dist/bottom-tab-bar/index.js +497 -0
- package/dist/button/index.d.cts +102 -5
- package/dist/button/index.d.ts +102 -5
- package/dist/button/index.js +2 -3
- package/dist/button.type-j1ZdkkSl.d.cts +4 -0
- package/dist/button.type-j1ZdkkSl.d.ts +4 -0
- package/dist/card/index.cjs +2 -0
- package/dist/card/index.d.cts +6 -1
- package/dist/card/index.d.ts +6 -1
- package/dist/card/index.js +4 -2
- package/dist/carousel/index.js +1 -1
- package/dist/chart/index.cjs +1067 -0
- package/dist/chart/index.d.cts +218 -0
- package/dist/chart/index.d.ts +218 -0
- package/dist/chart/index.js +1026 -0
- package/dist/checkbox/index.js +1 -2
- package/dist/chip/index.js +1 -2
- package/dist/chunk-3XSXTM3G.js +661 -0
- package/dist/chunk-4KSZLONZ.js +79 -0
- package/dist/{chunk-DXXNBF5P.js → chunk-CZFDZPAS.js} +0 -5
- package/dist/{chunk-LTKYHG5V.js → chunk-GHCVNQET.js} +12 -5
- package/dist/chunk-I4V5Y5GD.js +76 -0
- package/dist/{chunk-F7WH4DMG.js → chunk-UI5L26KD.js} +1 -1
- package/dist/{chunk-LUBWRVI2.js → chunk-ULJSCNPE.js} +1 -1
- package/dist/chunk-URBEEDFX.js +79 -0
- package/dist/core/index.js +3 -5
- package/dist/datepicker/index.js +1 -2
- package/dist/divider/index.js +2 -3
- package/dist/drawer/index.cjs +310 -0
- package/dist/drawer/index.d.cts +58 -0
- package/dist/drawer/index.d.ts +58 -0
- package/dist/drawer/index.js +236 -0
- package/dist/{accordion → expansion-panel}/index.cjs +45 -45
- package/dist/{accordion → expansion-panel}/index.d.cts +30 -30
- package/dist/{accordion → expansion-panel}/index.d.ts +30 -30
- package/dist/{accordion → expansion-panel}/index.js +40 -41
- package/dist/fab/index.d.cts +3 -3
- package/dist/fab/index.d.ts +3 -3
- package/dist/fab/index.js +3 -4
- package/dist/fab-menu/index.d.cts +2 -2
- package/dist/fab-menu/index.d.ts +2 -2
- package/dist/fab-menu/index.js +3 -4
- package/dist/{fab.type-Ba0QMprb.d.ts → fab.type-CgIYqQlT.d.ts} +1 -1
- package/dist/{fab.type-U09H8B7D.d.cts → fab.type-l2vjG8-p.d.cts} +1 -1
- package/dist/feature-discovery/index.cjs +531 -0
- package/dist/feature-discovery/index.d.cts +82 -0
- package/dist/feature-discovery/index.d.ts +82 -0
- package/dist/feature-discovery/index.js +464 -0
- package/dist/indicator/index.js +2 -3
- package/dist/input/index.cjs +258 -164
- package/dist/input/index.d.cts +15 -1
- package/dist/input/index.d.ts +15 -1
- package/dist/input/index.js +219 -126
- package/dist/list/index.js +1 -2
- package/dist/menu/index.js +2 -2
- package/dist/menubox/index.cjs +369 -0
- package/dist/menubox/index.d.cts +98 -0
- package/dist/menubox/index.d.ts +98 -0
- package/dist/menubox/index.js +296 -0
- package/dist/pager/index.cjs +243 -0
- package/dist/pager/index.d.cts +93 -0
- package/dist/pager/index.d.ts +93 -0
- package/dist/pager/index.js +205 -0
- package/dist/progress/index.js +1 -2
- package/dist/radio/index.cjs +537 -0
- package/dist/radio/index.d.cts +145 -0
- package/dist/radio/index.d.ts +145 -0
- package/dist/radio/index.js +464 -0
- package/dist/segment-button/index.js +2 -2
- package/dist/select/index.js +22 -10
- package/dist/skeleton/index.js +2 -2
- package/dist/slider/index.cjs +655 -0
- package/dist/slider/index.d.cts +171 -0
- package/dist/slider/index.d.ts +171 -0
- package/dist/slider/index.js +575 -0
- package/dist/stepper/index.cjs +624 -0
- package/dist/stepper/index.d.cts +137 -0
- package/dist/stepper/index.d.ts +137 -0
- package/dist/stepper/index.js +549 -0
- package/dist/switch/index.js +1 -2
- package/dist/tabs/index.cjs +523 -0
- package/dist/tabs/index.d.cts +176 -0
- package/dist/tabs/index.d.ts +176 -0
- package/dist/tabs/index.js +438 -0
- package/dist/timepicker/index.cjs +1280 -0
- package/dist/timepicker/index.d.cts +215 -0
- package/dist/timepicker/index.d.ts +215 -0
- package/dist/timepicker/index.js +1181 -0
- package/dist/toolbar/index.cjs +395 -0
- package/dist/toolbar/index.d.cts +100 -0
- package/dist/toolbar/index.d.ts +100 -0
- package/dist/toolbar/index.js +325 -0
- package/dist/typography/index.js +1 -2
- package/dist/view/index.cjs +16 -2
- package/dist/view/index.js +16 -2
- package/package.json +73 -8
- package/dist/button.type-D8tzEBo7.d.ts +0 -104
- package/dist/button.type-ikaWzhIg.d.cts +0 -104
- package/dist/chunk-GBHQCAKW.js +0 -19
- package/dist/chunk-JEGEPGVU.js +0 -287
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
+
import { T as ThemeColor, S as Size, R as Radius } from '../index-BOw6tbkc.js';
|
|
4
|
+
|
|
5
|
+
type TabsVariant = 'solid' | 'bordered' | 'light' | 'underlined';
|
|
6
|
+
type TabsItem = {
|
|
7
|
+
/**
|
|
8
|
+
* Unique key for the tab.
|
|
9
|
+
*/
|
|
10
|
+
key: string;
|
|
11
|
+
/**
|
|
12
|
+
* Label content for the tab trigger.
|
|
13
|
+
*/
|
|
14
|
+
title: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Optional content displayed before the title.
|
|
17
|
+
*/
|
|
18
|
+
startContent?: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Optional content displayed after the title.
|
|
21
|
+
*/
|
|
22
|
+
endContent?: ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Whether this tab is disabled.
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
isDisabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Optional content rendered when this tab is selected.
|
|
30
|
+
*/
|
|
31
|
+
content?: ReactNode;
|
|
32
|
+
};
|
|
33
|
+
type TabProps = {
|
|
34
|
+
/**
|
|
35
|
+
* Label content for the tab trigger.
|
|
36
|
+
*/
|
|
37
|
+
title: ReactNode;
|
|
38
|
+
/**
|
|
39
|
+
* Optional content displayed before the title.
|
|
40
|
+
*/
|
|
41
|
+
startContent?: ReactNode;
|
|
42
|
+
/**
|
|
43
|
+
* Optional content displayed after the title.
|
|
44
|
+
*/
|
|
45
|
+
endContent?: ReactNode;
|
|
46
|
+
/**
|
|
47
|
+
* Whether this tab is disabled.
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
isDisabled?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Optional content rendered when this tab is selected.
|
|
53
|
+
*/
|
|
54
|
+
children?: ReactNode;
|
|
55
|
+
};
|
|
56
|
+
type TabsCustomAppearance = {
|
|
57
|
+
/**
|
|
58
|
+
* Custom styles for the outer container.
|
|
59
|
+
*/
|
|
60
|
+
container?: ViewStyle;
|
|
61
|
+
/**
|
|
62
|
+
* Custom styles for the tabs list wrapper.
|
|
63
|
+
*/
|
|
64
|
+
list?: ViewStyle;
|
|
65
|
+
/**
|
|
66
|
+
* Custom styles for each tab trigger.
|
|
67
|
+
*/
|
|
68
|
+
tab?: ViewStyle;
|
|
69
|
+
/**
|
|
70
|
+
* Custom styles for the selected tab trigger.
|
|
71
|
+
*/
|
|
72
|
+
selectedTab?: ViewStyle;
|
|
73
|
+
/**
|
|
74
|
+
* Custom styles for tab title text.
|
|
75
|
+
*/
|
|
76
|
+
text?: TextStyle;
|
|
77
|
+
/**
|
|
78
|
+
* Custom styles for selected tab title text.
|
|
79
|
+
*/
|
|
80
|
+
selectedText?: TextStyle;
|
|
81
|
+
/**
|
|
82
|
+
* Custom styles for the animated cursor.
|
|
83
|
+
*/
|
|
84
|
+
cursor?: ViewStyle;
|
|
85
|
+
/**
|
|
86
|
+
* Custom styles for optional content area.
|
|
87
|
+
*/
|
|
88
|
+
content?: ViewStyle;
|
|
89
|
+
};
|
|
90
|
+
type RenderTabState = {
|
|
91
|
+
isSelected: boolean;
|
|
92
|
+
isDisabled: boolean;
|
|
93
|
+
};
|
|
94
|
+
type RenderChildrenState = {
|
|
95
|
+
selectedKey: string;
|
|
96
|
+
selectedItem?: TabsItem;
|
|
97
|
+
};
|
|
98
|
+
type TabsProps = {
|
|
99
|
+
/**
|
|
100
|
+
* Controlled selected key.
|
|
101
|
+
*/
|
|
102
|
+
selectedKey?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Default selected key in uncontrolled mode.
|
|
105
|
+
*/
|
|
106
|
+
defaultSelectedKey?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Callback fired when selection changes.
|
|
109
|
+
*/
|
|
110
|
+
onSelectionChange?: (key: string) => void;
|
|
111
|
+
/**
|
|
112
|
+
* Keys that should be disabled.
|
|
113
|
+
*/
|
|
114
|
+
disabledKeys?: string[];
|
|
115
|
+
/**
|
|
116
|
+
* Theme color of tabs.
|
|
117
|
+
* @default 'primary'
|
|
118
|
+
*/
|
|
119
|
+
color?: ThemeColor;
|
|
120
|
+
/**
|
|
121
|
+
* Visual variant.
|
|
122
|
+
* @default 'solid'
|
|
123
|
+
*/
|
|
124
|
+
variant?: TabsVariant;
|
|
125
|
+
/**
|
|
126
|
+
* Size of tab triggers.
|
|
127
|
+
* @default 'md'
|
|
128
|
+
*/
|
|
129
|
+
size?: Size;
|
|
130
|
+
/**
|
|
131
|
+
* Border radius for list and cursor.
|
|
132
|
+
* @default 'full'
|
|
133
|
+
*/
|
|
134
|
+
radius?: Radius;
|
|
135
|
+
/**
|
|
136
|
+
* Whether tabs should stretch to full width.
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
fullWidth?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Whether all tabs are disabled.
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
isDisabled?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Disable cursor animation.
|
|
147
|
+
* @default false
|
|
148
|
+
*/
|
|
149
|
+
disableAnimation?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Animation duration in milliseconds.
|
|
152
|
+
* @default 220
|
|
153
|
+
*/
|
|
154
|
+
animationDuration?: number;
|
|
155
|
+
/**
|
|
156
|
+
* Optional custom tab renderer.
|
|
157
|
+
*/
|
|
158
|
+
renderTab?: (item: TabsItem, state: RenderTabState) => ReactNode;
|
|
159
|
+
/**
|
|
160
|
+
* Tab items as children.
|
|
161
|
+
*/
|
|
162
|
+
children: ReactNode;
|
|
163
|
+
/**
|
|
164
|
+
* Optional content area rendered below the tabs.
|
|
165
|
+
*/
|
|
166
|
+
content?: ReactNode | ((state: RenderChildrenState) => ReactNode);
|
|
167
|
+
/**
|
|
168
|
+
* Custom appearance overrides.
|
|
169
|
+
*/
|
|
170
|
+
customAppearance?: TabsCustomAppearance;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
declare const Tab: React.FC<TabProps>;
|
|
174
|
+
declare const Tabs: React.FC<TabsProps>;
|
|
175
|
+
|
|
176
|
+
export { Tab, type TabProps, Tabs, type TabsItem, type TabsProps, type TabsVariant };
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useBorderRadiusStyles,
|
|
3
|
+
useXUITheme
|
|
4
|
+
} from "../chunk-4KSZLONZ.js";
|
|
5
|
+
|
|
6
|
+
// src/components/tabs/tabs.tsx
|
|
7
|
+
import React, { useCallback, useEffect, useMemo as useMemo2, useRef, useState } from "react";
|
|
8
|
+
import {
|
|
9
|
+
Animated as Animated2,
|
|
10
|
+
Pressable,
|
|
11
|
+
Text,
|
|
12
|
+
View
|
|
13
|
+
} from "react-native";
|
|
14
|
+
|
|
15
|
+
// src/components/tabs/tabs.animation.ts
|
|
16
|
+
import { Animated, Easing } from "react-native";
|
|
17
|
+
var runTabsCursorAnimation = (translateX, width, scaleX, toX, toWidth, duration) => {
|
|
18
|
+
scaleX.setValue(0.75);
|
|
19
|
+
Animated.parallel([
|
|
20
|
+
Animated.timing(translateX, {
|
|
21
|
+
toValue: toX,
|
|
22
|
+
duration,
|
|
23
|
+
easing: Easing.inOut(Easing.quad),
|
|
24
|
+
useNativeDriver: false
|
|
25
|
+
}),
|
|
26
|
+
Animated.timing(width, {
|
|
27
|
+
toValue: toWidth,
|
|
28
|
+
duration,
|
|
29
|
+
easing: Easing.inOut(Easing.quad),
|
|
30
|
+
useNativeDriver: false
|
|
31
|
+
}),
|
|
32
|
+
Animated.timing(scaleX, {
|
|
33
|
+
toValue: 1,
|
|
34
|
+
duration,
|
|
35
|
+
easing: Easing.out(Easing.quad),
|
|
36
|
+
useNativeDriver: false
|
|
37
|
+
})
|
|
38
|
+
]).start();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/components/tabs/tabs.hook.ts
|
|
42
|
+
import { useMemo } from "react";
|
|
43
|
+
import { getSafeThemeColor, withPaletteNumber } from "@xaui/core";
|
|
44
|
+
function useTabsSizeStyles(size) {
|
|
45
|
+
const theme = useXUITheme();
|
|
46
|
+
return useMemo(() => {
|
|
47
|
+
const sizes = {
|
|
48
|
+
xs: {
|
|
49
|
+
minHeight: 32,
|
|
50
|
+
paddingHorizontal: theme.spacing.sm,
|
|
51
|
+
paddingVertical: theme.spacing.xs,
|
|
52
|
+
fontSize: theme.fontSizes.xs
|
|
53
|
+
},
|
|
54
|
+
sm: {
|
|
55
|
+
minHeight: 36,
|
|
56
|
+
paddingHorizontal: theme.spacing.md,
|
|
57
|
+
paddingVertical: theme.spacing.xs,
|
|
58
|
+
fontSize: theme.fontSizes.sm
|
|
59
|
+
},
|
|
60
|
+
md: {
|
|
61
|
+
minHeight: 42,
|
|
62
|
+
paddingHorizontal: theme.spacing.md,
|
|
63
|
+
paddingVertical: theme.spacing.sm,
|
|
64
|
+
fontSize: theme.fontSizes.md
|
|
65
|
+
},
|
|
66
|
+
lg: {
|
|
67
|
+
minHeight: 50,
|
|
68
|
+
paddingHorizontal: theme.spacing.lg,
|
|
69
|
+
paddingVertical: theme.spacing.md,
|
|
70
|
+
fontSize: theme.fontSizes.lg
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return sizes[size];
|
|
74
|
+
}, [size, theme]);
|
|
75
|
+
}
|
|
76
|
+
function useTabsVariantStyles(color, variant) {
|
|
77
|
+
const theme = useXUITheme();
|
|
78
|
+
const safeColor = getSafeThemeColor(color);
|
|
79
|
+
const palette = theme.colors[safeColor];
|
|
80
|
+
const cursorSolidColor = withPaletteNumber(palette.main, 400);
|
|
81
|
+
return useMemo(() => {
|
|
82
|
+
const variants = {
|
|
83
|
+
solid: {
|
|
84
|
+
listBackgroundColor: palette.background,
|
|
85
|
+
listBorderColor: "transparent",
|
|
86
|
+
listBorderWidth: 0,
|
|
87
|
+
listPaddingHorizontal: 4,
|
|
88
|
+
cursorColor: cursorSolidColor,
|
|
89
|
+
textColor: palette.main,
|
|
90
|
+
selectedTextColor: palette.foreground,
|
|
91
|
+
cursorHeight: void 0,
|
|
92
|
+
cursorTop: 4,
|
|
93
|
+
cursorBottom: 4,
|
|
94
|
+
cursorShadow: true
|
|
95
|
+
},
|
|
96
|
+
bordered: {
|
|
97
|
+
listBackgroundColor: "transparent",
|
|
98
|
+
listBorderColor: `${palette.main}30`,
|
|
99
|
+
listBorderWidth: theme.borderWidth.md,
|
|
100
|
+
listPaddingHorizontal: 0,
|
|
101
|
+
cursorColor: cursorSolidColor,
|
|
102
|
+
textColor: palette.main,
|
|
103
|
+
selectedTextColor: palette.foreground,
|
|
104
|
+
cursorHeight: void 0,
|
|
105
|
+
cursorTop: 0,
|
|
106
|
+
cursorBottom: 0,
|
|
107
|
+
cursorShadow: false
|
|
108
|
+
},
|
|
109
|
+
light: {
|
|
110
|
+
listBackgroundColor: "transparent",
|
|
111
|
+
listBorderColor: "transparent",
|
|
112
|
+
listBorderWidth: 0,
|
|
113
|
+
listPaddingHorizontal: 0,
|
|
114
|
+
cursorColor: `${cursorSolidColor}25`,
|
|
115
|
+
textColor: palette.main,
|
|
116
|
+
selectedTextColor: palette.main,
|
|
117
|
+
cursorHeight: void 0,
|
|
118
|
+
cursorTop: 0,
|
|
119
|
+
cursorBottom: 0,
|
|
120
|
+
cursorShadow: false
|
|
121
|
+
},
|
|
122
|
+
underlined: {
|
|
123
|
+
listBackgroundColor: "transparent",
|
|
124
|
+
listBorderColor: `${palette.main}45`,
|
|
125
|
+
listBorderWidth: 0,
|
|
126
|
+
listPaddingHorizontal: 0,
|
|
127
|
+
cursorColor: cursorSolidColor,
|
|
128
|
+
textColor: `${palette.main}B0`,
|
|
129
|
+
selectedTextColor: palette.main,
|
|
130
|
+
cursorHeight: 2,
|
|
131
|
+
cursorTop: void 0,
|
|
132
|
+
cursorBottom: -2,
|
|
133
|
+
cursorShadow: false
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return variants[variant];
|
|
137
|
+
}, [cursorSolidColor, palette, theme.borderWidth.md, variant]);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/components/tabs/tabs.style.ts
|
|
141
|
+
import { StyleSheet } from "react-native";
|
|
142
|
+
var styles = StyleSheet.create({
|
|
143
|
+
container: {
|
|
144
|
+
width: "100%"
|
|
145
|
+
},
|
|
146
|
+
list: {
|
|
147
|
+
position: "relative",
|
|
148
|
+
flexDirection: "row",
|
|
149
|
+
alignItems: "stretch",
|
|
150
|
+
alignSelf: "flex-start"
|
|
151
|
+
},
|
|
152
|
+
fullWidth: {
|
|
153
|
+
width: "100%",
|
|
154
|
+
alignSelf: "stretch"
|
|
155
|
+
},
|
|
156
|
+
tabPressable: {
|
|
157
|
+
flex: 1,
|
|
158
|
+
zIndex: 1
|
|
159
|
+
},
|
|
160
|
+
tab: {
|
|
161
|
+
minWidth: 64,
|
|
162
|
+
alignItems: "center",
|
|
163
|
+
justifyContent: "center",
|
|
164
|
+
flexDirection: "row",
|
|
165
|
+
gap: 6
|
|
166
|
+
},
|
|
167
|
+
text: {
|
|
168
|
+
textAlign: "center",
|
|
169
|
+
fontWeight: "500"
|
|
170
|
+
},
|
|
171
|
+
cursor: {
|
|
172
|
+
position: "absolute",
|
|
173
|
+
left: 0
|
|
174
|
+
},
|
|
175
|
+
disabled: {
|
|
176
|
+
opacity: 0.5
|
|
177
|
+
},
|
|
178
|
+
content: {
|
|
179
|
+
marginTop: 12
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// src/components/tabs/tabs.tsx
|
|
184
|
+
function isTabDisabled(item, disabledKeys, isDisabled) {
|
|
185
|
+
return isDisabled || item.isDisabled === true || disabledKeys?.includes(item.key) === true;
|
|
186
|
+
}
|
|
187
|
+
function getFallbackKey(items, disabledKeys, isDisabled) {
|
|
188
|
+
if (isDisabled) return "";
|
|
189
|
+
const firstEnabled = items.find((item) => !isTabDisabled(item, disabledKeys, false));
|
|
190
|
+
return firstEnabled?.key ?? "";
|
|
191
|
+
}
|
|
192
|
+
var Tab = () => null;
|
|
193
|
+
Tab.displayName = "Tab";
|
|
194
|
+
function toTabItems(children) {
|
|
195
|
+
return React.Children.toArray(children).flatMap((child) => {
|
|
196
|
+
if (!React.isValidElement(child) || child.type !== Tab) {
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
if (child.key == null) {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
return [
|
|
203
|
+
{
|
|
204
|
+
key: String(child.key),
|
|
205
|
+
title: child.props.title,
|
|
206
|
+
startContent: child.props.startContent,
|
|
207
|
+
endContent: child.props.endContent,
|
|
208
|
+
isDisabled: child.props.isDisabled,
|
|
209
|
+
content: child.props.children
|
|
210
|
+
}
|
|
211
|
+
];
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
var Tabs = ({
|
|
215
|
+
selectedKey: controlledSelectedKey,
|
|
216
|
+
defaultSelectedKey,
|
|
217
|
+
onSelectionChange,
|
|
218
|
+
disabledKeys,
|
|
219
|
+
color = "primary",
|
|
220
|
+
variant = "solid",
|
|
221
|
+
size = "md",
|
|
222
|
+
radius = "full",
|
|
223
|
+
fullWidth = false,
|
|
224
|
+
isDisabled = false,
|
|
225
|
+
disableAnimation = false,
|
|
226
|
+
animationDuration = 220,
|
|
227
|
+
renderTab,
|
|
228
|
+
children,
|
|
229
|
+
content,
|
|
230
|
+
customAppearance
|
|
231
|
+
}) => {
|
|
232
|
+
const items = useMemo2(() => toTabItems(children), [children]);
|
|
233
|
+
const isControlled = controlledSelectedKey !== void 0;
|
|
234
|
+
const initialKey = useMemo2(() => {
|
|
235
|
+
if (defaultSelectedKey) return defaultSelectedKey;
|
|
236
|
+
return getFallbackKey(items, disabledKeys, isDisabled);
|
|
237
|
+
}, [defaultSelectedKey, disabledKeys, isDisabled, items]);
|
|
238
|
+
const [internalSelectedKey, setInternalSelectedKey] = useState(initialKey);
|
|
239
|
+
const [layouts, setLayouts] = useState({});
|
|
240
|
+
const [listWidth, setListWidth] = useState(0);
|
|
241
|
+
const selectedKey = (isControlled ? controlledSelectedKey : internalSelectedKey) ?? "";
|
|
242
|
+
const selectedItem = useMemo2(
|
|
243
|
+
() => items.find((item) => item.key === selectedKey),
|
|
244
|
+
[items, selectedKey]
|
|
245
|
+
);
|
|
246
|
+
const sizeStyles = useTabsSizeStyles(size);
|
|
247
|
+
const variantStyles = useTabsVariantStyles(color, variant);
|
|
248
|
+
const radiusStyles = useBorderRadiusStyles(radius);
|
|
249
|
+
const cursorTranslateX = useRef(new Animated2.Value(0)).current;
|
|
250
|
+
const cursorWidth = useRef(new Animated2.Value(0)).current;
|
|
251
|
+
const cursorScaleX = useRef(new Animated2.Value(1)).current;
|
|
252
|
+
const prevCursorLayout = useRef(null);
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
if (isControlled || selectedKey) return;
|
|
255
|
+
const nextFallback = getFallbackKey(items, disabledKeys, isDisabled);
|
|
256
|
+
if (nextFallback && nextFallback !== selectedKey) {
|
|
257
|
+
setInternalSelectedKey(nextFallback);
|
|
258
|
+
}
|
|
259
|
+
}, [disabledKeys, isControlled, isDisabled, items, selectedKey]);
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
if (!selectedKey) return;
|
|
262
|
+
const selectedLayout = layouts[selectedKey];
|
|
263
|
+
if (!selectedLayout) return;
|
|
264
|
+
const from = prevCursorLayout.current;
|
|
265
|
+
prevCursorLayout.current = selectedLayout;
|
|
266
|
+
if (disableAnimation || !from) {
|
|
267
|
+
cursorTranslateX.setValue(selectedLayout.x);
|
|
268
|
+
cursorWidth.setValue(selectedLayout.width);
|
|
269
|
+
cursorScaleX.setValue(1);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
runTabsCursorAnimation(
|
|
273
|
+
cursorTranslateX,
|
|
274
|
+
cursorWidth,
|
|
275
|
+
cursorScaleX,
|
|
276
|
+
selectedLayout.x,
|
|
277
|
+
selectedLayout.width,
|
|
278
|
+
animationDuration
|
|
279
|
+
);
|
|
280
|
+
}, [
|
|
281
|
+
animationDuration,
|
|
282
|
+
cursorTranslateX,
|
|
283
|
+
cursorWidth,
|
|
284
|
+
cursorScaleX,
|
|
285
|
+
disableAnimation,
|
|
286
|
+
layouts,
|
|
287
|
+
selectedKey
|
|
288
|
+
]);
|
|
289
|
+
const onTabLayout = useCallback(
|
|
290
|
+
(key, event) => {
|
|
291
|
+
const nextLayout = event.nativeEvent.layout;
|
|
292
|
+
setLayouts((prev) => {
|
|
293
|
+
const current = prev[key];
|
|
294
|
+
if (current && current.x === nextLayout.x && current.width === nextLayout.width) {
|
|
295
|
+
return prev;
|
|
296
|
+
}
|
|
297
|
+
const isBordered = variant === "bordered";
|
|
298
|
+
const isFirstTab = items[0]?.key === key;
|
|
299
|
+
let cursorWidth2 = nextLayout.width;
|
|
300
|
+
let cursorX = nextLayout.x;
|
|
301
|
+
if (isBordered) {
|
|
302
|
+
cursorWidth2 = nextLayout.width;
|
|
303
|
+
cursorX = nextLayout.x;
|
|
304
|
+
if (isFirstTab) {
|
|
305
|
+
cursorWidth2 = nextLayout.width + variantStyles.listBorderWidth;
|
|
306
|
+
cursorX = Math.max(0, nextLayout.x - variantStyles.listBorderWidth);
|
|
307
|
+
}
|
|
308
|
+
if (listWidth > 0) {
|
|
309
|
+
const maxWidth = Math.max(0, listWidth - cursorX);
|
|
310
|
+
cursorWidth2 = Math.min(cursorWidth2, maxWidth);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
...prev,
|
|
315
|
+
[key]: { x: cursorX, width: cursorWidth2 }
|
|
316
|
+
};
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
[items, listWidth, setLayouts, variant, variantStyles.listBorderWidth]
|
|
320
|
+
);
|
|
321
|
+
const handleTabPress = useCallback(
|
|
322
|
+
(item) => {
|
|
323
|
+
if (isTabDisabled(item, disabledKeys, isDisabled)) return;
|
|
324
|
+
if (!isControlled) {
|
|
325
|
+
setInternalSelectedKey(item.key);
|
|
326
|
+
}
|
|
327
|
+
onSelectionChange?.(item.key);
|
|
328
|
+
},
|
|
329
|
+
[disabledKeys, isControlled, isDisabled, onSelectionChange]
|
|
330
|
+
);
|
|
331
|
+
const shouldShowCursor = !!selectedKey && !!layouts[selectedKey] && !isDisabled && items.length > 0;
|
|
332
|
+
const resolvedContent = typeof content === "function" ? content({ selectedKey, selectedItem }) : content ?? selectedItem?.content;
|
|
333
|
+
return /* @__PURE__ */ React.createElement(View, { style: [styles.container, customAppearance?.container] }, /* @__PURE__ */ React.createElement(
|
|
334
|
+
View,
|
|
335
|
+
{
|
|
336
|
+
onLayout: (event) => setListWidth(event.nativeEvent.layout.width),
|
|
337
|
+
style: [
|
|
338
|
+
styles.list,
|
|
339
|
+
{
|
|
340
|
+
borderRadius: variant === "underlined" ? 0 : radiusStyles.borderRadius,
|
|
341
|
+
backgroundColor: variantStyles.listBackgroundColor,
|
|
342
|
+
borderColor: variantStyles.listBorderColor,
|
|
343
|
+
borderWidth: variantStyles.listBorderWidth,
|
|
344
|
+
borderBottomWidth: variant === "underlined" ? variantStyles.cursorHeight ?? 2 : variantStyles.listBorderWidth,
|
|
345
|
+
paddingHorizontal: variantStyles.listPaddingHorizontal,
|
|
346
|
+
...variant === "bordered" && { overflow: "hidden" }
|
|
347
|
+
},
|
|
348
|
+
fullWidth && styles.fullWidth,
|
|
349
|
+
customAppearance?.list
|
|
350
|
+
]
|
|
351
|
+
},
|
|
352
|
+
shouldShowCursor && /* @__PURE__ */ React.createElement(
|
|
353
|
+
Animated2.View,
|
|
354
|
+
{
|
|
355
|
+
pointerEvents: "none",
|
|
356
|
+
style: [
|
|
357
|
+
styles.cursor,
|
|
358
|
+
{
|
|
359
|
+
bottom: variantStyles.cursorBottom,
|
|
360
|
+
borderRadius: variant === "underlined" ? 0 : Math.max(
|
|
361
|
+
0,
|
|
362
|
+
radiusStyles.borderRadius - variantStyles.listBorderWidth
|
|
363
|
+
),
|
|
364
|
+
width: cursorWidth,
|
|
365
|
+
backgroundColor: variantStyles.cursorColor,
|
|
366
|
+
transform: [
|
|
367
|
+
{ translateX: cursorTranslateX },
|
|
368
|
+
{ scaleX: cursorScaleX }
|
|
369
|
+
],
|
|
370
|
+
...variantStyles.cursorTop !== void 0 && {
|
|
371
|
+
top: variantStyles.cursorTop
|
|
372
|
+
},
|
|
373
|
+
...variantStyles.cursorHeight !== void 0 && {
|
|
374
|
+
height: variantStyles.cursorHeight
|
|
375
|
+
},
|
|
376
|
+
...variantStyles.cursorShadow && {
|
|
377
|
+
shadowColor: "#000",
|
|
378
|
+
shadowOffset: { width: 0, height: 1 },
|
|
379
|
+
shadowOpacity: 0.15,
|
|
380
|
+
shadowRadius: 3,
|
|
381
|
+
elevation: 2
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
customAppearance?.cursor
|
|
385
|
+
]
|
|
386
|
+
}
|
|
387
|
+
),
|
|
388
|
+
items.map((item) => {
|
|
389
|
+
const isSelected = selectedKey === item.key;
|
|
390
|
+
const disabled = isTabDisabled(item, disabledKeys, isDisabled);
|
|
391
|
+
return /* @__PURE__ */ React.createElement(
|
|
392
|
+
Pressable,
|
|
393
|
+
{
|
|
394
|
+
key: item.key,
|
|
395
|
+
onLayout: (event) => onTabLayout(item.key, event),
|
|
396
|
+
onPress: () => handleTabPress(item),
|
|
397
|
+
disabled,
|
|
398
|
+
style: [styles.tabPressable, disabled && styles.disabled]
|
|
399
|
+
},
|
|
400
|
+
/* @__PURE__ */ React.createElement(
|
|
401
|
+
View,
|
|
402
|
+
{
|
|
403
|
+
style: [
|
|
404
|
+
styles.tab,
|
|
405
|
+
{
|
|
406
|
+
minHeight: sizeStyles.minHeight,
|
|
407
|
+
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
408
|
+
paddingVertical: sizeStyles.paddingVertical
|
|
409
|
+
},
|
|
410
|
+
customAppearance?.tab,
|
|
411
|
+
isSelected && customAppearance?.selectedTab
|
|
412
|
+
]
|
|
413
|
+
},
|
|
414
|
+
renderTab ? renderTab(item, { isSelected, isDisabled: disabled }) : /* @__PURE__ */ React.createElement(React.Fragment, null, item.startContent, /* @__PURE__ */ React.createElement(
|
|
415
|
+
Text,
|
|
416
|
+
{
|
|
417
|
+
numberOfLines: 1,
|
|
418
|
+
style: [
|
|
419
|
+
styles.text,
|
|
420
|
+
{
|
|
421
|
+
color: isSelected ? variantStyles.selectedTextColor : variantStyles.textColor,
|
|
422
|
+
fontSize: sizeStyles.fontSize
|
|
423
|
+
},
|
|
424
|
+
customAppearance?.text,
|
|
425
|
+
isSelected && customAppearance?.selectedText
|
|
426
|
+
]
|
|
427
|
+
},
|
|
428
|
+
item.title
|
|
429
|
+
), item.endContent)
|
|
430
|
+
)
|
|
431
|
+
);
|
|
432
|
+
})
|
|
433
|
+
), resolvedContent !== void 0 && /* @__PURE__ */ React.createElement(View, { style: [styles.content, customAppearance?.content] }, resolvedContent));
|
|
434
|
+
};
|
|
435
|
+
export {
|
|
436
|
+
Tab,
|
|
437
|
+
Tabs
|
|
438
|
+
};
|