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