@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,1122 +0,0 @@
1
- import {
2
- CheckmarkIcon
3
- } from "../chunk-GBHQCAKW.js";
4
- import "../chunk-SHBDANQN.js";
5
- import {
6
- Portal,
7
- useXUITheme
8
- } from "../chunk-RBSA4NH4.js";
9
-
10
- // src/components/autocomplete/autocomplete.tsx
11
- import React4, { useCallback as useCallback3, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
12
- import { Keyboard as Keyboard2, Text as Text3, View as View4 } from "react-native";
13
-
14
- // src/components/autocomplete/autocomplete-context.ts
15
- import { createContext } from "react";
16
- var AutocompleteContext = createContext({
17
- size: "md",
18
- themeColor: "default",
19
- isDisabled: false
20
- });
21
-
22
- // src/components/autocomplete/autocomplete.hook.ts
23
- import { useMemo } from "react";
24
- import { getSafeThemeColor, withOpacity } from "@xaui/core";
25
- import { colors } from "@xaui/core/palette";
26
- var useAutocompleteColorScheme = (themeColor) => {
27
- const theme = useXUITheme();
28
- const safeThemeColor = getSafeThemeColor(themeColor);
29
- const colorScheme = theme.colors[safeThemeColor];
30
- return { theme, colorScheme };
31
- };
32
- var useAutocompleteSizeStyles = (size) => {
33
- const theme = useXUITheme();
34
- return useMemo(() => {
35
- const sizes = {
36
- xs: {
37
- minHeight: theme.componentSizes.xs,
38
- paddingHorizontal: theme.spacing.sm,
39
- paddingVertical: theme.spacing.xs,
40
- fontSize: theme.fontSizes.xs,
41
- labelSize: theme.fontSizes.xs
42
- },
43
- sm: {
44
- minHeight: theme.componentSizes.sm,
45
- paddingHorizontal: theme.spacing.md,
46
- paddingVertical: theme.spacing.xs,
47
- fontSize: theme.fontSizes.sm,
48
- labelSize: theme.fontSizes.xs
49
- },
50
- md: {
51
- minHeight: theme.componentSizes.md,
52
- paddingHorizontal: theme.spacing.md,
53
- paddingVertical: theme.spacing.sm,
54
- fontSize: theme.fontSizes.md,
55
- labelSize: theme.fontSizes.sm
56
- },
57
- lg: {
58
- minHeight: theme.componentSizes.lg,
59
- paddingHorizontal: theme.spacing.lg,
60
- paddingVertical: theme.spacing.md,
61
- fontSize: theme.fontSizes.lg,
62
- labelSize: theme.fontSizes.md
63
- }
64
- };
65
- return sizes[size];
66
- }, [size, theme]);
67
- };
68
- var useAutocompleteRadiusStyles = (radius) => {
69
- const theme = useXUITheme();
70
- const radiusStyles = useMemo(() => {
71
- const radii = {
72
- none: theme.borderRadius.none,
73
- sm: theme.borderRadius.sm,
74
- md: theme.borderRadius.md,
75
- lg: theme.borderRadius.lg,
76
- full: theme.borderRadius.full
77
- };
78
- return { borderRadius: radii[radius] };
79
- }, [radius, theme]);
80
- const listboxRadius = useMemo(() => {
81
- const radii = {
82
- none: theme.borderRadius.none,
83
- sm: theme.borderRadius.sm,
84
- md: theme.borderRadius.md,
85
- lg: theme.borderRadius.lg,
86
- full: theme.borderRadius.full
87
- };
88
- return Math.min(radii[radius], theme.borderRadius.lg);
89
- }, [radius, theme]);
90
- return { radiusStyles, listboxRadius };
91
- };
92
- var useAutocompleteVariantStyles = (themeColor, variant, isInvalid) => {
93
- const { theme, colorScheme } = useAutocompleteColorScheme(themeColor);
94
- return useMemo(() => {
95
- let borderColor = isInvalid ? theme.colors.danger.main : colorScheme.main;
96
- if (variant === "bordered" && themeColor === "default") {
97
- borderColor = colors.gray[300];
98
- }
99
- const styles4 = {
100
- bordered: {
101
- backgroundColor: "transparent",
102
- borderWidth: theme.borderWidth.md,
103
- borderColor
104
- },
105
- colored: {
106
- backgroundColor: withOpacity(colorScheme.container, 0.5),
107
- borderWidth: 0
108
- },
109
- light: {
110
- backgroundColor: "transparent",
111
- borderWidth: 0
112
- },
113
- underlined: {
114
- backgroundColor: "transparent",
115
- borderBottomWidth: theme.borderWidth.md,
116
- borderColor
117
- }
118
- };
119
- return styles4[variant];
120
- }, [variant, theme, colorScheme, isInvalid, themeColor]);
121
- };
122
- var useAutocompleteLabelStyle = (themeColor, isInvalid, labelSize) => {
123
- const { theme, colorScheme } = useAutocompleteColorScheme(themeColor);
124
- return useMemo(() => {
125
- let baseColor = theme.colors.foreground;
126
- if (isInvalid) {
127
- baseColor = theme.colors.danger.main;
128
- } else if (themeColor !== "default") {
129
- baseColor = colorScheme.main;
130
- }
131
- return {
132
- fontSize: labelSize,
133
- color: baseColor
134
- };
135
- }, [isInvalid, labelSize, theme, themeColor, colorScheme]);
136
- };
137
- var useAutocompleteHelperColor = (isInvalid) => {
138
- const theme = useXUITheme();
139
- return useMemo(() => {
140
- if (isInvalid) {
141
- return theme.colors.danger.main;
142
- }
143
- return colors.gray[600];
144
- }, [isInvalid, theme]);
145
- };
146
-
147
- // src/components/autocomplete/autocomplete.style.ts
148
- import { StyleSheet } from "react-native";
149
- var styles = StyleSheet.create({
150
- container: {
151
- gap: 6,
152
- position: "relative"
153
- },
154
- fullWidth: {
155
- flexShrink: 1,
156
- flexBasis: "auto",
157
- width: "100%"
158
- },
159
- minWidth: {
160
- minWidth: 170
161
- },
162
- label: {
163
- fontWeight: "500"
164
- },
165
- trigger: {
166
- flexDirection: "row",
167
- alignItems: "center",
168
- justifyContent: "space-between",
169
- gap: 8
170
- },
171
- triggerText: {
172
- flex: 1
173
- },
174
- triggerWrapper: {
175
- position: "relative"
176
- },
177
- triggerContent: {
178
- flexDirection: "row",
179
- alignItems: "center",
180
- flex: 1,
181
- gap: 8
182
- },
183
- triggerContentColumn: {
184
- flexDirection: "column",
185
- alignItems: "flex-start"
186
- },
187
- inputWrapper: {
188
- flex: 1,
189
- gap: 2
190
- },
191
- input: {
192
- flexShrink: 1,
193
- padding: 0
194
- },
195
- endSlot: {
196
- flexDirection: "row",
197
- alignItems: "center",
198
- gap: 8
199
- },
200
- clearButton: {
201
- padding: 2,
202
- paddingLeft: 4,
203
- marginRight: -4
204
- },
205
- helperText: {
206
- fontSize: 12
207
- },
208
- disabled: {
209
- opacity: 0.5
210
- },
211
- listbox: {
212
- overflow: "hidden",
213
- marginTop: 0,
214
- position: "absolute",
215
- left: 0,
216
- right: 0,
217
- zIndex: 50,
218
- elevation: 4
219
- },
220
- listboxContent: {
221
- flexShrink: 1
222
- },
223
- emptyMessage: {
224
- paddingHorizontal: 16,
225
- paddingVertical: 12,
226
- textAlign: "center"
227
- },
228
- outsideLeftRow: {
229
- flexDirection: "row",
230
- alignItems: "center",
231
- gap: 12
232
- }
233
- });
234
-
235
- // src/components/autocomplete/autocomplete.state.hook.ts
236
- import { useCallback, useEffect, useRef, useState } from "react";
237
- var useAutocompleteOpenState = ({
238
- isOpened,
239
- isDisabled,
240
- onOpenChange,
241
- onClose
242
- }) => {
243
- const [internalIsOpen, setInternalIsOpen] = useState(false);
244
- const isOpen = isOpened !== void 0 ? isOpened : internalIsOpen;
245
- const setOpen = useCallback(
246
- (open) => {
247
- if (isDisabled) {
248
- return;
249
- }
250
- if (isOpened === void 0) {
251
- setInternalIsOpen(open);
252
- }
253
- onOpenChange?.(open);
254
- if (!open) {
255
- onClose?.();
256
- }
257
- },
258
- [isDisabled, isOpened, onOpenChange, onClose]
259
- );
260
- return { isOpen, setOpen };
261
- };
262
- var useAutocompleteInputState = ({
263
- inputValue,
264
- defaultInputValue,
265
- selectedKey,
266
- onInputChange
267
- }) => {
268
- const [internalInputValue, setInternalInputValue] = useState(
269
- defaultInputValue ?? ""
270
- );
271
- const currentInputValue = inputValue !== void 0 ? inputValue : internalInputValue;
272
- const updateInputValue = useCallback(
273
- (value) => {
274
- if (inputValue === void 0) {
275
- setInternalInputValue(value);
276
- }
277
- onInputChange?.(value);
278
- },
279
- [inputValue, onInputChange]
280
- );
281
- useEffect(() => {
282
- if (selectedKey === null && inputValue === void 0) {
283
- setInternalInputValue("");
284
- }
285
- }, [selectedKey, inputValue]);
286
- return { currentInputValue, updateInputValue };
287
- };
288
- var useAutocompleteSelection = ({
289
- onSelectionChange
290
- }) => {
291
- const [currentSelectedKey, setCurrentSelectedKey] = useState(null);
292
- const updateSelection = useCallback(
293
- (key) => {
294
- setCurrentSelectedKey(key);
295
- onSelectionChange?.(key);
296
- },
297
- [onSelectionChange]
298
- );
299
- return { currentSelectedKey, updateSelection };
300
- };
301
-
302
- // src/components/autocomplete/autocomplete.utils.ts
303
- var getTextValue = (node) => {
304
- if (typeof node === "string" || typeof node === "number") {
305
- return String(node);
306
- }
307
- return null;
308
- };
309
- var defaultFilterFunction = (textValue, inputValue) => {
310
- const normalizedText = textValue.toLowerCase().trim();
311
- const normalizedInput = inputValue.toLowerCase().trim();
312
- return normalizedText.includes(normalizedInput);
313
- };
314
-
315
- // src/components/dialogs/autocomplete-dialog/autocomplete-dialog.tsx
316
- import React2, { useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
317
- import {
318
- Animated as Animated3,
319
- BackHandler,
320
- FlatList,
321
- InteractionManager,
322
- Keyboard,
323
- Platform,
324
- Pressable as Pressable2,
325
- View as View2,
326
- useWindowDimensions
327
- } from "react-native";
328
-
329
- // src/components/dialogs/autocomplete-dialog/autocomplete-dialog-header.tsx
330
- import React from "react";
331
- import {
332
- Animated,
333
- Pressable,
334
- Text,
335
- TextInput,
336
- View
337
- } from "react-native";
338
- import { ArrowBackIcon, CloseIcon } from "@xaui/icons";
339
-
340
- // src/components/dialogs/autocomplete-dialog/autocomplete-dialog.style.ts
341
- import { StyleSheet as StyleSheet2 } from "react-native";
342
- var styles2 = StyleSheet2.create({
343
- backdrop: {
344
- ...StyleSheet2.absoluteFillObject,
345
- backgroundColor: "rgba(0, 0, 0, 0.5)"
346
- },
347
- dialogContainer: {
348
- flex: 1,
349
- zIndex: 1
350
- },
351
- container: {
352
- flex: 1,
353
- paddingTop: 55,
354
- paddingHorizontal: 16
355
- },
356
- header: {
357
- marginBottom: 12
358
- },
359
- titleRow: {
360
- flexDirection: "row",
361
- alignItems: "center",
362
- gap: 8,
363
- marginBottom: 16
364
- },
365
- backButton: {
366
- padding: 4
367
- },
368
- title: {
369
- fontSize: 20,
370
- fontWeight: "600"
371
- },
372
- inputContainer: {
373
- flexDirection: "row",
374
- alignItems: "center",
375
- gap: 8
376
- },
377
- inputWrapper: {
378
- flex: 1,
379
- flexDirection: "row",
380
- alignItems: "center",
381
- position: "relative"
382
- },
383
- input: {
384
- flex: 1,
385
- paddingVertical: 12,
386
- paddingHorizontal: 16,
387
- paddingRight: 40,
388
- borderRadius: 8,
389
- fontSize: 16
390
- },
391
- clearInputButton: {
392
- position: "absolute",
393
- right: 8,
394
- padding: 4
395
- },
396
- listContainer: {
397
- flex: 1
398
- },
399
- listContentContainer: {
400
- paddingBottom: 80
401
- },
402
- checkmarkButtonContainer: {
403
- position: "absolute",
404
- bottom: 24,
405
- right: 24
406
- },
407
- checkmarkButton: {
408
- width: 54,
409
- height: 54,
410
- borderRadius: 27,
411
- justifyContent: "center",
412
- alignItems: "center",
413
- elevation: 8
414
- }
415
- });
416
-
417
- // src/components/dialogs/autocomplete-dialog/autocomplete-dialog-header.tsx
418
- import { withOpacity as withOpacity2 } from "@xaui/core";
419
- var AutocompleteDialogHeader = ({
420
- title,
421
- inputValue,
422
- placeholder = "Search...",
423
- inputRef,
424
- inputAnimatedStyle,
425
- inputTextStyle,
426
- onInputChange,
427
- onClose,
428
- onCheckmarkPress,
429
- onFocus,
430
- onBlur
431
- }) => {
432
- const theme = useXUITheme();
433
- return /* @__PURE__ */ React.createElement(View, { style: styles2.header }, title ? /* @__PURE__ */ React.createElement(View, { style: styles2.titleRow }, /* @__PURE__ */ React.createElement(
434
- Pressable,
435
- {
436
- style: styles2.backButton,
437
- onPress: onClose,
438
- accessibilityLabel: "Back",
439
- accessibilityRole: "button"
440
- },
441
- /* @__PURE__ */ React.createElement(ArrowBackIcon, { size: 20, color: theme.colors.foreground })
442
- ), /* @__PURE__ */ React.createElement(Text, { style: [styles2.title, { color: theme.colors.foreground }] }, title)) : null, /* @__PURE__ */ React.createElement(View, { style: styles2.inputContainer }, /* @__PURE__ */ React.createElement(Animated.View, { style: [styles2.inputWrapper, inputAnimatedStyle] }, /* @__PURE__ */ React.createElement(
443
- TextInput,
444
- {
445
- ref: inputRef,
446
- value: inputValue,
447
- onChangeText: onInputChange,
448
- placeholder,
449
- placeholderTextColor: withOpacity2(theme.colors.foreground, 0.5),
450
- style: [
451
- styles2.input,
452
- {
453
- backgroundColor: theme.colors.default.container,
454
- color: theme.colors.foreground
455
- },
456
- inputTextStyle
457
- ],
458
- autoFocus: true,
459
- returnKeyType: "done",
460
- onSubmitEditing: onCheckmarkPress,
461
- onFocus,
462
- onBlur
463
- }
464
- ), inputValue ? /* @__PURE__ */ React.createElement(
465
- Pressable,
466
- {
467
- style: styles2.clearInputButton,
468
- onPress: () => onInputChange?.(""),
469
- accessibilityLabel: "Clear input",
470
- accessibilityRole: "button"
471
- },
472
- /* @__PURE__ */ React.createElement(CloseIcon, { color: theme.colors.foreground })
473
- ) : null)));
474
- };
475
-
476
- // src/components/dialogs/autocomplete-dialog/autocomplete-dialog.animation.ts
477
- import { useEffect as useEffect2 } from "react";
478
- import { Animated as Animated2 } from "react-native";
479
- var useAutocompleteDialogAnimation = ({
480
- visible,
481
- fadeAnim,
482
- slideAnim,
483
- scaleAnim
484
- }) => {
485
- useEffect2(() => {
486
- if (visible) {
487
- Animated2.parallel([
488
- Animated2.timing(fadeAnim, {
489
- toValue: 1,
490
- duration: 250,
491
- useNativeDriver: true
492
- }),
493
- Animated2.spring(slideAnim, {
494
- toValue: 1,
495
- useNativeDriver: true,
496
- tension: 65,
497
- friction: 10
498
- }),
499
- Animated2.spring(scaleAnim, {
500
- toValue: 1,
501
- useNativeDriver: true,
502
- tension: 50,
503
- friction: 8
504
- })
505
- ]).start();
506
- } else {
507
- fadeAnim.setValue(0);
508
- slideAnim.setValue(0);
509
- scaleAnim.setValue(0);
510
- }
511
- }, [visible, fadeAnim, slideAnim, scaleAnim]);
512
- };
513
-
514
- // src/components/dialogs/autocomplete-dialog/autocomplete-dialog.tsx
515
- var AutocompleteDialog = ({
516
- visible,
517
- inputValue,
518
- placeholder = "Search...",
519
- title,
520
- themeColor = "primary",
521
- children,
522
- showCheckmark = true,
523
- checkmarkIcon,
524
- inputTextStyle,
525
- style,
526
- onInputChange,
527
- onClose,
528
- onCheckmark,
529
- onFocus,
530
- onBlur
531
- }) => {
532
- const theme = useXUITheme();
533
- const { width: screenWidth, height: screenHeight } = useWindowDimensions();
534
- const fadeAnim = useRef2(new Animated3.Value(0)).current;
535
- const slideAnim = useRef2(new Animated3.Value(0)).current;
536
- const scaleAnim = useRef2(new Animated3.Value(0)).current;
537
- const inputRef = useRef2(null);
538
- const [keyboardHeight, setKeyboardHeight] = useState2(0);
539
- useEffect3(() => {
540
- const showEvent = Platform.OS === "ios" ? "keyboardWillShow" : "keyboardDidShow";
541
- const hideEvent = Platform.OS === "ios" ? "keyboardWillHide" : "keyboardDidHide";
542
- const showSub = Keyboard.addListener(showEvent, (e) => {
543
- setKeyboardHeight(e.endCoordinates.height);
544
- });
545
- const hideSub = Keyboard.addListener(hideEvent, () => {
546
- setKeyboardHeight(0);
547
- });
548
- return () => {
549
- showSub.remove();
550
- hideSub.remove();
551
- };
552
- }, []);
553
- const items = useMemo2(
554
- () => React2.Children.toArray(children).filter(
555
- React2.isValidElement
556
- ),
557
- [children]
558
- );
559
- const checkmarkColor = theme.colors[themeColor].main;
560
- const checkmarkBackgroundColor = theme.colors[themeColor].container;
561
- useAutocompleteDialogAnimation({ visible, fadeAnim, slideAnim, scaleAnim });
562
- useEffect3(() => {
563
- if (!visible) return;
564
- const sub = BackHandler.addEventListener("hardwareBackPress", () => {
565
- onClose?.();
566
- return true;
567
- });
568
- return () => sub.remove();
569
- }, [visible, onClose]);
570
- const focusInput = useCallback2(() => {
571
- const delay = Platform.OS === "android" ? 300 : 100;
572
- InteractionManager.runAfterInteractions(() => {
573
- setTimeout(() => {
574
- inputRef.current?.focus();
575
- }, delay);
576
- });
577
- }, []);
578
- const handleCheckmarkPress = () => {
579
- onCheckmark?.();
580
- Keyboard.dismiss();
581
- };
582
- useEffect3(() => {
583
- if (!visible) {
584
- Keyboard.dismiss();
585
- return;
586
- }
587
- focusInput();
588
- }, [focusInput, visible]);
589
- const listBottomPadding = useMemo2(() => {
590
- const basePadding = showCheckmark ? 96 : 64;
591
- return (keyboardHeight > 0 ? keyboardHeight : 0) + basePadding;
592
- }, [keyboardHeight, showCheckmark]);
593
- if (!visible) return null;
594
- const overlayStyle = {
595
- position: "absolute",
596
- top: 0,
597
- left: 0,
598
- width: screenWidth,
599
- height: screenHeight
600
- };
601
- const containerAnimatedStyle = {
602
- transform: [
603
- {
604
- translateY: slideAnim.interpolate({
605
- inputRange: [0, 1],
606
- outputRange: [screenHeight, 0]
607
- })
608
- }
609
- ]
610
- };
611
- const inputAnimatedStyle = {
612
- transform: [{ scaleX: scaleAnim }]
613
- };
614
- const listHeader = /* @__PURE__ */ React2.createElement(
615
- AutocompleteDialogHeader,
616
- {
617
- title,
618
- inputValue,
619
- placeholder,
620
- inputRef,
621
- inputAnimatedStyle,
622
- inputTextStyle,
623
- onInputChange,
624
- onClose,
625
- onCheckmarkPress: handleCheckmarkPress,
626
- onFocus,
627
- onBlur
628
- }
629
- );
630
- return /* @__PURE__ */ React2.createElement(Portal, null, /* @__PURE__ */ React2.createElement(View2, { style: [overlayStyle, style] }, /* @__PURE__ */ React2.createElement(Animated3.View, { style: [styles2.backdrop, { opacity: fadeAnim }] }), /* @__PURE__ */ React2.createElement(Animated3.View, { style: [styles2.dialogContainer, containerAnimatedStyle] }, /* @__PURE__ */ React2.createElement(
631
- View2,
632
- {
633
- style: [styles2.container, { backgroundColor: theme.colors.background }]
634
- },
635
- listHeader,
636
- /* @__PURE__ */ React2.createElement(
637
- FlatList,
638
- {
639
- data: items,
640
- renderItem: ({ item }) => item,
641
- keyExtractor: (_, index) => String(index),
642
- style: styles2.listContainer,
643
- contentContainerStyle: {
644
- paddingBottom: listBottomPadding
645
- },
646
- keyboardShouldPersistTaps: "always",
647
- keyboardDismissMode: "none",
648
- showsVerticalScrollIndicator: false
649
- }
650
- ),
651
- showCheckmark ? /* @__PURE__ */ React2.createElement(View2, { style: styles2.checkmarkButtonContainer }, /* @__PURE__ */ React2.createElement(
652
- Pressable2,
653
- {
654
- style: [
655
- styles2.checkmarkButton,
656
- { backgroundColor: checkmarkBackgroundColor }
657
- ],
658
- onPress: handleCheckmarkPress,
659
- accessibilityLabel: "Confirm",
660
- accessibilityRole: "button"
661
- },
662
- checkmarkIcon ?? /* @__PURE__ */ React2.createElement(CheckmarkIcon, { color: checkmarkColor, size: 20 })
663
- )) : null
664
- ))));
665
- };
666
-
667
- // src/components/autocomplete/autocomplete-trigger.tsx
668
- import React3 from "react";
669
- import { Pressable as Pressable3, Text as Text2, TouchableOpacity, View as View3 } from "react-native";
670
- import { CloseIcon as CloseIcon2 } from "@xaui/icons";
671
- var AutocompleteTrigger = ({
672
- triggerRef,
673
- isDisabled,
674
- currentSelectedKey,
675
- currentInputValue,
676
- displayValue,
677
- sizeStyles,
678
- radiusStyles,
679
- variantStyles,
680
- theme,
681
- isClearable,
682
- label,
683
- labelText,
684
- isLabelInside,
685
- clearIcon,
686
- style,
687
- textStyle,
688
- onPress: handleTriggerPress,
689
- onClear: handleClear,
690
- onLayout: handleTriggerLayout
691
- }) => {
692
- const renderLabel = isLabelInside && label;
693
- return /* @__PURE__ */ React3.createElement(
694
- Pressable3,
695
- {
696
- ref: triggerRef,
697
- onPress: handleTriggerPress,
698
- onLayout: handleTriggerLayout,
699
- disabled: isDisabled,
700
- style: [
701
- styles.trigger,
702
- {
703
- minHeight: sizeStyles.minHeight,
704
- paddingHorizontal: sizeStyles.paddingHorizontal,
705
- paddingVertical: sizeStyles.paddingVertical
706
- },
707
- radiusStyles,
708
- variantStyles,
709
- isDisabled && styles.disabled,
710
- style
711
- ],
712
- accessibilityLabel: labelText ?? (typeof label === "string" ? label : void 0),
713
- accessibilityRole: "button",
714
- accessibilityState: { disabled: isDisabled }
715
- },
716
- /* @__PURE__ */ React3.createElement(View3, { style: styles.triggerContent }, isLabelInside && renderLabel, /* @__PURE__ */ React3.createElement(
717
- Text2,
718
- {
719
- style: [
720
- styles.triggerText,
721
- { fontSize: sizeStyles.fontSize, color: theme.colors.foreground },
722
- !currentSelectedKey && !currentInputValue && { opacity: 0.5 },
723
- textStyle
724
- ],
725
- numberOfLines: 1,
726
- ellipsizeMode: "tail"
727
- },
728
- displayValue
729
- )),
730
- isClearable && (currentSelectedKey || currentInputValue) ? /* @__PURE__ */ React3.createElement(
731
- TouchableOpacity,
732
- {
733
- onPress: handleClear,
734
- style: styles.clearButton,
735
- hitSlop: { top: 8, right: 8, bottom: 8, left: 8 }
736
- },
737
- clearIcon ?? /* @__PURE__ */ React3.createElement(CloseIcon2, { color: theme.colors.foreground, size: 20 })
738
- ) : null
739
- );
740
- };
741
-
742
- // src/components/autocomplete/autocomplete.tsx
743
- var defaultPlaceholder = "Search...";
744
- var Autocomplete = ({
745
- children,
746
- variant = "colored",
747
- themeColor = "default",
748
- size = "md",
749
- radius = "md",
750
- placeholder = defaultPlaceholder,
751
- labelPlacement = "outside",
752
- label,
753
- description,
754
- errorMessage,
755
- clearIcon,
756
- fullWidth = false,
757
- isDisabled = false,
758
- isInvalid = false,
759
- isClearable = true,
760
- allowsCustomValue = false,
761
- forceSelection = false,
762
- allowsEmptyCollection = true,
763
- disableLocalFilter = false,
764
- inputValue,
765
- defaultInputValue,
766
- customAppearance,
767
- onClose,
768
- onOpenChange,
769
- onSelectionChange,
770
- onInputChange,
771
- onClear
772
- }) => {
773
- const { currentSelectedKey, updateSelection } = useAutocompleteSelection({
774
- onSelectionChange
775
- });
776
- const { currentInputValue, updateInputValue } = useAutocompleteInputState({
777
- inputValue,
778
- defaultInputValue,
779
- selectedKey: currentSelectedKey,
780
- onInputChange
781
- });
782
- const { isOpen, setOpen } = useAutocompleteOpenState({
783
- isOpened: void 0,
784
- isDisabled,
785
- onOpenChange,
786
- onClose
787
- });
788
- const triggerRef = useRef3(null);
789
- const [triggerLayout, setTriggerLayout] = useState3();
790
- const handleTriggerLayout = useCallback3(() => {
791
- triggerRef.current?.measureInWindow((x, y, width, height) => {
792
- setTriggerLayout({ x, y, width, height });
793
- });
794
- }, []);
795
- const items = useMemo3(() => {
796
- const elements = React4.Children.toArray(children).filter(Boolean);
797
- return elements.map((child, index) => {
798
- if (!React4.isValidElement(child)) {
799
- return null;
800
- }
801
- const key = child.props.value ?? String(index);
802
- const labelText = getTextValue(child.props.label) ?? key;
803
- return {
804
- key,
805
- element: child,
806
- labelText
807
- };
808
- }).filter((item) => item !== null);
809
- }, [children]);
810
- const filteredItems = useMemo3(() => {
811
- if (disableLocalFilter || !currentInputValue.trim()) {
812
- return items;
813
- }
814
- return items.filter(
815
- (item) => defaultFilterFunction(item.labelText, currentInputValue)
816
- );
817
- }, [disableLocalFilter, items, currentInputValue]);
818
- const theme = useXUITheme();
819
- const sizeStyles = useAutocompleteSizeStyles(size);
820
- const { radiusStyles } = useAutocompleteRadiusStyles(radius);
821
- const variantStyles = useAutocompleteVariantStyles(themeColor, variant, isInvalid);
822
- const labelStyle = useAutocompleteLabelStyle(
823
- themeColor,
824
- isInvalid,
825
- sizeStyles.labelSize
826
- );
827
- const helperColor = useAutocompleteHelperColor(isInvalid);
828
- const selectedItem = items.find((item) => item.key === currentSelectedKey);
829
- const displayValue = forceSelection ? selectedItem?.labelText || placeholder : currentInputValue || placeholder;
830
- const handleInputChange = useCallback3(
831
- (text) => {
832
- updateInputValue(text);
833
- const selectedLabel = selectedItem?.labelText ?? "";
834
- const shouldClearSelection = !text.trim() && !allowsCustomValue || currentSelectedKey !== null && text !== selectedLabel;
835
- if (shouldClearSelection) {
836
- updateSelection(null);
837
- }
838
- },
839
- [
840
- updateInputValue,
841
- allowsCustomValue,
842
- updateSelection,
843
- selectedItem,
844
- currentSelectedKey
845
- ]
846
- );
847
- const handleItemSelection = useCallback3(
848
- (key, itemLabel) => {
849
- if (isDisabled) {
850
- return;
851
- }
852
- updateSelection(key);
853
- updateInputValue(itemLabel);
854
- setTimeout(() => {
855
- Keyboard2.dismiss();
856
- setOpen(false);
857
- }, 50);
858
- },
859
- [isDisabled, updateSelection, updateInputValue, setOpen]
860
- );
861
- const handleCheckmark = useCallback3(() => {
862
- setOpen(false);
863
- }, [setOpen]);
864
- const handleClear = useCallback3(() => {
865
- if (isDisabled) {
866
- return;
867
- }
868
- updateSelection(null);
869
- updateInputValue("");
870
- onClear?.();
871
- }, [isDisabled, updateSelection, updateInputValue, onClear]);
872
- const handleTriggerPress = useCallback3(() => {
873
- if (!isDisabled) {
874
- if (selectedItem && !currentInputValue) {
875
- updateInputValue(selectedItem.labelText);
876
- }
877
- setOpen(true);
878
- }
879
- }, [isDisabled, setOpen, selectedItem, currentInputValue, updateInputValue]);
880
- const listItems = filteredItems.map((item) => {
881
- const itemProps = item.element.props;
882
- const itemDisabled = isDisabled || itemProps.isDisabled;
883
- const itemSelected = itemProps.isSelected ?? currentSelectedKey === item.key;
884
- const handleItemSelected = () => {
885
- if (itemDisabled || itemProps.isReadOnly) {
886
- return;
887
- }
888
- handleItemSelection(item.key, item.labelText);
889
- itemProps.onSelected?.();
890
- };
891
- return React4.cloneElement(item.element, {
892
- key: item.key,
893
- isDisabled: itemDisabled,
894
- isSelected: itemSelected,
895
- onSelected: handleItemSelected
896
- });
897
- });
898
- const showEmptyMessage = !allowsEmptyCollection && listItems.length === 0;
899
- const isLabelInside = labelPlacement === "inside";
900
- const isLabelOutsideLeft = labelPlacement === "outside-left";
901
- const isLabelOutside = labelPlacement === "outside" || labelPlacement === "outside-top";
902
- const renderLabel = label ? typeof label === "string" || typeof label === "number" ? /* @__PURE__ */ React4.createElement(Text3, { style: [styles.label, labelStyle] }, label) : /* @__PURE__ */ React4.createElement(View4, null, label) : null;
903
- const shouldShowHelper = Boolean(description || errorMessage);
904
- const helperContent = isInvalid && errorMessage ? errorMessage : description;
905
- const triggerContent = /* @__PURE__ */ React4.createElement(
906
- AutocompleteTrigger,
907
- {
908
- triggerRef,
909
- isDisabled,
910
- currentSelectedKey,
911
- currentInputValue,
912
- displayValue,
913
- sizeStyles,
914
- radiusStyles,
915
- variantStyles,
916
- theme,
917
- isClearable,
918
- label: renderLabel,
919
- labelText: typeof label === "string" ? label : void 0,
920
- isLabelInside,
921
- clearIcon,
922
- style: customAppearance?.container,
923
- textStyle: customAppearance?.text,
924
- onPress: handleTriggerPress,
925
- onClear: handleClear,
926
- onLayout: handleTriggerLayout
927
- }
928
- );
929
- const labelBlock = isLabelOutside || isLabelInside ? renderLabel : null;
930
- return /* @__PURE__ */ React4.createElement(View4, { style: [styles.container, fullWidth ? styles.fullWidth : styles.minWidth] }, isLabelOutside && labelBlock, isLabelOutsideLeft ? /* @__PURE__ */ React4.createElement(View4, { style: styles.outsideLeftRow }, renderLabel, triggerContent) : triggerContent, shouldShowHelper && helperContent ? typeof helperContent === "string" || typeof helperContent === "number" ? /* @__PURE__ */ React4.createElement(Text3, { style: [styles.helperText, { color: helperColor }] }, helperContent) : /* @__PURE__ */ React4.createElement(View4, null, helperContent) : null, /* @__PURE__ */ React4.createElement(
931
- AutocompleteDialog,
932
- {
933
- visible: isOpen,
934
- inputValue: currentInputValue,
935
- placeholder,
936
- title: typeof label === "string" ? label : void 0,
937
- themeColor,
938
- _triggerLayout: triggerLayout,
939
- showCheckmark: false,
940
- onInputChange: handleInputChange,
941
- onClose: () => setOpen(false),
942
- onCheckmark: handleCheckmark
943
- },
944
- /* @__PURE__ */ React4.createElement(AutocompleteContext.Provider, { value: { size, themeColor, isDisabled } }, showEmptyMessage ? /* @__PURE__ */ React4.createElement(Text3, { style: [styles.emptyMessage, { color: theme.colors.foreground }] }, "No results found") : listItems)
945
- ));
946
- };
947
-
948
- // src/components/autocomplete/autocomplete-item.tsx
949
- import React5, { useContext as useContext2 } from "react";
950
- import { Pressable as Pressable4, Text as Text4, View as View5 } from "react-native";
951
-
952
- // src/components/autocomplete/autocomplete-item.style.ts
953
- import { StyleSheet as StyleSheet3 } from "react-native";
954
- var styles3 = StyleSheet3.create({
955
- item: {
956
- flexDirection: "row",
957
- alignItems: "center",
958
- gap: 8
959
- },
960
- content: {
961
- flex: 1,
962
- gap: 2
963
- },
964
- title: {
965
- fontWeight: "500"
966
- },
967
- description: {
968
- opacity: 0.7
969
- },
970
- disabled: {
971
- opacity: 0.5
972
- }
973
- });
974
-
975
- // src/components/autocomplete/autocomplete-item.hook.ts
976
- import { useContext, useMemo as useMemo4 } from "react";
977
- import { getSafeThemeColor as getSafeThemeColor2 } from "@xaui/core";
978
- var useAutocompleteItemSizeStyles = (size) => {
979
- const theme = useXUITheme();
980
- return useMemo4(() => {
981
- const sizes = {
982
- xs: {
983
- paddingVertical: theme.spacing.sm,
984
- paddingHorizontal: theme.spacing.sm,
985
- titleSize: theme.fontSizes.xs,
986
- descriptionSize: theme.fontSizes.xs
987
- },
988
- sm: {
989
- paddingVertical: theme.spacing.sm,
990
- paddingHorizontal: theme.spacing.sm,
991
- titleSize: theme.fontSizes.sm,
992
- descriptionSize: theme.fontSizes.xs
993
- },
994
- md: {
995
- paddingVertical: theme.spacing.sm,
996
- paddingHorizontal: theme.spacing.sm,
997
- titleSize: theme.fontSizes.md,
998
- descriptionSize: theme.fontSizes.xs
999
- },
1000
- lg: {
1001
- paddingVertical: theme.spacing.sm,
1002
- paddingHorizontal: theme.spacing.sm,
1003
- titleSize: theme.fontSizes.lg,
1004
- descriptionSize: theme.fontSizes.md
1005
- }
1006
- };
1007
- return sizes[size];
1008
- }, [size, theme]);
1009
- };
1010
- var useAutocompleteItemBackgroundColor = (themeColor, isSelected) => {
1011
- const theme = useXUITheme();
1012
- const safeThemeColor = getSafeThemeColor2(themeColor);
1013
- const colorScheme = theme.colors[safeThemeColor];
1014
- return useMemo4(() => {
1015
- return "transparent";
1016
- }, [isSelected, colorScheme]);
1017
- };
1018
- var useAutocompleteItemTextColors = () => {
1019
- const theme = useXUITheme();
1020
- return useMemo4(() => {
1021
- return {
1022
- textColor: theme.colors.foreground,
1023
- descriptionColor: theme.colors.foreground
1024
- };
1025
- }, [theme]);
1026
- };
1027
- var useAutocompleteItemCheckmarkColor = (themeColor) => {
1028
- const theme = useXUITheme();
1029
- const safeThemeColor = getSafeThemeColor2(themeColor);
1030
- const colorScheme = theme.colors[safeThemeColor];
1031
- return useMemo4(() => {
1032
- if (themeColor === "default") {
1033
- return theme.colors.primary.main;
1034
- }
1035
- return colorScheme.main;
1036
- }, [themeColor, colorScheme, theme]);
1037
- };
1038
- var useAutocompleteItemStyles = (isSelected, _isDisabled) => {
1039
- const context = useContext(AutocompleteContext);
1040
- const backgroundColor = useAutocompleteItemBackgroundColor(
1041
- context.themeColor,
1042
- isSelected
1043
- );
1044
- const { textColor, descriptionColor } = useAutocompleteItemTextColors();
1045
- const checkmarkColor = useAutocompleteItemCheckmarkColor(context.themeColor);
1046
- return {
1047
- backgroundColor,
1048
- labelColor: textColor,
1049
- descriptionColor,
1050
- checkmarkColor
1051
- };
1052
- };
1053
-
1054
- // src/components/autocomplete/autocomplete-item.tsx
1055
- var defaultSize = "md";
1056
- var AutocompleteItem = ({
1057
- label,
1058
- description,
1059
- startContent,
1060
- endContent,
1061
- selectedIcon: _selectedIcon,
1062
- isDisabled = false,
1063
- isSelected = false,
1064
- isReadOnly = false,
1065
- customAppearance,
1066
- onSelected
1067
- }) => {
1068
- const context = useContext2(AutocompleteContext);
1069
- const size = context?.size ?? defaultSize;
1070
- const isItemDisabled = context?.isDisabled ? true : isDisabled;
1071
- const sizeStyles = useAutocompleteItemSizeStyles(size);
1072
- const { backgroundColor, labelColor, descriptionColor } = useAutocompleteItemStyles(isSelected, isItemDisabled);
1073
- const handlePress = () => {
1074
- if (isItemDisabled || isReadOnly) {
1075
- return;
1076
- }
1077
- onSelected?.();
1078
- };
1079
- return /* @__PURE__ */ React5.createElement(
1080
- Pressable4,
1081
- {
1082
- onPress: handlePress,
1083
- disabled: isItemDisabled,
1084
- style: [
1085
- styles3.item,
1086
- {
1087
- paddingVertical: sizeStyles.paddingVertical,
1088
- paddingHorizontal: sizeStyles.paddingHorizontal,
1089
- backgroundColor
1090
- },
1091
- isItemDisabled && styles3.disabled,
1092
- customAppearance?.container
1093
- ]
1094
- },
1095
- startContent,
1096
- /* @__PURE__ */ React5.createElement(View5, { style: styles3.content }, /* @__PURE__ */ React5.createElement(
1097
- Text4,
1098
- {
1099
- style: [
1100
- styles3.title,
1101
- { fontSize: sizeStyles.titleSize, color: labelColor },
1102
- customAppearance?.text
1103
- ]
1104
- },
1105
- label
1106
- ), description && /* @__PURE__ */ React5.createElement(
1107
- Text4,
1108
- {
1109
- style: [
1110
- styles3.description,
1111
- { fontSize: sizeStyles.descriptionSize, color: descriptionColor }
1112
- ]
1113
- },
1114
- description
1115
- )),
1116
- endContent
1117
- );
1118
- };
1119
- export {
1120
- Autocomplete,
1121
- AutocompleteItem
1122
- };