@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,878 +0,0 @@
1
- import {
2
- CheckmarkIcon
3
- } from "../chunk-GBHQCAKW.js";
4
- import "../chunk-SHBDANQN.js";
5
- import {
6
- useXUITheme
7
- } from "../chunk-RBSA4NH4.js";
8
-
9
- // src/components/select/select.tsx
10
- import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
11
- import {
12
- Animated as Animated3,
13
- Modal,
14
- Pressable as Pressable2,
15
- ScrollView,
16
- Text as Text2,
17
- View as View2,
18
- useWindowDimensions
19
- } from "react-native";
20
-
21
- // src/components/select/select-context.ts
22
- import { createContext } from "react";
23
- var SelectContext = createContext(null);
24
-
25
- // src/components/select/select.hook.ts
26
- import { useMemo } from "react";
27
- import { getSafeThemeColor, withOpacity } from "@xaui/core";
28
- import { colors } from "@xaui/core/palette";
29
- var useSelectColorScheme = (themeColor) => {
30
- const theme = useXUITheme();
31
- const safeThemeColor = getSafeThemeColor(themeColor);
32
- const colorScheme = theme.colors[safeThemeColor];
33
- return { theme, colorScheme };
34
- };
35
- var useSelectSizeStyles = (size) => {
36
- const theme = useXUITheme();
37
- return useMemo(() => {
38
- const sizes = {
39
- xs: {
40
- minHeight: theme.componentSizes.xs,
41
- paddingHorizontal: theme.spacing.sm,
42
- paddingVertical: theme.spacing.xs,
43
- fontSize: theme.fontSizes.xs,
44
- labelSize: theme.fontSizes.xs
45
- },
46
- sm: {
47
- minHeight: theme.componentSizes.sm,
48
- paddingHorizontal: theme.spacing.md,
49
- paddingVertical: theme.spacing.xs,
50
- fontSize: theme.fontSizes.sm,
51
- labelSize: theme.fontSizes.xs
52
- },
53
- md: {
54
- minHeight: theme.componentSizes.md,
55
- paddingHorizontal: theme.spacing.md,
56
- paddingVertical: theme.spacing.sm,
57
- fontSize: theme.fontSizes.md,
58
- labelSize: theme.fontSizes.sm
59
- },
60
- lg: {
61
- minHeight: theme.componentSizes.lg,
62
- paddingHorizontal: theme.spacing.lg,
63
- paddingVertical: theme.spacing.md,
64
- fontSize: theme.fontSizes.lg,
65
- labelSize: theme.fontSizes.md
66
- }
67
- };
68
- return sizes[size];
69
- }, [size, theme]);
70
- };
71
- var useSelectRadiusStyles = (radius) => {
72
- const theme = useXUITheme();
73
- const radiusStyles = useMemo(() => {
74
- const radii = {
75
- none: theme.borderRadius.none,
76
- sm: theme.borderRadius.sm,
77
- md: theme.borderRadius.md,
78
- lg: theme.borderRadius.lg,
79
- full: theme.borderRadius.full
80
- };
81
- return { borderRadius: radii[radius] };
82
- }, [radius, theme]);
83
- const listboxRadius = useMemo(() => {
84
- const radii = {
85
- none: theme.borderRadius.none,
86
- sm: theme.borderRadius.sm,
87
- md: theme.borderRadius.md,
88
- lg: theme.borderRadius.lg,
89
- full: theme.borderRadius.full
90
- };
91
- return Math.min(radii[radius], theme.borderRadius.lg);
92
- }, [radius, theme]);
93
- return { radiusStyles, listboxRadius };
94
- };
95
- var useSelectVariantStyles = (themeColor, variant, isInvalid) => {
96
- const { theme, colorScheme } = useSelectColorScheme(themeColor);
97
- return useMemo(() => {
98
- let borderColor = isInvalid ? theme.colors.danger.main : colorScheme.main;
99
- if (variant === "bordered" && themeColor === "default") {
100
- borderColor = colors.gray[300];
101
- }
102
- const styles3 = {
103
- bordered: {
104
- backgroundColor: "transparent",
105
- borderWidth: theme.borderWidth.md,
106
- borderColor
107
- },
108
- colored: {
109
- backgroundColor: withOpacity(colorScheme.container, 0.5),
110
- borderWidth: 0
111
- },
112
- light: {
113
- backgroundColor: "transparent",
114
- borderWidth: 0
115
- },
116
- underlined: {
117
- backgroundColor: "transparent",
118
- borderBottomWidth: theme.borderWidth.md,
119
- borderColor
120
- }
121
- };
122
- return styles3[variant];
123
- }, [variant, theme, colorScheme, isInvalid, themeColor]);
124
- };
125
- var useSelectLabelStyle = (themeColor, isInvalid, labelSize) => {
126
- const { theme, colorScheme } = useSelectColorScheme(themeColor);
127
- return useMemo(() => {
128
- let baseColor = theme.colors.foreground;
129
- if (isInvalid) {
130
- baseColor = theme.colors.danger.main;
131
- } else if (themeColor !== "default") {
132
- baseColor = colorScheme.main;
133
- }
134
- return {
135
- fontSize: labelSize,
136
- color: baseColor
137
- };
138
- }, [isInvalid, labelSize, theme, themeColor, colorScheme]);
139
- };
140
- var useSelectValueColor = (isInvalid, shouldShowPlaceholder) => {
141
- const theme = useXUITheme();
142
- return useMemo(() => {
143
- if (isInvalid) {
144
- return theme.colors.danger.main;
145
- }
146
- if (shouldShowPlaceholder) {
147
- return colors.gray[500];
148
- }
149
- return theme.colors.foreground;
150
- }, [isInvalid, shouldShowPlaceholder, theme]);
151
- };
152
- var useSelectHelperColor = (isInvalid) => {
153
- const theme = useXUITheme();
154
- return useMemo(() => {
155
- if (isInvalid) {
156
- return theme.colors.danger.main;
157
- }
158
- return colors.gray[600];
159
- }, [isInvalid, theme]);
160
- };
161
- var useSelectSelectorColor = (isInvalid, shouldShowPlaceholder) => {
162
- const theme = useXUITheme();
163
- return useMemo(() => {
164
- if (isInvalid) {
165
- return theme.colors.danger.main;
166
- }
167
- if (shouldShowPlaceholder) {
168
- return colors.gray[600];
169
- }
170
- return theme.colors.foreground;
171
- }, [isInvalid, shouldShowPlaceholder, theme]);
172
- };
173
-
174
- // src/components/select/select.style.ts
175
- import { StyleSheet } from "react-native";
176
- var styles = StyleSheet.create({
177
- container: {
178
- gap: 6
179
- },
180
- fullWidth: {
181
- flexShrink: 1,
182
- flexBasis: "auto",
183
- width: "100%"
184
- },
185
- minWidth: {
186
- minWidth: 170
187
- },
188
- label: {
189
- fontWeight: "500"
190
- },
191
- trigger: {
192
- flexDirection: "row",
193
- alignItems: "center",
194
- justifyContent: "space-between",
195
- gap: 8
196
- },
197
- triggerContent: {
198
- flexDirection: "row",
199
- alignItems: "center",
200
- flex: 1,
201
- gap: 8
202
- },
203
- triggerContentColumn: {
204
- flexDirection: "column",
205
- alignItems: "flex-start"
206
- },
207
- valueWrapper: {
208
- flex: 1,
209
- gap: 2
210
- },
211
- valueText: {
212
- flexShrink: 1
213
- },
214
- endSlot: {
215
- flexDirection: "row",
216
- alignItems: "center",
217
- gap: 8
218
- },
219
- clearButton: {
220
- paddingHorizontal: 4,
221
- paddingVertical: 2
222
- },
223
- clearText: {
224
- fontSize: 12
225
- },
226
- helperText: {
227
- fontSize: 12
228
- },
229
- disabled: {
230
- opacity: 0.5
231
- },
232
- overlay: {
233
- flex: 1,
234
- backgroundColor: "rgba(0, 0, 0, 0.70)",
235
- justifyContent: "center",
236
- alignItems: "center"
237
- },
238
- listbox: {
239
- overflow: "hidden"
240
- },
241
- listboxContent: {
242
- minWidth: "100%"
243
- },
244
- dialogTitle: {
245
- fontWeight: "600",
246
- paddingHorizontal: 16,
247
- paddingVertical: 12
248
- },
249
- outsideLeftRow: {
250
- flexDirection: "row",
251
- alignItems: "center",
252
- gap: 12
253
- }
254
- });
255
-
256
- // src/components/select/select-trigger.tsx
257
- import React2 from "react";
258
- import {
259
- Pressable,
260
- Text,
261
- View
262
- } from "react-native";
263
-
264
- // src/components/select/chevron-down-icon.tsx
265
- import React, { useEffect, useRef } from "react";
266
- import { Animated } from "react-native";
267
- import Svg, { Path } from "react-native-svg";
268
- function ChevronDownIcon({
269
- color,
270
- size,
271
- isOpen = false
272
- }) {
273
- const rotation = useRef(new Animated.Value(isOpen ? 1 : 0)).current;
274
- useEffect(() => {
275
- Animated.timing(rotation, {
276
- toValue: isOpen ? 1 : 0,
277
- duration: 180,
278
- useNativeDriver: true
279
- }).start();
280
- }, [isOpen, rotation]);
281
- const rotate = rotation.interpolate({
282
- inputRange: [0, 1],
283
- outputRange: ["0deg", "180deg"]
284
- });
285
- return /* @__PURE__ */ React.createElement(Animated.View, { style: { transform: [{ rotate }] } }, /* @__PURE__ */ React.createElement(Svg, { width: size, height: size, viewBox: "0 0 24 24", fill: "none" }, /* @__PURE__ */ React.createElement(
286
- Path,
287
- {
288
- d: "M6 9L12 15L18 9",
289
- stroke: color,
290
- strokeWidth: 2,
291
- strokeLinecap: "round",
292
- strokeLinejoin: "round"
293
- }
294
- )));
295
- }
296
-
297
- // src/components/select/select-trigger.tsx
298
- var SelectTrigger = ({
299
- triggerRef,
300
- isOpen,
301
- isDisabled,
302
- onPress,
303
- onLayout,
304
- accessibilityLabel,
305
- variant,
306
- sizeStyles,
307
- radiusStyles,
308
- variantStyles,
309
- displayValue,
310
- valueColor,
311
- selectorColor,
312
- labelInside,
313
- labelNode,
314
- startContent,
315
- endContent,
316
- selectorIcon,
317
- onClear,
318
- showClear,
319
- textStyle,
320
- style
321
- }) => {
322
- const renderSelectorIcon = selectorIcon ?? /* @__PURE__ */ React2.createElement(ChevronDownIcon, { color: selectorColor, size: 16, isOpen });
323
- return /* @__PURE__ */ React2.createElement(View, { ref: triggerRef, collapsable: false }, /* @__PURE__ */ React2.createElement(
324
- Pressable,
325
- {
326
- onPress,
327
- disabled: isDisabled,
328
- onLayout,
329
- accessibilityRole: "button",
330
- accessibilityLabel,
331
- accessibilityState: { disabled: isDisabled, expanded: isOpen },
332
- style: [
333
- styles.trigger,
334
- variant === "underlined" ? { borderRadius: 0 } : radiusStyles,
335
- variantStyles,
336
- {
337
- minHeight: sizeStyles.minHeight,
338
- paddingHorizontal: variant === "underlined" ? 2 : sizeStyles.paddingHorizontal,
339
- paddingVertical: sizeStyles.paddingVertical
340
- },
341
- isDisabled && styles.disabled,
342
- style
343
- ]
344
- },
345
- /* @__PURE__ */ React2.createElement(
346
- View,
347
- {
348
- style: [styles.triggerContent, labelInside && styles.triggerContentColumn]
349
- },
350
- startContent,
351
- /* @__PURE__ */ React2.createElement(View, { style: styles.valueWrapper }, labelInside && labelNode, /* @__PURE__ */ React2.createElement(
352
- Text,
353
- {
354
- style: [
355
- styles.valueText,
356
- { fontSize: sizeStyles.fontSize, color: valueColor },
357
- textStyle
358
- ]
359
- },
360
- displayValue
361
- )),
362
- endContent
363
- ),
364
- /* @__PURE__ */ React2.createElement(View, { style: styles.endSlot }, showClear && onClear && /* @__PURE__ */ React2.createElement(Pressable, { onPress: onClear, style: styles.clearButton }, /* @__PURE__ */ React2.createElement(Text, { style: [styles.clearText, { color: selectorColor }] }, "x")), renderSelectorIcon)
365
- ));
366
- };
367
-
368
- // src/components/select/select.animation.ts
369
- import { useEffect as useEffect2, useRef as useRef2 } from "react";
370
- import { Animated as Animated2 } from "react-native";
371
- var useSelectListboxAnimation = (isOpen) => {
372
- const animationOpacity = useRef2(new Animated2.Value(0)).current;
373
- const animationScale = useRef2(new Animated2.Value(0.98)).current;
374
- useEffect2(() => {
375
- if (!isOpen) {
376
- return;
377
- }
378
- animationOpacity.setValue(0);
379
- animationScale.setValue(0.98);
380
- Animated2.parallel([
381
- Animated2.timing(animationOpacity, {
382
- toValue: 1,
383
- duration: 180,
384
- useNativeDriver: true
385
- }),
386
- Animated2.timing(animationScale, {
387
- toValue: 1,
388
- duration: 180,
389
- useNativeDriver: true
390
- })
391
- ]).start();
392
- }, [isOpen, animationOpacity, animationScale]);
393
- return { animationOpacity, animationScale };
394
- };
395
-
396
- // src/components/select/select.state.hook.ts
397
- import { useCallback, useEffect as useEffect3, useRef as useRef3, useState } from "react";
398
- var useSelectOpenState = ({
399
- isOpened,
400
- isDisabled,
401
- onOpenChange,
402
- onClose
403
- }) => {
404
- const [internalOpen, setInternalOpen] = useState(false);
405
- const isOpen = isOpened ?? internalOpen;
406
- const setOpen = useCallback(
407
- (nextOpen) => {
408
- if (nextOpen && isDisabled) {
409
- return;
410
- }
411
- if (isOpened === void 0) {
412
- setInternalOpen(nextOpen);
413
- }
414
- onOpenChange?.(nextOpen);
415
- if (!nextOpen) {
416
- onClose?.();
417
- }
418
- },
419
- [isDisabled, isOpened, onOpenChange, onClose]
420
- );
421
- return { isOpen, setOpen };
422
- };
423
- var useSelectSelection = ({
424
- selectionMode,
425
- selectedKeys,
426
- defaultSelectedKeys,
427
- onSelectionChange,
428
- onClear
429
- }) => {
430
- const [internalSelectedKeys, setInternalSelectedKeys] = useState(
431
- defaultSelectedKeys ?? []
432
- );
433
- const isControlledSelection = selectedKeys !== void 0;
434
- const currentSelectedKeys = isControlledSelection ? selectedKeys ?? [] : internalSelectedKeys;
435
- const updateSelection = useCallback(
436
- (nextKeys) => {
437
- if (!isControlledSelection) {
438
- setInternalSelectedKeys(nextKeys);
439
- }
440
- onSelectionChange?.(nextKeys);
441
- if (nextKeys.length === 0) {
442
- onClear?.();
443
- }
444
- },
445
- [isControlledSelection, onSelectionChange, onClear]
446
- );
447
- const getNextSelection = useCallback(
448
- (key) => {
449
- const isAlreadySelected = currentSelectedKeys.includes(key);
450
- if (selectionMode === "multiple") {
451
- return isAlreadySelected ? currentSelectedKeys.filter((existingKey) => existingKey !== key) : [...currentSelectedKeys, key];
452
- }
453
- if (!isAlreadySelected) {
454
- return [key];
455
- }
456
- return currentSelectedKeys;
457
- },
458
- [currentSelectedKeys, selectionMode]
459
- );
460
- return { currentSelectedKeys, updateSelection, getNextSelection };
461
- };
462
- var useSelectTriggerMeasurements = (isOpen) => {
463
- const triggerRef = useRef3(null);
464
- const [triggerWidth, setTriggerWidth] = useState(null);
465
- const [triggerPosition, setTriggerPosition] = useState(
466
- null
467
- );
468
- const handleTriggerLayout = useCallback((event) => {
469
- setTriggerWidth(event.nativeEvent.layout.width);
470
- }, []);
471
- useEffect3(() => {
472
- if (!isOpen) {
473
- return;
474
- }
475
- const measureTrigger = () => {
476
- triggerRef.current?.measureInWindow((x, y, width, height) => {
477
- setTriggerPosition({ x, y, width, height });
478
- });
479
- };
480
- const frameId = globalThis.setTimeout(measureTrigger, 0);
481
- return () => globalThis.clearTimeout(frameId);
482
- }, [isOpen]);
483
- return { triggerRef, triggerWidth, triggerPosition, handleTriggerLayout };
484
- };
485
-
486
- // src/components/select/select.utils.ts
487
- var getTextValue = (value) => {
488
- if (typeof value === "string") return value;
489
- if (typeof value === "number") return String(value);
490
- return void 0;
491
- };
492
-
493
- // src/components/select/select.tsx
494
- var defaultPlaceholder = "Select an option";
495
- var Select = ({
496
- children,
497
- selectionMode = "single",
498
- selectedKeys,
499
- disabledKeys,
500
- defaultSelectedKeys,
501
- variant = "colored",
502
- themeColor = "default",
503
- size = "md",
504
- radius = "md",
505
- placeholder = defaultPlaceholder,
506
- labelPlacement = "outside",
507
- label,
508
- hint,
509
- errorMessage,
510
- startContent,
511
- endContent,
512
- selectorIcon,
513
- maxListboxHeight = 280,
514
- fullWidth = false,
515
- isOpened,
516
- isDisabled = false,
517
- isInvalid = false,
518
- style,
519
- textStyle,
520
- onClose,
521
- onOpenChange,
522
- onSelectionChange,
523
- onClear
524
- }) => {
525
- const { isOpen, setOpen } = useSelectOpenState({
526
- isOpened,
527
- isDisabled,
528
- onOpenChange,
529
- onClose
530
- });
531
- const { currentSelectedKeys, updateSelection, getNextSelection } = useSelectSelection({
532
- selectionMode,
533
- selectedKeys,
534
- defaultSelectedKeys,
535
- onSelectionChange,
536
- onClear
537
- });
538
- const { triggerRef, handleTriggerLayout } = useSelectTriggerMeasurements(isOpen);
539
- const { animationOpacity, animationScale } = useSelectListboxAnimation(isOpen);
540
- const { width: screenWidth, height: screenHeight } = useWindowDimensions();
541
- const disabledKeySet = useMemo2(() => {
542
- return new Set(disabledKeys ?? []);
543
- }, [disabledKeys]);
544
- const items = useMemo2(() => {
545
- const elements = React3.Children.toArray(children).filter(Boolean);
546
- return elements.map((child, index) => {
547
- if (!React3.isValidElement(child)) {
548
- return null;
549
- }
550
- const key = child.props.value ?? String(index);
551
- const labelText = getTextValue(child.props.label) ?? key;
552
- return {
553
- key,
554
- element: child,
555
- labelText
556
- };
557
- }).filter((item) => item !== null);
558
- }, [children]);
559
- const selectedLabels = useMemo2(() => {
560
- const labelMap = new Map(items.map((item) => [item.key, item.labelText]));
561
- return currentSelectedKeys.map((key) => labelMap.get(key)).filter((value) => Boolean(value));
562
- }, [currentSelectedKeys, items]);
563
- const displayValue = selectedLabels.length ? selectedLabels.join(", ") : placeholder;
564
- const shouldShowPlaceholder = selectedLabels.length === 0;
565
- const theme = useXUITheme();
566
- const sizeStyles = useSelectSizeStyles(size);
567
- const { radiusStyles, listboxRadius } = useSelectRadiusStyles(radius);
568
- const variantStyles = useSelectVariantStyles(themeColor, variant, isInvalid);
569
- const labelStyle = useSelectLabelStyle(themeColor, isInvalid, sizeStyles.labelSize);
570
- const valueColor = useSelectValueColor(isInvalid, shouldShowPlaceholder);
571
- const helperColor = useSelectHelperColor(isInvalid);
572
- const selectorColor = useSelectSelectorColor(isInvalid, shouldShowPlaceholder);
573
- const handleItemSelection = useCallback2(
574
- (key) => {
575
- if (isDisabled) {
576
- return;
577
- }
578
- const nextKeys = getNextSelection(key);
579
- if (nextKeys !== currentSelectedKeys) {
580
- updateSelection(nextKeys);
581
- }
582
- if (selectionMode === "single") {
583
- setOpen(false);
584
- }
585
- },
586
- [
587
- currentSelectedKeys,
588
- isDisabled,
589
- selectionMode,
590
- setOpen,
591
- updateSelection,
592
- getNextSelection
593
- ]
594
- );
595
- const handleClear = () => {
596
- if (isDisabled || currentSelectedKeys.length === 0) {
597
- return;
598
- }
599
- updateSelection([]);
600
- };
601
- const handleOverlayPress = () => {
602
- setOpen(false);
603
- };
604
- const renderLabel = label ? typeof label === "string" || typeof label === "number" ? /* @__PURE__ */ React3.createElement(Text2, { style: [styles.label, labelStyle] }, label) : /* @__PURE__ */ React3.createElement(View2, null, label) : null;
605
- const dialogTitle = typeof label === "string" || typeof label === "number" ? String(label) : void 0;
606
- const shouldShowHelper = Boolean(hint || errorMessage);
607
- const helperContent = isInvalid && errorMessage ? errorMessage : hint;
608
- const dialogWidth = screenWidth * 0.9;
609
- const dialogMaxHeight = Math.min(screenHeight * 0.6, maxListboxHeight);
610
- const listItems = items.map((item) => {
611
- const itemProps = item.element.props;
612
- const itemDisabled = isDisabled || itemProps.isDisabled || disabledKeySet.has(item.key);
613
- const itemSelected = itemProps.isSelected ?? currentSelectedKeys.includes(item.key);
614
- const handleItemSelected = () => {
615
- if (itemDisabled || itemProps.isReadOnly) {
616
- return;
617
- }
618
- handleItemSelection(item.key);
619
- itemProps.onSelected?.();
620
- };
621
- return React3.cloneElement(item.element, {
622
- key: item.key,
623
- isDisabled: itemDisabled,
624
- isSelected: itemSelected,
625
- onSelected: handleItemSelected
626
- });
627
- });
628
- const isLabelInside = labelPlacement === "inside";
629
- const isLabelOutsideLeft = labelPlacement === "outside-left";
630
- const isLabelOutside = labelPlacement === "outside" || labelPlacement === "outside-top";
631
- const triggerContent = /* @__PURE__ */ React3.createElement(
632
- SelectTrigger,
633
- {
634
- triggerRef,
635
- isOpen,
636
- isDisabled,
637
- onPress: () => setOpen(!isOpen),
638
- onLayout: handleTriggerLayout,
639
- accessibilityLabel: typeof label === "string" ? label : void 0,
640
- variant,
641
- sizeStyles,
642
- radiusStyles,
643
- variantStyles,
644
- displayValue,
645
- valueColor,
646
- selectorColor,
647
- labelInside: isLabelInside,
648
- labelNode: renderLabel,
649
- startContent,
650
- endContent,
651
- selectorIcon,
652
- onClear: handleClear,
653
- showClear: Boolean(onClear && currentSelectedKeys.length > 0),
654
- textStyle,
655
- style
656
- }
657
- );
658
- const labelBlock = isLabelOutside || isLabelInside ? renderLabel : null;
659
- return /* @__PURE__ */ React3.createElement(View2, { style: [styles.container, fullWidth ? styles.fullWidth : styles.minWidth] }, isLabelOutside && labelBlock, isLabelOutsideLeft ? /* @__PURE__ */ React3.createElement(View2, { style: styles.outsideLeftRow }, renderLabel, triggerContent) : triggerContent, shouldShowHelper && helperContent ? typeof helperContent === "string" || typeof helperContent === "number" ? /* @__PURE__ */ React3.createElement(Text2, { style: [styles.helperText, { color: helperColor }] }, helperContent) : /* @__PURE__ */ React3.createElement(View2, null, helperContent) : null, /* @__PURE__ */ React3.createElement(
660
- Modal,
661
- {
662
- visible: isOpen,
663
- transparent: true,
664
- animationType: "fade",
665
- onRequestClose: handleOverlayPress
666
- },
667
- /* @__PURE__ */ React3.createElement(Pressable2, { style: styles.overlay, onPress: handleOverlayPress }, /* @__PURE__ */ React3.createElement(
668
- Animated3.View,
669
- {
670
- style: [
671
- styles.listbox,
672
- {
673
- width: dialogWidth,
674
- maxHeight: dialogMaxHeight,
675
- borderRadius: listboxRadius,
676
- backgroundColor: theme.colors.background,
677
- opacity: animationOpacity,
678
- transform: [{ scale: animationScale }],
679
- ...theme.shadows.md
680
- }
681
- ]
682
- },
683
- /* @__PURE__ */ React3.createElement(
684
- Pressable2,
685
- {
686
- onPress: (event) => event.stopPropagation(),
687
- style: { maxHeight: dialogMaxHeight }
688
- },
689
- /* @__PURE__ */ React3.createElement(SelectContext.Provider, { value: { size, themeColor, isDisabled } }, /* @__PURE__ */ React3.createElement(
690
- View2,
691
- {
692
- style: [styles.listboxContent, { maxHeight: dialogMaxHeight }]
693
- },
694
- dialogTitle ? /* @__PURE__ */ React3.createElement(
695
- Text2,
696
- {
697
- style: [
698
- styles.dialogTitle,
699
- { color: theme.colors.foreground }
700
- ]
701
- },
702
- dialogTitle
703
- ) : null,
704
- /* @__PURE__ */ React3.createElement(ScrollView, { style: { maxHeight: dialogMaxHeight } }, listItems)
705
- ))
706
- )
707
- ))
708
- ));
709
- };
710
-
711
- // src/components/select/select-item.tsx
712
- import React4, { useContext } from "react";
713
- import { Pressable as Pressable3, Text as Text3, View as View3 } from "react-native";
714
-
715
- // src/components/select/select-item.hook.ts
716
- import { useMemo as useMemo3 } from "react";
717
- import { getSafeThemeColor as getSafeThemeColor2 } from "@xaui/core";
718
- var useSelectItemSizeStyles = (size) => {
719
- const theme = useXUITheme();
720
- return useMemo3(() => {
721
- const sizes = {
722
- xs: {
723
- paddingVertical: theme.spacing.sm,
724
- paddingHorizontal: theme.spacing.xs,
725
- titleSize: theme.fontSizes.xs,
726
- descriptionSize: theme.fontSizes.xs
727
- },
728
- sm: {
729
- paddingVertical: theme.spacing.sm,
730
- paddingHorizontal: theme.spacing.md,
731
- titleSize: theme.fontSizes.sm,
732
- descriptionSize: theme.fontSizes.xs
733
- },
734
- md: {
735
- paddingVertical: theme.spacing.md,
736
- paddingHorizontal: theme.spacing.md,
737
- titleSize: theme.fontSizes.md,
738
- descriptionSize: theme.fontSizes.xs
739
- },
740
- lg: {
741
- paddingVertical: theme.spacing.lg,
742
- paddingHorizontal: theme.spacing.lg,
743
- titleSize: theme.fontSizes.lg,
744
- descriptionSize: theme.fontSizes.md
745
- }
746
- };
747
- return sizes[size];
748
- }, [size, theme]);
749
- };
750
- var useSelectItemBackgroundColor = (themeColor, isSelected) => {
751
- const theme = useXUITheme();
752
- const safeThemeColor = getSafeThemeColor2(themeColor);
753
- const colorScheme = theme.colors[safeThemeColor];
754
- return useMemo3(() => {
755
- if (isSelected) {
756
- return colorScheme.container;
757
- }
758
- return "transparent";
759
- }, [isSelected, colorScheme]);
760
- };
761
- var useSelectItemTextColors = () => {
762
- const theme = useXUITheme();
763
- return useMemo3(() => {
764
- return {
765
- textColor: theme.colors.foreground,
766
- descriptionColor: theme.colors.foreground
767
- };
768
- }, [theme]);
769
- };
770
- var useSelectItemCheckmarkColor = (themeColor) => {
771
- const theme = useXUITheme();
772
- const safeThemeColor = getSafeThemeColor2(themeColor);
773
- const colorScheme = theme.colors[safeThemeColor];
774
- return useMemo3(() => {
775
- if (themeColor === "default") {
776
- return theme.colors.primary.main;
777
- }
778
- return colorScheme.main;
779
- }, [themeColor, colorScheme, theme]);
780
- };
781
-
782
- // src/components/select/select-item.style.ts
783
- import { StyleSheet as StyleSheet2 } from "react-native";
784
- var styles2 = StyleSheet2.create({
785
- item: {
786
- flexDirection: "row",
787
- alignItems: "center",
788
- gap: 8
789
- },
790
- content: {
791
- flex: 1,
792
- gap: 2
793
- },
794
- title: {
795
- fontWeight: "500"
796
- },
797
- description: {
798
- opacity: 0.7
799
- },
800
- disabled: {
801
- opacity: 0.5
802
- }
803
- });
804
-
805
- // src/components/select/select-item.tsx
806
- var defaultSize = "md";
807
- var SelectItem = ({
808
- label,
809
- description,
810
- startContent,
811
- endContent,
812
- selectedIcon,
813
- isDisabled = false,
814
- isSelected = false,
815
- isReadOnly = false,
816
- style,
817
- textStyle,
818
- onSelected
819
- }) => {
820
- const context = useContext(SelectContext);
821
- const size = context?.size ?? defaultSize;
822
- const themeColor = context?.themeColor ?? "default";
823
- const isItemDisabled = context?.isDisabled ? true : isDisabled;
824
- const sizeStyles = useSelectItemSizeStyles(size);
825
- const backgroundColor = useSelectItemBackgroundColor(themeColor, isSelected);
826
- const { textColor, descriptionColor } = useSelectItemTextColors();
827
- const checkmarkColor = useSelectItemCheckmarkColor(themeColor);
828
- const handlePress = () => {
829
- if (isItemDisabled || isReadOnly) {
830
- return;
831
- }
832
- onSelected?.();
833
- };
834
- return /* @__PURE__ */ React4.createElement(
835
- Pressable3,
836
- {
837
- onPress: handlePress,
838
- disabled: isItemDisabled,
839
- style: [
840
- styles2.item,
841
- {
842
- paddingVertical: sizeStyles.paddingVertical,
843
- paddingHorizontal: sizeStyles.paddingHorizontal,
844
- backgroundColor
845
- },
846
- isItemDisabled && styles2.disabled,
847
- style
848
- ]
849
- },
850
- startContent,
851
- /* @__PURE__ */ React4.createElement(View3, { style: styles2.content }, /* @__PURE__ */ React4.createElement(
852
- Text3,
853
- {
854
- style: [
855
- styles2.title,
856
- { fontSize: sizeStyles.titleSize, color: textColor },
857
- textStyle
858
- ]
859
- },
860
- label
861
- ), description && /* @__PURE__ */ React4.createElement(
862
- Text3,
863
- {
864
- style: [
865
- styles2.description,
866
- { fontSize: sizeStyles.descriptionSize, color: descriptionColor }
867
- ]
868
- },
869
- description
870
- )),
871
- isSelected && (selectedIcon || /* @__PURE__ */ React4.createElement(CheckmarkIcon, { color: checkmarkColor, size: 16 })),
872
- endContent
873
- );
874
- };
875
- export {
876
- Select,
877
- SelectItem
878
- };