@xaui/native 0.2.8 → 0.9.1-alpha.0

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 (224) hide show
  1. package/dist/chunk-JDS6KGCM.cjs +791 -0
  2. package/dist/chunk-T3ZI2PZ6.js +791 -0
  3. package/dist/index.cjs +32 -1
  4. package/dist/index.d.cts +2 -2
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +32 -0
  7. package/dist/theme/index.cjs +32 -0
  8. package/dist/theme/index.d.cts +669 -0
  9. package/dist/theme/index.d.ts +669 -0
  10. package/dist/theme/index.js +32 -0
  11. package/package.json +26 -249
  12. package/README.md +0 -178
  13. package/dist/alert/index.cjs +0 -340
  14. package/dist/alert/index.d.cts +0 -46
  15. package/dist/alert/index.d.ts +0 -46
  16. package/dist/alert/index.js +0 -340
  17. package/dist/app-bar/index.cjs +0 -148
  18. package/dist/app-bar/index.d.cts +0 -59
  19. package/dist/app-bar/index.d.ts +0 -59
  20. package/dist/app-bar/index.js +0 -148
  21. package/dist/autocomplete/index.cjs +0 -1122
  22. package/dist/autocomplete/index.d.cts +0 -88
  23. package/dist/autocomplete/index.d.ts +0 -88
  24. package/dist/autocomplete/index.js +0 -1122
  25. package/dist/avatar/index.cjs +0 -281
  26. package/dist/avatar/index.d.cts +0 -123
  27. package/dist/avatar/index.d.ts +0 -123
  28. package/dist/avatar/index.js +0 -281
  29. package/dist/badge/index.cjs +0 -197
  30. package/dist/badge/index.d.cts +0 -94
  31. package/dist/badge/index.d.ts +0 -94
  32. package/dist/badge/index.js +0 -197
  33. package/dist/bottom-sheet/index.cjs +0 -9
  34. package/dist/bottom-sheet/index.d.cts +0 -84
  35. package/dist/bottom-sheet/index.d.ts +0 -84
  36. package/dist/bottom-sheet/index.js +0 -9
  37. package/dist/bottom-tab-bar/index.cjs +0 -497
  38. package/dist/bottom-tab-bar/index.d.cts +0 -211
  39. package/dist/bottom-tab-bar/index.d.ts +0 -211
  40. package/dist/bottom-tab-bar/index.js +0 -497
  41. package/dist/button/index.cjs +0 -392
  42. package/dist/button/index.d.cts +0 -174
  43. package/dist/button/index.d.ts +0 -174
  44. package/dist/button/index.js +0 -392
  45. package/dist/button.type-j1ZdkkSl.d.cts +0 -4
  46. package/dist/button.type-j1ZdkkSl.d.ts +0 -4
  47. package/dist/card/index.cjs +0 -338
  48. package/dist/card/index.d.cts +0 -191
  49. package/dist/card/index.d.ts +0 -191
  50. package/dist/card/index.js +0 -338
  51. package/dist/carousel/index.cjs +0 -381
  52. package/dist/carousel/index.d.cts +0 -147
  53. package/dist/carousel/index.d.ts +0 -147
  54. package/dist/carousel/index.js +0 -381
  55. package/dist/chart/index.cjs +0 -1026
  56. package/dist/chart/index.d.cts +0 -218
  57. package/dist/chart/index.d.ts +0 -218
  58. package/dist/chart/index.js +0 -1026
  59. package/dist/checkbox/index.cjs +0 -443
  60. package/dist/checkbox/index.d.cts +0 -73
  61. package/dist/checkbox/index.d.ts +0 -73
  62. package/dist/checkbox/index.js +0 -443
  63. package/dist/chip/index.cjs +0 -503
  64. package/dist/chip/index.d.cts +0 -195
  65. package/dist/chip/index.d.ts +0 -195
  66. package/dist/chip/index.js +0 -503
  67. package/dist/chunk-4JFWQ5XT.js +0 -368
  68. package/dist/chunk-56RPWZD2.cjs +0 -9
  69. package/dist/chunk-7UFBLUMV.cjs +0 -136
  70. package/dist/chunk-A45TVXU5.js +0 -337
  71. package/dist/chunk-BYWUAPC4.cjs +0 -368
  72. package/dist/chunk-DECMUMCI.js +0 -0
  73. package/dist/chunk-DHSTKO3K.cjs +0 -19
  74. package/dist/chunk-DJ4Q37UT.cjs +0 -75
  75. package/dist/chunk-EUQDGTST.cjs +0 -1
  76. package/dist/chunk-GBHQCAKW.js +0 -19
  77. package/dist/chunk-RBSA4NH4.js +0 -136
  78. package/dist/chunk-SHBDANQN.js +0 -9
  79. package/dist/chunk-UGEINZM7.cjs +0 -290
  80. package/dist/chunk-UU4HHBDN.js +0 -290
  81. package/dist/chunk-VSZEXOUN.js +0 -384
  82. package/dist/chunk-YIEUN3G5.cjs +0 -384
  83. package/dist/chunk-ZH6ZSV2Q.cjs +0 -337
  84. package/dist/chunk-ZY7IUTAT.js +0 -75
  85. package/dist/color-picker/index.cjs +0 -457
  86. package/dist/color-picker/index.d.cts +0 -124
  87. package/dist/color-picker/index.d.ts +0 -124
  88. package/dist/color-picker/index.js +0 -457
  89. package/dist/core/index.cjs +0 -24
  90. package/dist/core/index.d.cts +0 -28
  91. package/dist/core/index.d.ts +0 -28
  92. package/dist/core/index.js +0 -24
  93. package/dist/datepicker/index.cjs +0 -1625
  94. package/dist/datepicker/index.d.cts +0 -45
  95. package/dist/datepicker/index.d.ts +0 -45
  96. package/dist/datepicker/index.js +0 -1625
  97. package/dist/dialog/index.cjs +0 -372
  98. package/dist/dialog/index.d.cts +0 -151
  99. package/dist/dialog/index.d.ts +0 -151
  100. package/dist/dialog/index.js +0 -372
  101. package/dist/divider/index.cjs +0 -8
  102. package/dist/divider/index.d.cts +0 -30
  103. package/dist/divider/index.d.ts +0 -30
  104. package/dist/divider/index.js +0 -8
  105. package/dist/drawer/index.cjs +0 -237
  106. package/dist/drawer/index.d.cts +0 -58
  107. package/dist/drawer/index.d.ts +0 -58
  108. package/dist/drawer/index.js +0 -237
  109. package/dist/expansion-panel/index.cjs +0 -441
  110. package/dist/expansion-panel/index.d.cts +0 -153
  111. package/dist/expansion-panel/index.d.ts +0 -153
  112. package/dist/expansion-panel/index.js +0 -441
  113. package/dist/fab/index.cjs +0 -9
  114. package/dist/fab/index.d.cts +0 -10
  115. package/dist/fab/index.d.ts +0 -10
  116. package/dist/fab/index.js +0 -9
  117. package/dist/fab-menu/index.cjs +0 -330
  118. package/dist/fab-menu/index.d.cts +0 -125
  119. package/dist/fab-menu/index.d.ts +0 -125
  120. package/dist/fab-menu/index.js +0 -330
  121. package/dist/fab.type-CkUHmXU_.d.ts +0 -86
  122. package/dist/fab.type-DN0vtAh6.d.cts +0 -86
  123. package/dist/feature-discovery/index.cjs +0 -464
  124. package/dist/feature-discovery/index.d.cts +0 -82
  125. package/dist/feature-discovery/index.d.ts +0 -82
  126. package/dist/feature-discovery/index.js +0 -464
  127. package/dist/indicator/index.cjs +0 -8
  128. package/dist/indicator/index.d.cts +0 -47
  129. package/dist/indicator/index.d.ts +0 -47
  130. package/dist/indicator/index.js +0 -8
  131. package/dist/input/index.cjs +0 -1462
  132. package/dist/input/index.d.cts +0 -522
  133. package/dist/input/index.d.ts +0 -522
  134. package/dist/input/index.js +0 -1462
  135. package/dist/input-trigger/index.cjs +0 -197
  136. package/dist/input-trigger/index.d.cts +0 -11
  137. package/dist/input-trigger/index.d.ts +0 -11
  138. package/dist/input-trigger/index.js +0 -197
  139. package/dist/input-trigger.type-Ba4bM3Qp.d.cts +0 -180
  140. package/dist/input-trigger.type-Ba4bM3Qp.d.ts +0 -180
  141. package/dist/list/index.cjs +0 -395
  142. package/dist/list/index.d.cts +0 -188
  143. package/dist/list/index.d.ts +0 -188
  144. package/dist/list/index.js +0 -395
  145. package/dist/menu/index.cjs +0 -316
  146. package/dist/menu/index.d.cts +0 -115
  147. package/dist/menu/index.d.ts +0 -115
  148. package/dist/menu/index.js +0 -316
  149. package/dist/menubox/index.cjs +0 -297
  150. package/dist/menubox/index.d.cts +0 -98
  151. package/dist/menubox/index.d.ts +0 -98
  152. package/dist/menubox/index.js +0 -297
  153. package/dist/pager/index.cjs +0 -205
  154. package/dist/pager/index.d.cts +0 -93
  155. package/dist/pager/index.d.ts +0 -93
  156. package/dist/pager/index.js +0 -205
  157. package/dist/picker/index.cjs +0 -244
  158. package/dist/picker/index.d.cts +0 -121
  159. package/dist/picker/index.d.ts +0 -121
  160. package/dist/picker/index.js +0 -244
  161. package/dist/progress/index.cjs +0 -219
  162. package/dist/progress/index.d.cts +0 -47
  163. package/dist/progress/index.d.ts +0 -47
  164. package/dist/progress/index.js +0 -219
  165. package/dist/radio/index.cjs +0 -465
  166. package/dist/radio/index.d.cts +0 -145
  167. package/dist/radio/index.d.ts +0 -145
  168. package/dist/radio/index.js +0 -465
  169. package/dist/refresh-control/index.cjs +0 -45
  170. package/dist/refresh-control/index.d.cts +0 -55
  171. package/dist/refresh-control/index.d.ts +0 -55
  172. package/dist/refresh-control/index.js +0 -45
  173. package/dist/segment-button/index.cjs +0 -405
  174. package/dist/segment-button/index.d.cts +0 -141
  175. package/dist/segment-button/index.d.ts +0 -141
  176. package/dist/segment-button/index.js +0 -405
  177. package/dist/select/index.cjs +0 -878
  178. package/dist/select/index.d.cts +0 -192
  179. package/dist/select/index.d.ts +0 -192
  180. package/dist/select/index.js +0 -878
  181. package/dist/skeleton/index.cjs +0 -89
  182. package/dist/skeleton/index.d.cts +0 -45
  183. package/dist/skeleton/index.d.ts +0 -45
  184. package/dist/skeleton/index.js +0 -89
  185. package/dist/slider/index.cjs +0 -576
  186. package/dist/slider/index.d.cts +0 -171
  187. package/dist/slider/index.d.ts +0 -171
  188. package/dist/slider/index.js +0 -576
  189. package/dist/snackbar/index.cjs +0 -436
  190. package/dist/snackbar/index.d.cts +0 -174
  191. package/dist/snackbar/index.d.ts +0 -174
  192. package/dist/snackbar/index.js +0 -436
  193. package/dist/snippet/index.cjs +0 -314
  194. package/dist/snippet/index.d.cts +0 -95
  195. package/dist/snippet/index.d.ts +0 -95
  196. package/dist/snippet/index.js +0 -314
  197. package/dist/stepper/index.cjs +0 -550
  198. package/dist/stepper/index.d.cts +0 -137
  199. package/dist/stepper/index.d.ts +0 -137
  200. package/dist/stepper/index.js +0 -550
  201. package/dist/switch/index.cjs +0 -358
  202. package/dist/switch/index.d.cts +0 -28
  203. package/dist/switch/index.d.ts +0 -28
  204. package/dist/switch/index.js +0 -358
  205. package/dist/tabs/index.cjs +0 -440
  206. package/dist/tabs/index.d.cts +0 -180
  207. package/dist/tabs/index.d.ts +0 -180
  208. package/dist/tabs/index.js +0 -440
  209. package/dist/timepicker/index.cjs +0 -823
  210. package/dist/timepicker/index.d.cts +0 -215
  211. package/dist/timepicker/index.d.ts +0 -215
  212. package/dist/timepicker/index.js +0 -823
  213. package/dist/toolbar/index.cjs +0 -333
  214. package/dist/toolbar/index.d.cts +0 -100
  215. package/dist/toolbar/index.d.ts +0 -100
  216. package/dist/toolbar/index.js +0 -333
  217. package/dist/typography/index.cjs +0 -238
  218. package/dist/typography/index.d.cts +0 -113
  219. package/dist/typography/index.d.ts +0 -113
  220. package/dist/typography/index.js +0 -238
  221. package/dist/view/index.cjs +0 -1361
  222. package/dist/view/index.d.cts +0 -833
  223. package/dist/view/index.d.ts +0 -833
  224. package/dist/view/index.js +0 -1361
@@ -1,1462 +0,0 @@
1
- import "../chunk-SHBDANQN.js";
2
- import {
3
- useXUITheme
4
- } from "../chunk-RBSA4NH4.js";
5
-
6
- // src/components/input/input.tsx
7
- import React, { forwardRef, useMemo as useMemo2, useState, useRef, useEffect } from "react";
8
- import {
9
- Pressable,
10
- Text,
11
- TextInput as RNTextInput,
12
- View,
13
- Animated
14
- } from "react-native";
15
- import { CloseIcon } from "@xaui/icons";
16
-
17
- // src/components/input/input.hook.ts
18
- import { useMemo } from "react";
19
- import { getSafeThemeColor, withOpacity, withPaletteNumber } from "@xaui/core";
20
- var useTextInputSizeStyles = (size) => {
21
- const theme = useXUITheme();
22
- return useMemo(() => {
23
- const sizeMap = {
24
- sm: {
25
- minHeight: theme.componentSizes.sm,
26
- fontSize: 14,
27
- paddingHorizontal: 12,
28
- paddingVertical: 8,
29
- slotGap: 8,
30
- labelSize: 13,
31
- helperSize: 12
32
- },
33
- md: {
34
- minHeight: theme.componentSizes.md,
35
- fontSize: 16,
36
- paddingHorizontal: 14,
37
- paddingVertical: 10,
38
- slotGap: 10,
39
- labelSize: 14,
40
- helperSize: 13
41
- },
42
- lg: {
43
- minHeight: theme.componentSizes.lg,
44
- fontSize: 17,
45
- paddingHorizontal: 16,
46
- paddingVertical: 12,
47
- slotGap: 12,
48
- labelSize: 15,
49
- helperSize: 15
50
- }
51
- };
52
- return sizeMap[size];
53
- }, [size, theme]);
54
- };
55
- var useTextInputRadiusStyles = (radius) => {
56
- const theme = useXUITheme();
57
- return useMemo(() => {
58
- if (radius === "full") {
59
- return { borderRadius: theme.borderRadius.full };
60
- }
61
- return { borderRadius: theme.borderRadius[radius] };
62
- }, [radius, theme.borderRadius]);
63
- };
64
- var useTextInputVariantStyles = ({
65
- themeColor,
66
- variant,
67
- isFocused,
68
- isInvalid,
69
- isDisabled
70
- }) => {
71
- const theme = useXUITheme();
72
- const safeThemeColor = getSafeThemeColor(themeColor);
73
- const colorScheme = theme.colors[safeThemeColor];
74
- return useMemo(() => {
75
- const focusColor = isInvalid ? theme.colors.danger.main : colorScheme.main;
76
- const neutralBorder = withOpacity(theme.colors.foreground, 0.1);
77
- const textColor = isDisabled ? withOpacity(theme.colors.foreground, 0.55) : theme.colors.foreground;
78
- const placeholderColor = withOpacity(theme.colors.foreground, 0.45);
79
- const labelColor = isInvalid ? theme.colors.danger.main : isFocused ? colorScheme.main : withOpacity(theme.colors.foreground, 0.8);
80
- const helperColor = isInvalid ? theme.colors.danger.main : withOpacity(theme.colors.foreground, 0.72);
81
- if (variant === "underlined") {
82
- return {
83
- container: {
84
- backgroundColor: "transparent",
85
- borderColor: focusColor,
86
- borderBottomWidth: isFocused || isInvalid ? 2 : 1
87
- },
88
- unfocusedBorderColor: neutralBorder,
89
- focusedBorderColor: focusColor,
90
- textColor,
91
- placeholderColor,
92
- labelColor,
93
- helperColor
94
- };
95
- }
96
- if (variant === "bordered") {
97
- return {
98
- container: {
99
- backgroundColor: theme.colors.background,
100
- borderColor: isFocused || isInvalid ? focusColor : neutralBorder,
101
- borderWidth: theme.borderWidth.md
102
- },
103
- unfocusedBorderColor: neutralBorder,
104
- focusedBorderColor: focusColor,
105
- textColor,
106
- placeholderColor,
107
- labelColor,
108
- helperColor
109
- };
110
- }
111
- if (variant === "light") {
112
- return {
113
- container: {
114
- borderColor: isFocused || isInvalid ? focusColor : "transparent",
115
- borderWidth: isFocused || isInvalid ? theme.borderWidth.md : 0
116
- },
117
- unfocusedBorderColor: "transparent",
118
- focusedBorderColor: focusColor,
119
- textColor,
120
- placeholderColor,
121
- labelColor,
122
- helperColor
123
- };
124
- }
125
- return {
126
- container: {
127
- backgroundColor: withOpacity(colorScheme.container, 0.5),
128
- borderColor: isFocused || isInvalid ? withPaletteNumber(focusColor, 500) : "transparent",
129
- borderWidth: isFocused || isInvalid ? theme.borderWidth.md : 0
130
- },
131
- unfocusedBorderColor: "transparent",
132
- focusedBorderColor: withPaletteNumber(focusColor, 500),
133
- textColor,
134
- placeholderColor,
135
- labelColor,
136
- helperColor
137
- };
138
- }, [colorScheme, isDisabled, isFocused, isInvalid, theme, variant]);
139
- };
140
-
141
- // src/components/input/input.style.ts
142
- import { StyleSheet } from "react-native";
143
- var styles = StyleSheet.create({
144
- container: {
145
- width: "100%",
146
- gap: 6
147
- },
148
- noFullWidth: {
149
- alignSelf: "flex-start"
150
- },
151
- inputContainer: {
152
- gap: 6
153
- },
154
- label: {
155
- fontWeight: "500"
156
- },
157
- inputWrapper: {
158
- flexDirection: "row",
159
- alignItems: "center"
160
- },
161
- underlinedWrapper: {
162
- borderBottomLeftRadius: 0,
163
- borderBottomRightRadius: 0,
164
- paddingHorizontal: 0
165
- },
166
- slot: {
167
- justifyContent: "center",
168
- alignItems: "center"
169
- },
170
- input: {
171
- flex: 1,
172
- padding: 0,
173
- includeFontPadding: false
174
- },
175
- clearButton: {
176
- justifyContent: "center",
177
- alignItems: "center",
178
- marginLeft: 6
179
- },
180
- helperText: {
181
- fontWeight: "400"
182
- },
183
- disabled: {
184
- opacity: 0.6
185
- }
186
- });
187
-
188
- // src/components/input/input.tsx
189
- var TextInput = forwardRef(
190
- ({
191
- value,
192
- defaultValue,
193
- onValueChange,
194
- onChangeText,
195
- onFocus,
196
- onBlur,
197
- label,
198
- labelPlacement = "outside",
199
- description,
200
- errorMessage,
201
- startContent,
202
- endContent,
203
- themeColor = "primary",
204
- variant = "colored",
205
- size = "md",
206
- radius = "md",
207
- isSecured = false,
208
- isClearable = false,
209
- isDisabled = false,
210
- isReadOnly = false,
211
- isInvalid = false,
212
- fullWidth = true,
213
- customAppearance,
214
- ...nativeProps
215
- }, forwardedRef) => {
216
- const isControlled = typeof value === "string";
217
- const [internalValue, setInternalValue] = useState(defaultValue ?? "");
218
- const [isFocused, setIsFocused] = useState(false);
219
- const internalRef = useRef(null);
220
- const borderAnimation = useRef(new Animated.Value(0)).current;
221
- const inputValue = isControlled ? value ?? "" : internalValue;
222
- const secureTextEntry = nativeProps.secureTextEntry ?? isSecured;
223
- const sizeStyles = useTextInputSizeStyles(size);
224
- const radiusStyles = useTextInputRadiusStyles(radius);
225
- const variantStyles = useTextInputVariantStyles({
226
- themeColor,
227
- variant,
228
- isFocused,
229
- isInvalid,
230
- isDisabled
231
- });
232
- useEffect(() => {
233
- Animated.timing(borderAnimation, {
234
- toValue: isFocused || isInvalid ? 1 : 0,
235
- duration: 200,
236
- useNativeDriver: false
237
- }).start();
238
- }, [borderAnimation, isFocused, isInvalid]);
239
- const showClearButton = isClearable && !!inputValue && !isDisabled && !isReadOnly && !secureTextEntry && nativeProps.editable !== false;
240
- const editable = nativeProps.editable ?? (!isDisabled && !isReadOnly);
241
- const helperText = useMemo2(() => {
242
- if (isInvalid && errorMessage) {
243
- return errorMessage;
244
- }
245
- return description;
246
- }, [description, errorMessage, isInvalid]);
247
- const handleChangeText = (text) => {
248
- if (!isControlled) {
249
- setInternalValue(text);
250
- }
251
- onValueChange?.(text);
252
- onChangeText?.(text);
253
- };
254
- const handleClear = () => {
255
- if (!isControlled) {
256
- setInternalValue("");
257
- }
258
- onValueChange?.("");
259
- onChangeText?.("");
260
- };
261
- const handleWrapperPress = () => {
262
- if (isDisabled || isReadOnly || nativeProps.editable === false) return;
263
- const inputRef = forwardedRef || internalRef;
264
- if (typeof forwardedRef === "function") {
265
- internalRef.current?.focus();
266
- } else if (inputRef?.current) {
267
- inputRef.current.focus();
268
- }
269
- };
270
- return /* @__PURE__ */ React.createElement(
271
- View,
272
- {
273
- style: [
274
- styles.container,
275
- !fullWidth && styles.noFullWidth,
276
- isDisabled && styles.disabled,
277
- customAppearance?.container
278
- ]
279
- },
280
- /* @__PURE__ */ React.createElement(View, { style: [styles.inputContainer, customAppearance?.inputContainer] }, label && labelPlacement === "outside" && /* @__PURE__ */ React.createElement(
281
- Text,
282
- {
283
- style: [
284
- styles.label,
285
- {
286
- color: variantStyles.labelColor,
287
- fontSize: sizeStyles.labelSize
288
- },
289
- customAppearance?.label
290
- ]
291
- },
292
- label
293
- ), /* @__PURE__ */ React.createElement(
294
- Pressable,
295
- {
296
- onPress: handleWrapperPress,
297
- disabled: isDisabled || isReadOnly
298
- },
299
- /* @__PURE__ */ React.createElement(
300
- Animated.View,
301
- {
302
- style: [
303
- styles.inputWrapper,
304
- {
305
- minHeight: sizeStyles.minHeight,
306
- paddingVertical: sizeStyles.paddingVertical,
307
- paddingHorizontal: sizeStyles.paddingHorizontal,
308
- gap: sizeStyles.slotGap,
309
- backgroundColor: variantStyles.container.backgroundColor,
310
- borderWidth: variant === "underlined" ? 0 : variantStyles.container.borderWidth,
311
- ...variant === "underlined" && {
312
- borderBottomWidth: variantStyles.container.borderBottomWidth
313
- },
314
- borderRadius: variant === "underlined" ? 0 : radiusStyles.borderRadius,
315
- ...variant === "underlined" ? {
316
- borderBottomColor: borderAnimation.interpolate({
317
- inputRange: [0, 1],
318
- outputRange: [
319
- variantStyles.unfocusedBorderColor,
320
- variantStyles.focusedBorderColor
321
- ]
322
- })
323
- } : {
324
- borderColor: borderAnimation.interpolate({
325
- inputRange: [0, 1],
326
- outputRange: [
327
- variantStyles.unfocusedBorderColor,
328
- variantStyles.focusedBorderColor
329
- ]
330
- })
331
- }
332
- },
333
- variant === "underlined" && styles.underlinedWrapper,
334
- customAppearance?.inputWrapper
335
- ]
336
- },
337
- startContent && /* @__PURE__ */ React.createElement(View, { style: styles.slot }, startContent),
338
- /* @__PURE__ */ React.createElement(
339
- View,
340
- {
341
- style: {
342
- flex: 1,
343
- gap: labelPlacement === "inside" && label ? 2 : 0
344
- }
345
- },
346
- label && labelPlacement === "inside" && /* @__PURE__ */ React.createElement(
347
- Text,
348
- {
349
- style: [
350
- styles.label,
351
- {
352
- color: variantStyles.labelColor,
353
- fontSize: sizeStyles.helperSize,
354
- paddingBottom: 2
355
- },
356
- customAppearance?.label
357
- ]
358
- },
359
- label
360
- ),
361
- /* @__PURE__ */ React.createElement(
362
- RNTextInput,
363
- {
364
- ref: typeof forwardedRef === "function" ? internalRef : forwardedRef || internalRef,
365
- value: inputValue,
366
- onChangeText: handleChangeText,
367
- onFocus: (event) => {
368
- setIsFocused(true);
369
- onFocus?.(event);
370
- },
371
- onBlur: (event) => {
372
- setIsFocused(false);
373
- onBlur?.(event);
374
- },
375
- editable,
376
- secureTextEntry,
377
- placeholderTextColor: variantStyles.placeholderColor,
378
- style: [
379
- styles.input,
380
- {
381
- color: variantStyles.textColor,
382
- fontSize: sizeStyles.fontSize
383
- },
384
- customAppearance?.input
385
- ],
386
- ...nativeProps
387
- }
388
- )
389
- ),
390
- showClearButton ? /* @__PURE__ */ React.createElement(
391
- Pressable,
392
- {
393
- onPress: handleClear,
394
- accessibilityLabel: "Clear input",
395
- accessibilityRole: "button",
396
- style: styles.clearButton
397
- },
398
- /* @__PURE__ */ React.createElement(CloseIcon, { size: 16, color: variantStyles.placeholderColor })
399
- ) : endContent && /* @__PURE__ */ React.createElement(View, { style: styles.slot }, endContent)
400
- )
401
- )),
402
- helperText && /* @__PURE__ */ React.createElement(
403
- Text,
404
- {
405
- style: [
406
- styles.helperText,
407
- {
408
- color: variantStyles.helperColor,
409
- fontSize: sizeStyles.helperSize
410
- },
411
- customAppearance?.helperText
412
- ]
413
- },
414
- helperText
415
- )
416
- );
417
- }
418
- );
419
- TextInput.displayName = "TextInput";
420
-
421
- // src/components/input/textarea.tsx
422
- import React2 from "react";
423
-
424
- // src/components/input/textarea.style.ts
425
- import { StyleSheet as StyleSheet2 } from "react-native";
426
- var textAreaStyles = StyleSheet2.create({
427
- inputWrapper: {
428
- alignItems: "flex-start"
429
- },
430
- input: {
431
- textAlignVertical: "top"
432
- }
433
- });
434
-
435
- // src/components/input/textarea.tsx
436
- var TextArea = ({
437
- minRows = 3,
438
- maxRows,
439
- size = "md",
440
- customAppearance,
441
- numberOfLines,
442
- textAlignVertical,
443
- scrollEnabled,
444
- ...props
445
- }) => {
446
- const sizeStyles = useTextInputSizeStyles(size);
447
- const lineHeight = Math.round(sizeStyles.fontSize * 1.35);
448
- const verticalPadding = sizeStyles.paddingVertical * 2;
449
- const normalizedMaxRows = typeof maxRows === "number" ? Math.max(maxRows, minRows) : void 0;
450
- const minHeight = minRows * lineHeight + verticalPadding;
451
- const maxHeight = typeof normalizedMaxRows === "number" ? normalizedMaxRows * lineHeight + verticalPadding : void 0;
452
- return /* @__PURE__ */ React2.createElement(
453
- TextInput,
454
- {
455
- ...props,
456
- size,
457
- multiline: true,
458
- numberOfLines: numberOfLines ?? minRows,
459
- textAlignVertical: textAlignVertical ?? "top",
460
- scrollEnabled: scrollEnabled ?? !!maxHeight,
461
- customAppearance: {
462
- ...customAppearance,
463
- inputWrapper: [
464
- textAreaStyles.inputWrapper,
465
- {
466
- minHeight,
467
- ...maxHeight ? { maxHeight } : {}
468
- },
469
- customAppearance?.inputWrapper
470
- ],
471
- input: [
472
- textAreaStyles.input,
473
- {
474
- lineHeight
475
- },
476
- customAppearance?.input
477
- ]
478
- }
479
- }
480
- );
481
- };
482
-
483
- // src/components/input/date-time-input.tsx
484
- import React3, { forwardRef as forwardRef2, useCallback, useMemo as useMemo3 } from "react";
485
-
486
- // src/components/input/date-time-input.hook.ts
487
- var YMD_LOCALES = ["ja", "zh", "ko", "hu", "lt", "mn"];
488
- var MDY_LOCALES = ["en-US", "en-PH", "en-BZ"];
489
- var getDateOrder = (locale) => {
490
- try {
491
- const formatter = new Intl.DateTimeFormat(locale, {
492
- year: "numeric",
493
- month: "2-digit",
494
- day: "2-digit"
495
- });
496
- const parts = formatter.formatToParts(new Date(2e3, 0, 2));
497
- const order = parts.filter((p) => p.type === "year" || p.type === "month" || p.type === "day").map((p) => p.type);
498
- if (order[0] === "year") return "YMD";
499
- if (order[0] === "month") return "MDY";
500
- return "DMY";
501
- } catch {
502
- const lang = locale.split("-")[0];
503
- if (YMD_LOCALES.includes(locale) || YMD_LOCALES.includes(lang)) return "YMD";
504
- if (MDY_LOCALES.includes(locale)) return "MDY";
505
- return "DMY";
506
- }
507
- };
508
- var insertAtPositions = (digits, positions, char) => {
509
- let result = "";
510
- let digitIndex = 0;
511
- for (let i = 0; i < positions.length; i++) {
512
- const segLen = positions[i];
513
- const segment = digits.slice(digitIndex, digitIndex + segLen);
514
- if (!segment) break;
515
- if (i > 0) result += char;
516
- result += segment;
517
- digitIndex += segLen;
518
- }
519
- return result;
520
- };
521
- var formatDateInput = (text, dateOrder, separator) => {
522
- const digits = text.replace(/\D/g, "").slice(0, 8);
523
- const segments = dateOrder === "YMD" ? [4, 2, 2] : [2, 2, 4];
524
- return insertAtPositions(digits, segments, separator);
525
- };
526
- var formatTimeInput = (text, granularity, hourCycle) => {
527
- const cleaned = text.replace(/[^0-9aApPmM ]/g, "");
528
- const digits = cleaned.replace(/\D/g, "");
529
- const maxDigits = granularity === "second" ? 6 : 4;
530
- const trimmed = digits.slice(0, maxDigits);
531
- const segments = granularity === "second" ? [2, 2, 2] : [2, 2];
532
- let result = insertAtPositions(trimmed, segments, ":");
533
- if (hourCycle === 12 && trimmed.length >= 4) {
534
- const ampmMatch = cleaned.match(/[aApP][mM]?/i);
535
- if (ampmMatch) {
536
- const period = ampmMatch[0].toUpperCase().startsWith("P") ? "PM" : "AM";
537
- result += " " + period;
538
- }
539
- }
540
- return result;
541
- };
542
- var formatDateTimeInput = (text, dateOrder, separator, granularity, hourCycle) => {
543
- const digits = text.replace(/[^0-9aApPmM]/g, "").replace(/[aApPmM]/g, "");
544
- const dateDigitCount = 8;
545
- const timeDigitCount = granularity === "second" ? 6 : 4;
546
- const maxDigits = dateDigitCount + timeDigitCount;
547
- const trimmed = digits.replace(/\D/g, "").slice(0, maxDigits);
548
- const datePart = trimmed.slice(0, dateDigitCount);
549
- const timePart = trimmed.slice(dateDigitCount);
550
- let result = formatDateInput(datePart, dateOrder, separator);
551
- if (timePart) {
552
- const timeSegments = granularity === "second" ? [2, 2, 2] : [2, 2];
553
- result += " " + insertAtPositions(timePart, timeSegments, ":");
554
- if (hourCycle === 12 && timePart.length >= 4) {
555
- const ampmMatch = text.match(/[aApP][mM]?/i);
556
- if (ampmMatch) {
557
- const period = ampmMatch[0].toUpperCase().startsWith("P") ? "PM" : "AM";
558
- result += " " + period;
559
- }
560
- }
561
- }
562
- return result;
563
- };
564
- var getDatePlaceholder = (dateOrder, separator) => {
565
- const parts = {
566
- YMD: ["YYYY", "MM", "DD"],
567
- DMY: ["DD", "MM", "YYYY"],
568
- MDY: ["MM", "DD", "YYYY"]
569
- };
570
- return parts[dateOrder].join(separator);
571
- };
572
- var getTimePlaceholder = (granularity, hourCycle) => {
573
- const hour = hourCycle === 12 ? "hh" : "HH";
574
- const base = `${hour}:mm`;
575
- const withSeconds = granularity === "second" ? `${base}:ss` : base;
576
- return hourCycle === 12 ? `${withSeconds} AM` : withSeconds;
577
- };
578
- var getDateTimePlaceholder = (dateOrder, separator, granularity, hourCycle) => {
579
- return `${getDatePlaceholder(dateOrder, separator)} ${getTimePlaceholder(granularity, hourCycle)}`;
580
- };
581
- var getDateMaxLength = (separator) => {
582
- return 8 + 2 * separator.length;
583
- };
584
- var getTimeMaxLength = (granularity, hourCycle) => {
585
- const base = granularity === "second" ? 8 : 5;
586
- return hourCycle === 12 ? base + 3 : base;
587
- };
588
- var getDateTimeMaxLength = (separator, granularity, hourCycle) => {
589
- return getDateMaxLength(separator) + 1 + getTimeMaxLength(granularity, hourCycle);
590
- };
591
- var pad = (n) => String(n).padStart(2, "0");
592
- var dateInputValueToDate = (value, dateOrder, separator) => {
593
- const parts = value.split(separator);
594
- if (parts.length !== 3) return null;
595
- let year, month, day;
596
- if (dateOrder === "YMD") {
597
- year = parseInt(parts[0], 10);
598
- month = parseInt(parts[1], 10);
599
- day = parseInt(parts[2], 10);
600
- } else if (dateOrder === "MDY") {
601
- month = parseInt(parts[0], 10);
602
- day = parseInt(parts[1], 10);
603
- year = parseInt(parts[2], 10);
604
- } else {
605
- day = parseInt(parts[0], 10);
606
- month = parseInt(parts[1], 10);
607
- year = parseInt(parts[2], 10);
608
- }
609
- if (isNaN(year) || isNaN(month) || isNaN(day)) return null;
610
- const date = new Date(year, month - 1, day);
611
- if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day)
612
- return null;
613
- return date;
614
- };
615
- var dateToDateInputValue = (date, dateOrder, separator) => {
616
- const d = typeof date === "string" ? new Date(date) : date;
617
- if (isNaN(d.getTime())) return "";
618
- const year = String(d.getFullYear());
619
- const month = pad(d.getMonth() + 1);
620
- const day = pad(d.getDate());
621
- if (dateOrder === "YMD") return [year, month, day].join(separator);
622
- if (dateOrder === "MDY") return [month, day, year].join(separator);
623
- return [day, month, year].join(separator);
624
- };
625
- var timeInputValueToDate = (value, options = {}) => {
626
- const { hourCycle = 24 } = options;
627
- const isPM = /pm$/i.test(value);
628
- const isAM = /am$/i.test(value);
629
- const cleaned = value.replace(/\s*(am|pm)$/i, "").trim();
630
- const segments = cleaned.split(":");
631
- let hours = parseInt(segments[0], 10);
632
- const minutes = parseInt(segments[1] ?? "0", 10);
633
- const seconds = parseInt(segments[2] ?? "0", 10);
634
- if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) return null;
635
- if (hourCycle === 12) {
636
- if (isPM && hours !== 12) hours += 12;
637
- if (isAM && hours === 12) hours = 0;
638
- }
639
- const date = /* @__PURE__ */ new Date();
640
- date.setHours(hours, minutes, seconds, 0);
641
- return date;
642
- };
643
- var dateToTimeInputValue = (date, options = {}) => {
644
- const { granularity = "minute", hourCycle = 24 } = options;
645
- const d = typeof date === "string" ? new Date(date) : date;
646
- if (isNaN(d.getTime())) return "";
647
- let hours = d.getHours();
648
- const minutes = pad(d.getMinutes());
649
- const seconds = pad(d.getSeconds());
650
- if (hourCycle === 12) {
651
- const period = hours >= 12 ? "PM" : "AM";
652
- hours = hours % 12 || 12;
653
- const base2 = `${pad(hours)}:${minutes}`;
654
- return granularity === "second" ? `${base2}:${seconds} ${period}` : `${base2} ${period}`;
655
- }
656
- const base = `${pad(hours)}:${minutes}`;
657
- return granularity === "second" ? `${base}:${seconds}` : base;
658
- };
659
- var dateTimeInputValueToDate = (value, dateOrder, options = {}) => {
660
- const { separator = "-", hourCycle = 24 } = options;
661
- const spaceIndex = value.indexOf(" ");
662
- if (spaceIndex === -1) return null;
663
- const date = dateInputValueToDate(value.slice(0, spaceIndex), dateOrder, separator);
664
- if (!date) return null;
665
- const timePart = value.slice(spaceIndex + 1);
666
- const timed = timeInputValueToDate(timePart, { hourCycle });
667
- if (!timed) return null;
668
- date.setHours(timed.getHours(), timed.getMinutes(), timed.getSeconds(), 0);
669
- return date;
670
- };
671
- var dateToDateTimeInputValue = (date, dateOrder, options = {}) => {
672
- const { separator = "-", granularity = "minute", hourCycle = 24 } = options;
673
- const d = typeof date === "string" ? new Date(date) : date;
674
- if (isNaN(d.getTime())) return "";
675
- const datePart = dateToDateInputValue(d, dateOrder, separator);
676
- const timePart = dateToTimeInputValue(d, { granularity, hourCycle });
677
- return `${datePart} ${timePart}`;
678
- };
679
-
680
- // src/components/input/date-time-input.tsx
681
- var DateInput = forwardRef2(
682
- ({
683
- separator = "-",
684
- dateOrder,
685
- locale = "en-US",
686
- placeholder,
687
- maxLength,
688
- onChangeText,
689
- onValueChange,
690
- ...props
691
- }, ref) => {
692
- const resolvedOrder = useMemo3(
693
- () => dateOrder ?? getDateOrder(locale),
694
- [dateOrder, locale]
695
- );
696
- const handleChangeText = useCallback(
697
- (text) => {
698
- const formatted = formatDateInput(text, resolvedOrder, separator);
699
- onChangeText?.(formatted);
700
- onValueChange?.(formatted);
701
- },
702
- [resolvedOrder, separator, onChangeText, onValueChange]
703
- );
704
- return /* @__PURE__ */ React3.createElement(
705
- TextInput,
706
- {
707
- ref,
708
- placeholder: placeholder ?? getDatePlaceholder(resolvedOrder, separator),
709
- keyboardType: "number-pad",
710
- autoCapitalize: "none",
711
- autoCorrect: false,
712
- maxLength: maxLength ?? getDateMaxLength(separator),
713
- onChangeText: handleChangeText,
714
- ...props
715
- }
716
- );
717
- }
718
- );
719
- var TimeInput = forwardRef2(
720
- ({
721
- granularity = "minute",
722
- hourCycle = 24,
723
- placeholder,
724
- maxLength,
725
- onChangeText,
726
- onValueChange,
727
- ...props
728
- }, ref) => {
729
- const handleChangeText = useCallback(
730
- (text) => {
731
- const formatted = formatTimeInput(text, granularity, hourCycle);
732
- onChangeText?.(formatted);
733
- onValueChange?.(formatted);
734
- },
735
- [granularity, hourCycle, onChangeText, onValueChange]
736
- );
737
- return /* @__PURE__ */ React3.createElement(
738
- TextInput,
739
- {
740
- ref,
741
- placeholder: placeholder ?? getTimePlaceholder(granularity, hourCycle),
742
- keyboardType: "number-pad",
743
- autoCapitalize: "none",
744
- autoCorrect: false,
745
- maxLength: maxLength ?? getTimeMaxLength(granularity, hourCycle),
746
- onChangeText: handleChangeText,
747
- ...props
748
- }
749
- );
750
- }
751
- );
752
- var DateTimeInput = forwardRef2(
753
- ({
754
- separator = "-",
755
- dateOrder,
756
- locale = "en-US",
757
- granularity = "minute",
758
- hourCycle = 24,
759
- placeholder,
760
- maxLength,
761
- onChangeText,
762
- onValueChange,
763
- ...props
764
- }, ref) => {
765
- const resolvedOrder = useMemo3(
766
- () => dateOrder ?? getDateOrder(locale),
767
- [dateOrder, locale]
768
- );
769
- const handleChangeText = useCallback(
770
- (text) => {
771
- const formatted = formatDateTimeInput(
772
- text,
773
- resolvedOrder,
774
- separator,
775
- granularity,
776
- hourCycle
777
- );
778
- onChangeText?.(formatted);
779
- onValueChange?.(formatted);
780
- },
781
- [resolvedOrder, separator, granularity, hourCycle, onChangeText, onValueChange]
782
- );
783
- return /* @__PURE__ */ React3.createElement(
784
- TextInput,
785
- {
786
- ref,
787
- placeholder: placeholder ?? getDateTimePlaceholder(resolvedOrder, separator, granularity, hourCycle),
788
- keyboardType: "number-pad",
789
- autoCapitalize: "none",
790
- autoCorrect: false,
791
- maxLength: maxLength ?? getDateTimeMaxLength(separator, granularity, hourCycle),
792
- onChangeText: handleChangeText,
793
- ...props
794
- }
795
- );
796
- }
797
- );
798
- DateInput.displayName = "DateInput";
799
- TimeInput.displayName = "TimeInput";
800
- DateTimeInput.displayName = "DateTimeInput";
801
-
802
- // src/components/input/otp-input.tsx
803
- import React4, { useCallback as useCallback3, useEffect as useEffect2, useRef as useRef3 } from "react";
804
- import {
805
- Animated as Animated2,
806
- Pressable as Pressable2,
807
- Text as Text2,
808
- TextInput as RNTextInput2,
809
- View as View2
810
- } from "react-native";
811
- import { withOpacity as withOpacity2 } from "@xaui/core";
812
-
813
- // src/components/input/otp-input.hook.ts
814
- import { useCallback as useCallback2, useMemo as useMemo4, useRef as useRef2, useState as useState2 } from "react";
815
- var segmentSizeMap = {
816
- sm: { width: 40, height: 40, fontSize: 16 },
817
- md: { width: 48, height: 48, fontSize: 20 },
818
- lg: { width: 56, height: 56, fontSize: 24 }
819
- };
820
- var useOTPSegmentSizeStyles = (size) => {
821
- return useMemo4(() => segmentSizeMap[size], [size]);
822
- };
823
- var useOTPInputState = ({
824
- length,
825
- value,
826
- defaultValue,
827
- onValueChange,
828
- onComplete,
829
- allowedKeys
830
- }) => {
831
- const isControlled = typeof value === "string";
832
- const [internalValue, setInternalValue] = useState2(defaultValue ?? "");
833
- const [activeIndex, setActiveIndex] = useState2(-1);
834
- const refs = useRef2([]);
835
- const currentValue = isControlled ? value : internalValue;
836
- const segments = useMemo4(() => {
837
- const chars = currentValue.split("");
838
- return Array.from({ length }, (_, i) => chars[i] ?? "");
839
- }, [currentValue, length]);
840
- const updateValue = useCallback2(
841
- (newValue) => {
842
- if (!isControlled) {
843
- setInternalValue(newValue);
844
- }
845
- onValueChange?.(newValue);
846
- if (newValue.length === length) {
847
- onComplete?.(newValue);
848
- }
849
- },
850
- [isControlled, length, onValueChange, onComplete]
851
- );
852
- const handleSegmentChange = useCallback2(
853
- (index, text) => {
854
- if (!text) return;
855
- const char = text.slice(-1);
856
- if (!allowedKeys.test(char)) return;
857
- const chars = currentValue.split("");
858
- while (chars.length < length) chars.push("");
859
- chars[index] = char;
860
- const newValue = chars.join("").replace(/\s+$/, "");
861
- updateValue(newValue);
862
- if (index < length - 1) {
863
- refs.current[index + 1]?.focus();
864
- }
865
- },
866
- [allowedKeys, currentValue, length, updateValue]
867
- );
868
- const handleSegmentKeyPress = useCallback2(
869
- (index, key) => {
870
- if (key !== "Backspace") return;
871
- const chars = currentValue.split("");
872
- while (chars.length < length) chars.push("");
873
- if (chars[index]) {
874
- chars[index] = "";
875
- updateValue(chars.join("").replace(/\s+$/, ""));
876
- return;
877
- }
878
- if (index > 0) {
879
- chars[index - 1] = "";
880
- updateValue(chars.join("").replace(/\s+$/, ""));
881
- refs.current[index - 1]?.focus();
882
- }
883
- },
884
- [currentValue, length, updateValue]
885
- );
886
- const handleSegmentFocus = useCallback2((index) => {
887
- setActiveIndex(index);
888
- }, []);
889
- const handleSegmentBlur = useCallback2(() => {
890
- setActiveIndex(-1);
891
- }, []);
892
- return {
893
- segments,
894
- activeIndex,
895
- refs,
896
- handleSegmentChange,
897
- handleSegmentKeyPress,
898
- handleSegmentFocus,
899
- handleSegmentBlur
900
- };
901
- };
902
-
903
- // src/components/input/otp-input.style.ts
904
- import { StyleSheet as StyleSheet3 } from "react-native";
905
- var otpStyles = StyleSheet3.create({
906
- container: {
907
- gap: 6
908
- },
909
- fullWidth: {
910
- width: "100%"
911
- },
912
- segmentContainer: {
913
- flexDirection: "row",
914
- gap: 8
915
- },
916
- segment: {
917
- justifyContent: "center",
918
- alignItems: "center",
919
- overflow: "hidden"
920
- },
921
- segmentText: {
922
- fontWeight: "600",
923
- textAlign: "center"
924
- },
925
- securedDot: {
926
- width: 10,
927
- height: 10,
928
- borderRadius: 5
929
- },
930
- hiddenInput: {
931
- position: "absolute",
932
- width: 1,
933
- height: 1,
934
- opacity: 0
935
- },
936
- underline: {
937
- position: "absolute",
938
- left: 0,
939
- right: 0,
940
- bottom: 0
941
- },
942
- label: {
943
- fontWeight: "500"
944
- },
945
- helperText: {
946
- fontWeight: "400"
947
- },
948
- disabled: {
949
- opacity: 0.6
950
- }
951
- });
952
-
953
- // src/components/input/otp-input.tsx
954
- var OTPSegment = ({
955
- char,
956
- isActive,
957
- isSecured,
958
- isDisabled,
959
- variantStyles,
960
- sizeStyles,
961
- radiusStyles,
962
- customSegment,
963
- customSegmentText,
964
- inputRef,
965
- onChangeText,
966
- onKeyPress,
967
- onFocus,
968
- onBlur,
969
- onPress
970
- }) => {
971
- const borderAnimation = useRef3(new Animated2.Value(0)).current;
972
- const isUnderlined = variantStyles.container.borderBottomWidth !== void 0;
973
- useEffect2(() => {
974
- Animated2.timing(borderAnimation, {
975
- toValue: isActive ? 1 : 0,
976
- duration: 200,
977
- useNativeDriver: false
978
- }).start();
979
- }, [borderAnimation, isActive]);
980
- const unfocusedLineColor = isUnderlined ? withOpacity2(variantStyles.focusedBorderColor, 0.35) : variantStyles.unfocusedBorderColor;
981
- const animatedBorderColor = borderAnimation.interpolate({
982
- inputRange: [0, 1],
983
- outputRange: [unfocusedLineColor, variantStyles.focusedBorderColor]
984
- });
985
- return /* @__PURE__ */ React4.createElement(
986
- Pressable2,
987
- {
988
- onPress: () => {
989
- if (!isDisabled) {
990
- onPress();
991
- }
992
- },
993
- disabled: isDisabled
994
- },
995
- /* @__PURE__ */ React4.createElement(
996
- Animated2.View,
997
- {
998
- style: [
999
- otpStyles.segment,
1000
- {
1001
- width: sizeStyles.width,
1002
- height: sizeStyles.height,
1003
- backgroundColor: variantStyles.container.backgroundColor,
1004
- borderRadius: isUnderlined ? 0 : radiusStyles.borderRadius,
1005
- borderWidth: isUnderlined ? 0 : variantStyles.container.borderWidth ?? 0,
1006
- borderColor: isUnderlined ? void 0 : animatedBorderColor
1007
- },
1008
- customSegment?.segment
1009
- ]
1010
- },
1011
- char && isSecured ? /* @__PURE__ */ React4.createElement(
1012
- View2,
1013
- {
1014
- style: [
1015
- otpStyles.securedDot,
1016
- { backgroundColor: variantStyles.textColor }
1017
- ]
1018
- }
1019
- ) : /* @__PURE__ */ React4.createElement(
1020
- Text2,
1021
- {
1022
- style: [
1023
- otpStyles.segmentText,
1024
- {
1025
- color: variantStyles.textColor,
1026
- fontSize: sizeStyles.fontSize
1027
- },
1028
- customSegmentText?.segmentText
1029
- ]
1030
- },
1031
- char
1032
- ),
1033
- /* @__PURE__ */ React4.createElement(
1034
- RNTextInput2,
1035
- {
1036
- ref: inputRef,
1037
- style: otpStyles.hiddenInput,
1038
- value: char,
1039
- onChangeText,
1040
- onKeyPress: (e) => onKeyPress(e.nativeEvent.key),
1041
- onFocus,
1042
- onBlur,
1043
- maxLength: 2,
1044
- keyboardType: "number-pad",
1045
- editable: !isDisabled,
1046
- caretHidden: true
1047
- }
1048
- ),
1049
- isUnderlined && /* @__PURE__ */ React4.createElement(
1050
- Animated2.View,
1051
- {
1052
- style: [
1053
- otpStyles.underline,
1054
- {
1055
- height: variantStyles.container.borderBottomWidth ?? 1,
1056
- backgroundColor: animatedBorderColor
1057
- }
1058
- ]
1059
- }
1060
- )
1061
- )
1062
- );
1063
- };
1064
- var OTPInput = ({
1065
- length = 4,
1066
- value,
1067
- defaultValue,
1068
- onValueChange,
1069
- onComplete,
1070
- variant = "colored",
1071
- size = "md",
1072
- radius = "md",
1073
- themeColor = "primary",
1074
- isDisabled = false,
1075
- isInvalid = false,
1076
- isSecured = false,
1077
- errorMessage,
1078
- description,
1079
- label,
1080
- allowedKeys = /^[0-9]$/,
1081
- customAppearance,
1082
- fullWidth = false
1083
- }) => {
1084
- const sizeStyles = useOTPSegmentSizeStyles(size);
1085
- const radiusStyles = useTextInputRadiusStyles(radius);
1086
- const variantStyles = useTextInputVariantStyles({
1087
- themeColor,
1088
- variant,
1089
- isFocused: false,
1090
- isInvalid,
1091
- isDisabled
1092
- });
1093
- const {
1094
- segments,
1095
- activeIndex,
1096
- refs,
1097
- handleSegmentChange,
1098
- handleSegmentKeyPress,
1099
- handleSegmentFocus,
1100
- handleSegmentBlur
1101
- } = useOTPInputState({
1102
- length,
1103
- value,
1104
- defaultValue,
1105
- onValueChange,
1106
- onComplete,
1107
- allowedKeys
1108
- });
1109
- const helperText = isInvalid && errorMessage ? errorMessage : description;
1110
- const helperColor = isInvalid ? variantStyles.helperColor : variantStyles.helperColor;
1111
- const activeVariantStyles = useTextInputVariantStyles({
1112
- themeColor,
1113
- variant,
1114
- isFocused: true,
1115
- isInvalid,
1116
- isDisabled
1117
- });
1118
- const focusSegment = useCallback3(
1119
- (index) => {
1120
- if (isDisabled) return;
1121
- refs.current[index]?.focus();
1122
- },
1123
- [isDisabled, refs]
1124
- );
1125
- const handleContainerPress = useCallback3(() => {
1126
- const firstEmptyIndex = segments.findIndex((segment) => !segment);
1127
- const targetIndex = firstEmptyIndex === -1 ? length - 1 : firstEmptyIndex;
1128
- focusSegment(targetIndex);
1129
- }, [focusSegment, length, segments]);
1130
- return /* @__PURE__ */ React4.createElement(
1131
- View2,
1132
- {
1133
- style: [
1134
- otpStyles.container,
1135
- fullWidth && otpStyles.fullWidth,
1136
- isDisabled && otpStyles.disabled,
1137
- customAppearance?.container
1138
- ]
1139
- },
1140
- label && /* @__PURE__ */ React4.createElement(
1141
- Text2,
1142
- {
1143
- style: [
1144
- otpStyles.label,
1145
- {
1146
- color: variantStyles.labelColor,
1147
- fontSize: 14
1148
- },
1149
- customAppearance?.label
1150
- ]
1151
- },
1152
- label
1153
- ),
1154
- /* @__PURE__ */ React4.createElement(
1155
- Pressable2,
1156
- {
1157
- onPress: handleContainerPress,
1158
- disabled: isDisabled,
1159
- style: [otpStyles.segmentContainer, customAppearance?.segmentContainer]
1160
- },
1161
- segments.map((char, index) => /* @__PURE__ */ React4.createElement(
1162
- OTPSegment,
1163
- {
1164
- key: index,
1165
- char,
1166
- isActive: activeIndex === index,
1167
- isSecured,
1168
- isDisabled,
1169
- variantStyles: activeIndex === index ? activeVariantStyles : variantStyles,
1170
- sizeStyles,
1171
- radiusStyles,
1172
- customSegment: customAppearance,
1173
- customSegmentText: customAppearance,
1174
- inputRef: (ref) => {
1175
- refs.current[index] = ref;
1176
- },
1177
- onChangeText: (text) => handleSegmentChange(index, text),
1178
- onKeyPress: (key) => handleSegmentKeyPress(index, key),
1179
- onFocus: () => handleSegmentFocus(index),
1180
- onBlur: handleSegmentBlur,
1181
- onPress: () => focusSegment(index)
1182
- }
1183
- ))
1184
- ),
1185
- helperText && /* @__PURE__ */ React4.createElement(
1186
- Text2,
1187
- {
1188
- style: [
1189
- otpStyles.helperText,
1190
- { color: helperColor, fontSize: 13 },
1191
- customAppearance?.helperText
1192
- ]
1193
- },
1194
- helperText
1195
- )
1196
- );
1197
- };
1198
- OTPInput.displayName = "OTPInput";
1199
-
1200
- // src/components/input/number-input.tsx
1201
- import React5, { forwardRef as forwardRef3 } from "react";
1202
- import { Pressable as Pressable3, View as View3 } from "react-native";
1203
- import { AddIcon, RemoveIcon } from "@xaui/icons";
1204
- import { withOpacity as withOpacity3 } from "@xaui/core";
1205
-
1206
- // src/components/input/number-input.hook.ts
1207
- import { useCallback as useCallback4, useMemo as useMemo5, useState as useState3 } from "react";
1208
- var useNumberInputState = ({
1209
- value,
1210
- defaultValue,
1211
- onValueChange,
1212
- minValue,
1213
- maxValue,
1214
- step,
1215
- formatOptions,
1216
- locale
1217
- }) => {
1218
- const isControlled = typeof value === "number";
1219
- const [internalValue, setInternalValue] = useState3(
1220
- defaultValue
1221
- );
1222
- const [isEditing, setIsEditing] = useState3(false);
1223
- const [rawText, setRawText] = useState3("");
1224
- const currentValue = isControlled ? value : internalValue;
1225
- const formatter = useMemo5(() => {
1226
- if (!formatOptions) return null;
1227
- return new Intl.NumberFormat(locale, formatOptions);
1228
- }, [formatOptions, locale]);
1229
- const displayValue = useMemo5(() => {
1230
- if (isEditing) return rawText;
1231
- if (currentValue === void 0) return "";
1232
- if (formatter) return formatter.format(currentValue);
1233
- return String(currentValue);
1234
- }, [currentValue, formatter, isEditing, rawText]);
1235
- const updateValue = useCallback4(
1236
- (newValue) => {
1237
- if (!isControlled) {
1238
- setInternalValue(newValue);
1239
- }
1240
- onValueChange?.(newValue);
1241
- },
1242
- [isControlled, onValueChange]
1243
- );
1244
- const clamp = useCallback4(
1245
- (num) => {
1246
- let clamped = num;
1247
- if (minValue !== void 0 && clamped < minValue) clamped = minValue;
1248
- if (maxValue !== void 0 && clamped > maxValue) clamped = maxValue;
1249
- return clamped;
1250
- },
1251
- [minValue, maxValue]
1252
- );
1253
- const handleTextChange = useCallback4(
1254
- (text) => {
1255
- setRawText(text);
1256
- if (text === "" || text === "-") return;
1257
- const parsed = parseFloat(text);
1258
- if (isNaN(parsed)) return;
1259
- updateValue(parsed);
1260
- },
1261
- [updateValue]
1262
- );
1263
- const handleFocus = useCallback4(() => {
1264
- setIsEditing(true);
1265
- setRawText(currentValue !== void 0 ? String(currentValue) : "");
1266
- }, [currentValue]);
1267
- const handleBlur = useCallback4(() => {
1268
- setIsEditing(false);
1269
- if (rawText === "" || rawText === "-") {
1270
- updateValue(void 0);
1271
- return;
1272
- }
1273
- const parsed = parseFloat(rawText);
1274
- if (isNaN(parsed)) {
1275
- updateValue(void 0);
1276
- return;
1277
- }
1278
- updateValue(clamp(parsed));
1279
- }, [rawText, clamp, updateValue]);
1280
- const handleClear = useCallback4(() => {
1281
- setRawText("");
1282
- updateValue(void 0);
1283
- }, [updateValue]);
1284
- const canIncrement = maxValue === void 0 || (currentValue ?? 0) + step <= maxValue;
1285
- const canDecrement = minValue === void 0 || (currentValue ?? 0) - step >= minValue;
1286
- const handleIncrement = useCallback4(() => {
1287
- const base = currentValue ?? 0;
1288
- const newValue = clamp(base + step);
1289
- updateValue(newValue);
1290
- }, [currentValue, step, clamp, updateValue]);
1291
- const handleDecrement = useCallback4(() => {
1292
- const base = currentValue ?? 0;
1293
- const newValue = clamp(base - step);
1294
- updateValue(newValue);
1295
- }, [currentValue, step, clamp, updateValue]);
1296
- return {
1297
- displayValue,
1298
- handleTextChange,
1299
- handleFocus,
1300
- handleBlur,
1301
- handleClear,
1302
- handleIncrement,
1303
- handleDecrement,
1304
- canIncrement,
1305
- canDecrement
1306
- };
1307
- };
1308
-
1309
- // src/components/input/number-input.style.ts
1310
- import { StyleSheet as StyleSheet4 } from "react-native";
1311
- var numberInputStyles = StyleSheet4.create({
1312
- stepperContainer: {
1313
- flexDirection: "row",
1314
- alignItems: "center",
1315
- gap: 4
1316
- },
1317
- stepperButton: {
1318
- justifyContent: "center",
1319
- alignItems: "center",
1320
- width: 28,
1321
- height: 28,
1322
- borderRadius: 6
1323
- },
1324
- stepperDisabled: {
1325
- opacity: 0.4
1326
- }
1327
- });
1328
-
1329
- // src/components/input/number-input.tsx
1330
- var NumberInput = forwardRef3(
1331
- ({
1332
- value,
1333
- defaultValue,
1334
- onValueChange,
1335
- minValue,
1336
- maxValue,
1337
- step = 1,
1338
- hideStepper = false,
1339
- formatOptions,
1340
- locale = "en-US",
1341
- label,
1342
- labelPlacement = "outside",
1343
- description,
1344
- errorMessage,
1345
- placeholder,
1346
- themeColor = "primary",
1347
- variant = "colored",
1348
- size = "md",
1349
- radius = "md",
1350
- isDisabled = false,
1351
- isReadOnly = false,
1352
- isInvalid = false,
1353
- isClearable = false,
1354
- fullWidth = true,
1355
- customAppearance
1356
- }, ref) => {
1357
- const theme = useXUITheme();
1358
- const {
1359
- displayValue,
1360
- handleTextChange,
1361
- handleFocus,
1362
- handleBlur,
1363
- handleIncrement,
1364
- handleDecrement,
1365
- canIncrement,
1366
- canDecrement
1367
- } = useNumberInputState({
1368
- value,
1369
- defaultValue,
1370
- onValueChange,
1371
- minValue,
1372
- maxValue,
1373
- step,
1374
- formatOptions,
1375
- locale
1376
- });
1377
- const iconColor = withOpacity3(theme.colors.foreground, 0.7);
1378
- const stepperContent = hideStepper || isReadOnly ? void 0 : /* @__PURE__ */ React5.createElement(
1379
- View3,
1380
- {
1381
- style: [
1382
- numberInputStyles.stepperContainer,
1383
- customAppearance?.stepperContainer
1384
- ]
1385
- },
1386
- /* @__PURE__ */ React5.createElement(
1387
- Pressable3,
1388
- {
1389
- onPress: handleDecrement,
1390
- disabled: isDisabled || !canDecrement,
1391
- accessibilityLabel: "Decrease value",
1392
- accessibilityRole: "button",
1393
- style: [
1394
- numberInputStyles.stepperButton,
1395
- (!canDecrement || isDisabled) && numberInputStyles.stepperDisabled,
1396
- customAppearance?.stepperButton
1397
- ]
1398
- },
1399
- /* @__PURE__ */ React5.createElement(RemoveIcon, { size: 16, color: iconColor })
1400
- ),
1401
- /* @__PURE__ */ React5.createElement(
1402
- Pressable3,
1403
- {
1404
- onPress: handleIncrement,
1405
- disabled: isDisabled || !canIncrement,
1406
- accessibilityLabel: "Increase value",
1407
- accessibilityRole: "button",
1408
- style: [
1409
- numberInputStyles.stepperButton,
1410
- (!canIncrement || isDisabled) && numberInputStyles.stepperDisabled,
1411
- customAppearance?.stepperButton
1412
- ]
1413
- },
1414
- /* @__PURE__ */ React5.createElement(AddIcon, { size: 16, color: iconColor })
1415
- )
1416
- );
1417
- return /* @__PURE__ */ React5.createElement(
1418
- TextInput,
1419
- {
1420
- ref,
1421
- value: displayValue,
1422
- onChangeText: handleTextChange,
1423
- onFocus: handleFocus,
1424
- onBlur: handleBlur,
1425
- label,
1426
- labelPlacement,
1427
- description,
1428
- errorMessage,
1429
- placeholder,
1430
- themeColor,
1431
- variant,
1432
- size,
1433
- radius,
1434
- isDisabled,
1435
- isReadOnly,
1436
- isInvalid,
1437
- isClearable,
1438
- fullWidth,
1439
- keyboardType: "numeric",
1440
- endContent: stepperContent,
1441
- customAppearance
1442
- }
1443
- );
1444
- }
1445
- );
1446
- NumberInput.displayName = "NumberInput";
1447
- export {
1448
- DateInput,
1449
- DateTimeInput,
1450
- NumberInput,
1451
- OTPInput,
1452
- TextArea,
1453
- TextInput,
1454
- TimeInput,
1455
- dateInputValueToDate,
1456
- dateTimeInputValueToDate,
1457
- dateToDateInputValue,
1458
- dateToDateTimeInputValue,
1459
- dateToTimeInputValue,
1460
- getDateOrder,
1461
- timeInputValueToDate
1462
- };