react-native-mantine 0.6.0 → 0.8.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 (225) hide show
  1. package/README.md +38 -6
  2. package/lib/commonjs/components/Anchor/index.js +6 -1
  3. package/lib/commonjs/components/Anchor/index.js.map +1 -1
  4. package/lib/commonjs/components/Badge/index.js +12 -13
  5. package/lib/commonjs/components/Badge/index.js.map +1 -1
  6. package/lib/commonjs/components/Blockquote/index.js +8 -12
  7. package/lib/commonjs/components/Blockquote/index.js.map +1 -1
  8. package/lib/commonjs/components/Button/index.js +5 -6
  9. package/lib/commonjs/components/Button/index.js.map +1 -1
  10. package/lib/commonjs/components/Chip/index.js +8 -9
  11. package/lib/commonjs/components/Chip/index.js.map +1 -1
  12. package/lib/commonjs/components/Code/index.js +13 -8
  13. package/lib/commonjs/components/Code/index.js.map +1 -1
  14. package/lib/commonjs/components/Group/index.js.map +1 -1
  15. package/lib/commonjs/components/Kbd/index.js +7 -8
  16. package/lib/commonjs/components/Kbd/index.js.map +1 -1
  17. package/lib/commonjs/components/List/index.js +6 -5
  18. package/lib/commonjs/components/List/index.js.map +1 -1
  19. package/lib/commonjs/components/Mark/index.js +4 -0
  20. package/lib/commonjs/components/Mark/index.js.map +1 -1
  21. package/lib/commonjs/components/Menu/index.js +12 -15
  22. package/lib/commonjs/components/Menu/index.js.map +1 -1
  23. package/lib/commonjs/components/NavLink/index.js +7 -11
  24. package/lib/commonjs/components/NavLink/index.js.map +1 -1
  25. package/lib/commonjs/components/Notification/index.js +5 -15
  26. package/lib/commonjs/components/Notification/index.js.map +1 -1
  27. package/lib/commonjs/components/Radio/index.js +62 -6
  28. package/lib/commonjs/components/Radio/index.js.map +1 -1
  29. package/lib/commonjs/components/Table/Table.example.js +131 -0
  30. package/lib/commonjs/components/Table/Table.example.js.map +1 -0
  31. package/lib/commonjs/components/Table/index.js +69 -15
  32. package/lib/commonjs/components/Table/index.js.map +1 -1
  33. package/lib/commonjs/components/Title/index.js +4 -0
  34. package/lib/commonjs/components/Title/index.js.map +1 -1
  35. package/lib/commonjs/hooks/index.js +28 -0
  36. package/lib/commonjs/hooks/index.js.map +1 -0
  37. package/lib/commonjs/hooks/use-form/index.js +40 -0
  38. package/lib/commonjs/hooks/use-form/index.js.map +1 -0
  39. package/lib/commonjs/hooks/use-form/types.js +2 -0
  40. package/lib/commonjs/hooks/use-form/types.js.map +1 -0
  41. package/lib/commonjs/hooks/use-form/useForm.js +418 -0
  42. package/lib/commonjs/hooks/use-form/useForm.js.map +1 -0
  43. package/lib/commonjs/hooks/use-form/validators.js +135 -0
  44. package/lib/commonjs/hooks/use-form/validators.js.map +1 -0
  45. package/lib/commonjs/index.js +11 -0
  46. package/lib/commonjs/index.js.map +1 -1
  47. package/lib/commonjs/theme/utils/index.js +26 -0
  48. package/lib/commonjs/theme/utils/index.js.map +1 -0
  49. package/lib/commonjs/theme/utils/withTextWrapper.js +49 -0
  50. package/lib/commonjs/theme/utils/withTextWrapper.js.map +1 -0
  51. package/lib/module/components/Anchor/index.js +6 -1
  52. package/lib/module/components/Anchor/index.js.map +1 -1
  53. package/lib/module/components/Badge/index.js +5 -6
  54. package/lib/module/components/Badge/index.js.map +1 -1
  55. package/lib/module/components/Blockquote/index.js +6 -10
  56. package/lib/module/components/Blockquote/index.js.map +1 -1
  57. package/lib/module/components/Button/index.js +5 -6
  58. package/lib/module/components/Button/index.js.map +1 -1
  59. package/lib/module/components/Chip/index.js +5 -6
  60. package/lib/module/components/Chip/index.js.map +1 -1
  61. package/lib/module/components/Code/index.js +13 -8
  62. package/lib/module/components/Code/index.js.map +1 -1
  63. package/lib/module/components/Group/index.js.map +1 -1
  64. package/lib/module/components/Kbd/index.js +5 -6
  65. package/lib/module/components/Kbd/index.js.map +1 -1
  66. package/lib/module/components/List/index.js +6 -5
  67. package/lib/module/components/List/index.js.map +1 -1
  68. package/lib/module/components/Mark/index.js +4 -0
  69. package/lib/module/components/Mark/index.js.map +1 -1
  70. package/lib/module/components/Menu/index.js +7 -10
  71. package/lib/module/components/Menu/index.js.map +1 -1
  72. package/lib/module/components/NavLink/index.js +5 -9
  73. package/lib/module/components/NavLink/index.js.map +1 -1
  74. package/lib/module/components/Notification/index.js +5 -15
  75. package/lib/module/components/Notification/index.js.map +1 -1
  76. package/lib/module/components/Radio/index.js +64 -8
  77. package/lib/module/components/Radio/index.js.map +1 -1
  78. package/lib/module/components/Table/Table.example.js +128 -0
  79. package/lib/module/components/Table/Table.example.js.map +1 -0
  80. package/lib/module/components/Table/index.js +70 -16
  81. package/lib/module/components/Table/index.js.map +1 -1
  82. package/lib/module/components/Title/index.js +4 -0
  83. package/lib/module/components/Title/index.js.map +1 -1
  84. package/lib/module/hooks/index.js +5 -0
  85. package/lib/module/hooks/index.js.map +1 -0
  86. package/lib/module/hooks/use-form/index.js +6 -0
  87. package/lib/module/hooks/use-form/index.js.map +1 -0
  88. package/lib/module/hooks/use-form/types.js +2 -0
  89. package/lib/module/hooks/use-form/types.js.map +1 -0
  90. package/lib/module/hooks/use-form/useForm.js +414 -0
  91. package/lib/module/hooks/use-form/useForm.js.map +1 -0
  92. package/lib/module/hooks/use-form/validators.js +122 -0
  93. package/lib/module/hooks/use-form/validators.js.map +1 -0
  94. package/lib/module/index.js +1 -0
  95. package/lib/module/index.js.map +1 -1
  96. package/lib/module/theme/utils/index.js +5 -0
  97. package/lib/module/theme/utils/index.js.map +1 -0
  98. package/lib/module/theme/utils/withTextWrapper.js +45 -0
  99. package/lib/module/theme/utils/withTextWrapper.js.map +1 -0
  100. package/lib/typescript/commonjs/src/components/Anchor/index.d.ts +2 -1
  101. package/lib/typescript/commonjs/src/components/Anchor/index.d.ts.map +1 -1
  102. package/lib/typescript/commonjs/src/components/Badge/index.d.ts +2 -1
  103. package/lib/typescript/commonjs/src/components/Badge/index.d.ts.map +1 -1
  104. package/lib/typescript/commonjs/src/components/Blockquote/index.d.ts +2 -1
  105. package/lib/typescript/commonjs/src/components/Blockquote/index.d.ts.map +1 -1
  106. package/lib/typescript/commonjs/src/components/Button/index.d.ts +2 -2
  107. package/lib/typescript/commonjs/src/components/Button/index.d.ts.map +1 -1
  108. package/lib/typescript/commonjs/src/components/Chip/index.d.ts +2 -1
  109. package/lib/typescript/commonjs/src/components/Chip/index.d.ts.map +1 -1
  110. package/lib/typescript/commonjs/src/components/Code/index.d.ts +2 -1
  111. package/lib/typescript/commonjs/src/components/Code/index.d.ts.map +1 -1
  112. package/lib/typescript/commonjs/src/components/Group/index.d.ts +1 -0
  113. package/lib/typescript/commonjs/src/components/Group/index.d.ts.map +1 -1
  114. package/lib/typescript/commonjs/src/components/Kbd/index.d.ts +2 -1
  115. package/lib/typescript/commonjs/src/components/Kbd/index.d.ts.map +1 -1
  116. package/lib/typescript/commonjs/src/components/List/index.d.ts +2 -1
  117. package/lib/typescript/commonjs/src/components/List/index.d.ts.map +1 -1
  118. package/lib/typescript/commonjs/src/components/Mark/index.d.ts +2 -1
  119. package/lib/typescript/commonjs/src/components/Mark/index.d.ts.map +1 -1
  120. package/lib/typescript/commonjs/src/components/Menu/index.d.ts +3 -2
  121. package/lib/typescript/commonjs/src/components/Menu/index.d.ts.map +1 -1
  122. package/lib/typescript/commonjs/src/components/NavLink/index.d.ts +2 -1
  123. package/lib/typescript/commonjs/src/components/NavLink/index.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/src/components/Notification/index.d.ts +2 -1
  125. package/lib/typescript/commonjs/src/components/Notification/index.d.ts.map +1 -1
  126. package/lib/typescript/commonjs/src/components/Radio/index.d.ts +22 -1
  127. package/lib/typescript/commonjs/src/components/Radio/index.d.ts.map +1 -1
  128. package/lib/typescript/commonjs/src/components/Table/Table.example.d.ts +3 -0
  129. package/lib/typescript/commonjs/src/components/Table/Table.example.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/src/components/Table/index.d.ts +7 -2
  131. package/lib/typescript/commonjs/src/components/Table/index.d.ts.map +1 -1
  132. package/lib/typescript/commonjs/src/components/Title/index.d.ts +2 -1
  133. package/lib/typescript/commonjs/src/components/Title/index.d.ts.map +1 -1
  134. package/lib/typescript/commonjs/src/hooks/index.d.ts +3 -0
  135. package/lib/typescript/commonjs/src/hooks/index.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/src/hooks/use-form/index.d.ts +4 -0
  137. package/lib/typescript/commonjs/src/hooks/use-form/index.d.ts.map +1 -0
  138. package/lib/typescript/commonjs/src/hooks/use-form/types.d.ts +119 -0
  139. package/lib/typescript/commonjs/src/hooks/use-form/types.d.ts.map +1 -0
  140. package/lib/typescript/commonjs/src/hooks/use-form/useForm.d.ts +30 -0
  141. package/lib/typescript/commonjs/src/hooks/use-form/useForm.d.ts.map +1 -0
  142. package/lib/typescript/commonjs/src/hooks/use-form/validators.d.ts +41 -0
  143. package/lib/typescript/commonjs/src/hooks/use-form/validators.d.ts.map +1 -0
  144. package/lib/typescript/commonjs/src/index.d.ts +1 -0
  145. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  146. package/lib/typescript/commonjs/src/theme/utils/index.d.ts +3 -0
  147. package/lib/typescript/commonjs/src/theme/utils/index.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/src/theme/utils/withTextWrapper.d.ts +41 -0
  149. package/lib/typescript/commonjs/src/theme/utils/withTextWrapper.d.ts.map +1 -0
  150. package/lib/typescript/module/src/components/Anchor/index.d.ts +2 -1
  151. package/lib/typescript/module/src/components/Anchor/index.d.ts.map +1 -1
  152. package/lib/typescript/module/src/components/Badge/index.d.ts +2 -1
  153. package/lib/typescript/module/src/components/Badge/index.d.ts.map +1 -1
  154. package/lib/typescript/module/src/components/Blockquote/index.d.ts +2 -1
  155. package/lib/typescript/module/src/components/Blockquote/index.d.ts.map +1 -1
  156. package/lib/typescript/module/src/components/Button/index.d.ts +2 -2
  157. package/lib/typescript/module/src/components/Button/index.d.ts.map +1 -1
  158. package/lib/typescript/module/src/components/Chip/index.d.ts +2 -1
  159. package/lib/typescript/module/src/components/Chip/index.d.ts.map +1 -1
  160. package/lib/typescript/module/src/components/Code/index.d.ts +2 -1
  161. package/lib/typescript/module/src/components/Code/index.d.ts.map +1 -1
  162. package/lib/typescript/module/src/components/Group/index.d.ts +1 -0
  163. package/lib/typescript/module/src/components/Group/index.d.ts.map +1 -1
  164. package/lib/typescript/module/src/components/Kbd/index.d.ts +2 -1
  165. package/lib/typescript/module/src/components/Kbd/index.d.ts.map +1 -1
  166. package/lib/typescript/module/src/components/List/index.d.ts +2 -1
  167. package/lib/typescript/module/src/components/List/index.d.ts.map +1 -1
  168. package/lib/typescript/module/src/components/Mark/index.d.ts +2 -1
  169. package/lib/typescript/module/src/components/Mark/index.d.ts.map +1 -1
  170. package/lib/typescript/module/src/components/Menu/index.d.ts +3 -2
  171. package/lib/typescript/module/src/components/Menu/index.d.ts.map +1 -1
  172. package/lib/typescript/module/src/components/NavLink/index.d.ts +2 -1
  173. package/lib/typescript/module/src/components/NavLink/index.d.ts.map +1 -1
  174. package/lib/typescript/module/src/components/Notification/index.d.ts +2 -1
  175. package/lib/typescript/module/src/components/Notification/index.d.ts.map +1 -1
  176. package/lib/typescript/module/src/components/Radio/index.d.ts +22 -1
  177. package/lib/typescript/module/src/components/Radio/index.d.ts.map +1 -1
  178. package/lib/typescript/module/src/components/Table/Table.example.d.ts +3 -0
  179. package/lib/typescript/module/src/components/Table/Table.example.d.ts.map +1 -0
  180. package/lib/typescript/module/src/components/Table/index.d.ts +7 -2
  181. package/lib/typescript/module/src/components/Table/index.d.ts.map +1 -1
  182. package/lib/typescript/module/src/components/Title/index.d.ts +2 -1
  183. package/lib/typescript/module/src/components/Title/index.d.ts.map +1 -1
  184. package/lib/typescript/module/src/hooks/index.d.ts +3 -0
  185. package/lib/typescript/module/src/hooks/index.d.ts.map +1 -0
  186. package/lib/typescript/module/src/hooks/use-form/index.d.ts +4 -0
  187. package/lib/typescript/module/src/hooks/use-form/index.d.ts.map +1 -0
  188. package/lib/typescript/module/src/hooks/use-form/types.d.ts +119 -0
  189. package/lib/typescript/module/src/hooks/use-form/types.d.ts.map +1 -0
  190. package/lib/typescript/module/src/hooks/use-form/useForm.d.ts +30 -0
  191. package/lib/typescript/module/src/hooks/use-form/useForm.d.ts.map +1 -0
  192. package/lib/typescript/module/src/hooks/use-form/validators.d.ts +41 -0
  193. package/lib/typescript/module/src/hooks/use-form/validators.d.ts.map +1 -0
  194. package/lib/typescript/module/src/index.d.ts +1 -0
  195. package/lib/typescript/module/src/index.d.ts.map +1 -1
  196. package/lib/typescript/module/src/theme/utils/index.d.ts +3 -0
  197. package/lib/typescript/module/src/theme/utils/index.d.ts.map +1 -0
  198. package/lib/typescript/module/src/theme/utils/withTextWrapper.d.ts +41 -0
  199. package/lib/typescript/module/src/theme/utils/withTextWrapper.d.ts.map +1 -0
  200. package/package.json +1 -1
  201. package/src/components/Anchor/index.tsx +8 -2
  202. package/src/components/Badge/index.tsx +5 -3
  203. package/src/components/Blockquote/index.tsx +6 -5
  204. package/src/components/Button/index.tsx +5 -6
  205. package/src/components/Chip/index.tsx +5 -3
  206. package/src/components/Code/index.tsx +19 -14
  207. package/src/components/Group/index.tsx +1 -0
  208. package/src/components/Kbd/index.tsx +5 -4
  209. package/src/components/List/index.tsx +7 -8
  210. package/src/components/Mark/index.tsx +7 -2
  211. package/src/components/Menu/index.tsx +8 -7
  212. package/src/components/NavLink/index.tsx +6 -4
  213. package/src/components/Notification/index.tsx +6 -15
  214. package/src/components/Radio/index.tsx +99 -8
  215. package/src/components/Table/Table.example.tsx +85 -0
  216. package/src/components/Table/index.tsx +93 -11
  217. package/src/components/Title/index.tsx +7 -2
  218. package/src/hooks/index.ts +2 -0
  219. package/src/hooks/use-form/index.ts +3 -0
  220. package/src/hooks/use-form/types.ts +169 -0
  221. package/src/hooks/use-form/useForm.ts +436 -0
  222. package/src/hooks/use-form/validators.ts +143 -0
  223. package/src/index.tsx +1 -0
  224. package/src/theme/utils/index.ts +2 -0
  225. package/src/theme/utils/withTextWrapper.tsx +58 -0
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["hooks/use-form/types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,418 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useForm = useForm;
7
+ var _react = require("react");
8
+ /**
9
+ * Validates a single field value against validation rules
10
+ */
11
+ function validateFieldValue(field, value, rules) {
12
+ if (!rules || !rules[field]) {
13
+ return null;
14
+ }
15
+ const validators = rules[field];
16
+ if (!validators) {
17
+ return null;
18
+ }
19
+
20
+ // Handle single validator
21
+ if (typeof validators === 'function') {
22
+ return validators(value);
23
+ }
24
+
25
+ // Handle array of validators
26
+ if (Array.isArray(validators)) {
27
+ for (const validator of validators) {
28
+ const error = validator(value);
29
+ if (error) {
30
+ return error;
31
+ }
32
+ }
33
+ }
34
+ return null;
35
+ }
36
+
37
+ /**
38
+ * Validates all form values
39
+ */
40
+ function validateAllValues(values, rules) {
41
+ if (!rules) {
42
+ return {};
43
+ }
44
+ const errors = {};
45
+ for (const field in rules) {
46
+ const error = validateFieldValue(field, values[field], rules);
47
+ if (error) {
48
+ errors[field] = error;
49
+ }
50
+ }
51
+ return errors;
52
+ }
53
+
54
+ /**
55
+ * Form state management hook for React Native
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * const form = useForm({
60
+ * initialValues: {
61
+ * email: '',
62
+ * password: '',
63
+ * },
64
+ * validate: {
65
+ * email: isEmail('Invalid email'),
66
+ * password: minLength(6, 'Password must be at least 6 characters'),
67
+ * },
68
+ * });
69
+ *
70
+ * return (
71
+ * <View>
72
+ * <TextInput {...form.getInputProps('email')} />
73
+ * <TextInput {...form.getInputProps('password')} />
74
+ * <Button onPress={form.onSubmit((values) => console.log(values))}>
75
+ * Submit
76
+ * </Button>
77
+ * </View>
78
+ * );
79
+ * ```
80
+ */
81
+ function useForm({
82
+ initialValues = {},
83
+ initialErrors = {},
84
+ initialTouched = {},
85
+ initialDirty = {},
86
+ validate: validationRules,
87
+ clearInputErrorOnChange = true,
88
+ validateInputOnChange = false,
89
+ validateInputOnBlur = false,
90
+ transformValues = values => values
91
+ } = {}) {
92
+ // Form state
93
+ const [values, setValuesState] = (0, _react.useState)(initialValues);
94
+ const [errors, setErrorsState] = (0, _react.useState)(initialErrors);
95
+ const [touched, setTouchedState] = (0, _react.useState)(initialTouched);
96
+ const [dirty, setDirtyState] = (0, _react.useState)(initialDirty);
97
+
98
+ // Keep track of initial values for reset
99
+ const initialValuesRef = (0, _react.useRef)(initialValues);
100
+
101
+ /**
102
+ * Set a single field value
103
+ */
104
+ const setFieldValue = (0, _react.useCallback)((field, value) => {
105
+ setValuesState(prev => ({
106
+ ...prev,
107
+ [field]: value
108
+ }));
109
+ setDirtyState(prev => ({
110
+ ...prev,
111
+ [field]: true
112
+ }));
113
+
114
+ // Validate on change if enabled
115
+ if (validateInputOnChange && validationRules) {
116
+ const error = validateFieldValue(field, value, validationRules);
117
+ if (error) {
118
+ setErrorsState(prev => ({
119
+ ...prev,
120
+ [field]: error
121
+ }));
122
+ } else {
123
+ setErrorsState(prev => {
124
+ const newErrors = {
125
+ ...prev
126
+ };
127
+ delete newErrors[field];
128
+ return newErrors;
129
+ });
130
+ }
131
+ } else if (clearInputErrorOnChange) {
132
+ // Clear error on change if enabled
133
+ setErrorsState(prev => {
134
+ const newErrors = {
135
+ ...prev
136
+ };
137
+ delete newErrors[field];
138
+ return newErrors;
139
+ });
140
+ }
141
+ }, [validateInputOnChange, clearInputErrorOnChange, validationRules]);
142
+
143
+ /**
144
+ * Set multiple field values
145
+ */
146
+ const setValues = (0, _react.useCallback)(newValues => {
147
+ setValuesState(prev => ({
148
+ ...prev,
149
+ ...newValues
150
+ }));
151
+
152
+ // Mark all updated fields as dirty
153
+ const dirtyFields = {};
154
+ for (const key in newValues) {
155
+ dirtyFields[key] = true;
156
+ }
157
+ setDirtyState(prev => ({
158
+ ...prev,
159
+ ...dirtyFields
160
+ }));
161
+ if (clearInputErrorOnChange) {
162
+ setErrorsState(prev => {
163
+ const newErrors = {
164
+ ...prev
165
+ };
166
+ for (const key in newValues) {
167
+ delete newErrors[key];
168
+ }
169
+ return newErrors;
170
+ });
171
+ }
172
+ }, [clearInputErrorOnChange]);
173
+
174
+ /**
175
+ * Set a single field error
176
+ */
177
+ const setFieldError = (0, _react.useCallback)((field, error) => {
178
+ if (error === null) {
179
+ setErrorsState(prev => {
180
+ const newErrors = {
181
+ ...prev
182
+ };
183
+ delete newErrors[field];
184
+ return newErrors;
185
+ });
186
+ } else {
187
+ setErrorsState(prev => ({
188
+ ...prev,
189
+ [field]: error
190
+ }));
191
+ }
192
+ }, []);
193
+
194
+ /**
195
+ * Set multiple errors
196
+ */
197
+ const setErrors = (0, _react.useCallback)(newErrors => {
198
+ setErrorsState(newErrors);
199
+ }, []);
200
+
201
+ /**
202
+ * Clear a specific field error
203
+ */
204
+ const clearFieldError = (0, _react.useCallback)(field => {
205
+ setErrorsState(prev => {
206
+ const newErrors = {
207
+ ...prev
208
+ };
209
+ delete newErrors[field];
210
+ return newErrors;
211
+ });
212
+ }, []);
213
+
214
+ /**
215
+ * Clear all errors
216
+ */
217
+ const clearErrors = (0, _react.useCallback)(() => {
218
+ setErrorsState({});
219
+ }, []);
220
+
221
+ /**
222
+ * Reset form to initial values
223
+ */
224
+ const reset = (0, _react.useCallback)(() => {
225
+ setValuesState(initialValuesRef.current);
226
+ setErrorsState({});
227
+ setTouchedState({});
228
+ setDirtyState({});
229
+ }, []);
230
+
231
+ /**
232
+ * Validate a specific field
233
+ */
234
+ const validateField = (0, _react.useCallback)(field => {
235
+ if (!validationRules) {
236
+ return true;
237
+ }
238
+ const error = validateFieldValue(field, values[field], validationRules);
239
+ if (error) {
240
+ setFieldError(field, error);
241
+ return false;
242
+ }
243
+ clearFieldError(field);
244
+ return true;
245
+ }, [values, validationRules, setFieldError, clearFieldError]);
246
+
247
+ /**
248
+ * Validate entire form
249
+ */
250
+ const validate = (0, _react.useCallback)(() => {
251
+ if (!validationRules) {
252
+ return true;
253
+ }
254
+ const newErrors = validateAllValues(values, validationRules);
255
+ setErrorsState(newErrors);
256
+ return Object.keys(newErrors).length === 0;
257
+ }, [values, validationRules]);
258
+
259
+ /**
260
+ * Check if form is valid
261
+ */
262
+ const isValid = (0, _react.useCallback)(() => {
263
+ if (!validationRules) {
264
+ return true;
265
+ }
266
+ const validationErrors = validateAllValues(values, validationRules);
267
+ return Object.keys(validationErrors).length === 0;
268
+ }, [values, validationRules]);
269
+
270
+ /**
271
+ * Check if form is dirty
272
+ */
273
+ const isDirty = (0, _react.useCallback)(() => {
274
+ return Object.values(dirty).some(isDirty => isDirty === true);
275
+ }, [dirty]);
276
+
277
+ /**
278
+ * Get field status
279
+ */
280
+ const getFieldStatus = (0, _react.useCallback)(field => {
281
+ return {
282
+ hasError: !!errors[field],
283
+ isTouched: !!touched[field],
284
+ isDirty: !!dirty[field]
285
+ };
286
+ }, [errors, touched, dirty]);
287
+
288
+ /**
289
+ * Mark field as touched
290
+ */
291
+ const setFieldTouched = (0, _react.useCallback)((field, isTouched = true) => {
292
+ setTouchedState(prev => ({
293
+ ...prev,
294
+ [field]: isTouched
295
+ }));
296
+
297
+ // Validate on blur if enabled
298
+ if (isTouched && validateInputOnBlur && validationRules) {
299
+ const error = validateFieldValue(field, values[field], validationRules);
300
+ if (error) {
301
+ setFieldError(field, error);
302
+ } else {
303
+ clearFieldError(field);
304
+ }
305
+ }
306
+ }, [validateInputOnBlur, validationRules, values, setFieldError, clearFieldError]);
307
+
308
+ /**
309
+ * Reset touched state
310
+ */
311
+ const resetTouched = (0, _react.useCallback)(() => {
312
+ setTouchedState({});
313
+ }, []);
314
+
315
+ /**
316
+ * Reset dirty state
317
+ */
318
+ const resetDirty = (0, _react.useCallback)(() => {
319
+ setDirtyState({});
320
+ }, []);
321
+
322
+ /**
323
+ * Get props to spread on input component
324
+ */
325
+ const getInputProps = (0, _react.useCallback)((field, options = {}) => {
326
+ const {
327
+ type = 'input',
328
+ withError = true,
329
+ withFocus = true
330
+ } = options;
331
+ const baseProps = {
332
+ value: values[field]
333
+ };
334
+
335
+ // Add error if needed
336
+ if (withError && errors[field]) {
337
+ baseProps.error = errors[field];
338
+ }
339
+
340
+ // Add blur handler if focus tracking is enabled
341
+ if (withFocus) {
342
+ baseProps.onBlur = () => {
343
+ setFieldTouched(field, true);
344
+ };
345
+ }
346
+
347
+ // Handle different input types
348
+ if (type === 'checkbox') {
349
+ return {
350
+ ...baseProps,
351
+ onChange: value => {
352
+ setFieldValue(field, value);
353
+ }
354
+ };
355
+ }
356
+ if (type === 'radio' || type === 'select') {
357
+ return {
358
+ ...baseProps,
359
+ onChange: value => {
360
+ setFieldValue(field, value);
361
+ }
362
+ };
363
+ }
364
+
365
+ // Default text input
366
+ return {
367
+ ...baseProps,
368
+ onChangeText: text => {
369
+ setFieldValue(field, text);
370
+ }
371
+ };
372
+ }, [values, errors, setFieldValue, setFieldTouched]);
373
+
374
+ /**
375
+ * Handle form submit
376
+ */
377
+ const onSubmit = (0, _react.useCallback)(handleSubmit => {
378
+ return async event => {
379
+ event?.preventDefault?.();
380
+
381
+ // Validate form
382
+ const isFormValid = validate();
383
+ if (!isFormValid) {
384
+ return;
385
+ }
386
+
387
+ // Transform values if needed
388
+ const transformedValues = transformValues(values);
389
+
390
+ // Call submit handler
391
+ await handleSubmit(transformedValues, event);
392
+ };
393
+ }, [validate, values, transformValues]);
394
+ return {
395
+ values,
396
+ errors,
397
+ touched,
398
+ dirty,
399
+ setFieldValue,
400
+ setValues,
401
+ setFieldError,
402
+ setErrors,
403
+ clearFieldError,
404
+ clearErrors,
405
+ reset,
406
+ validateField,
407
+ validate,
408
+ isValid,
409
+ isDirty,
410
+ getFieldStatus,
411
+ getInputProps,
412
+ onSubmit,
413
+ resetTouched,
414
+ resetDirty,
415
+ setFieldTouched
416
+ };
417
+ }
418
+ //# sourceMappingURL=useForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","validateFieldValue","field","value","rules","validators","Array","isArray","validator","error","validateAllValues","values","errors","useForm","initialValues","initialErrors","initialTouched","initialDirty","validate","validationRules","clearInputErrorOnChange","validateInputOnChange","validateInputOnBlur","transformValues","setValuesState","useState","setErrorsState","touched","setTouchedState","dirty","setDirtyState","initialValuesRef","useRef","setFieldValue","useCallback","prev","newErrors","setValues","newValues","dirtyFields","key","setFieldError","setErrors","clearFieldError","clearErrors","reset","current","validateField","Object","keys","length","isValid","validationErrors","isDirty","some","getFieldStatus","hasError","isTouched","setFieldTouched","resetTouched","resetDirty","getInputProps","options","type","withError","withFocus","baseProps","onBlur","onChange","onChangeText","text","onSubmit","handleSubmit","event","preventDefault","isFormValid","transformedValues"],"sourceRoot":"../../../../src","sources":["hooks/use-form/useForm.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAaA;AACA;AACA;AACA,SAASC,kBAAkBA,CACzBC,KAAmB,EACnBC,KAAU,EACVC,KAAmC,EACpB;EACf,IAAI,CAACA,KAAK,IAAI,CAACA,KAAK,CAACF,KAAK,CAAC,EAAE;IAC3B,OAAO,IAAI;EACb;EAEA,MAAMG,UAAU,GAAGD,KAAK,CAACF,KAAK,CAAC;EAC/B,IAAI,CAACG,UAAU,EAAE;IACf,OAAO,IAAI;EACb;;EAEA;EACA,IAAI,OAAOA,UAAU,KAAK,UAAU,EAAE;IACpC,OAAOA,UAAU,CAACF,KAAK,CAAC;EAC1B;;EAEA;EACA,IAAIG,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC,EAAE;IAC7B,KAAK,MAAMG,SAAS,IAAIH,UAAU,EAAE;MAClC,MAAMI,KAAK,GAAGD,SAAS,CAACL,KAAK,CAAC;MAC9B,IAAIM,KAAK,EAAE;QACT,OAAOA,KAAK;MACd;IACF;EACF;EAEA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA,SAASC,iBAAiBA,CACxBC,MAAc,EAC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cAAc;IACdM,aAAa;IACbU,QAAQ;IACRZ,YAAY;IACZC,UAAU;IACVF;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.minLength = exports.min = exports.maxLength = exports.max = exports.matches = exports.isNotEmpty = exports.isInArray = exports.isEmail = exports.inRange = void 0;
7
+ /**
8
+ * Built-in validators
9
+ */
10
+
11
+ /**
12
+ * Validates that a value is not empty
13
+ */
14
+ const isNotEmpty = (message = 'This field is required') => {
15
+ return value => {
16
+ if (value === null || value === undefined || value === '') {
17
+ return message;
18
+ }
19
+ if (Array.isArray(value) && value.length === 0) {
20
+ return message;
21
+ }
22
+ if (typeof value === 'string' && value.trim().length === 0) {
23
+ return message;
24
+ }
25
+ return null;
26
+ };
27
+ };
28
+
29
+ /**
30
+ * Validates minimum length
31
+ */
32
+ exports.isNotEmpty = isNotEmpty;
33
+ const minLength = (min, message) => {
34
+ return value => {
35
+ if (!value) return null;
36
+ if (value.length < min) {
37
+ return message || `Must be at least ${min} characters`;
38
+ }
39
+ return null;
40
+ };
41
+ };
42
+
43
+ /**
44
+ * Validates maximum length
45
+ */
46
+ exports.minLength = minLength;
47
+ const maxLength = (max, message) => {
48
+ return value => {
49
+ if (!value) return null;
50
+ if (value.length > max) {
51
+ return message || `Must be at most ${max} characters`;
52
+ }
53
+ return null;
54
+ };
55
+ };
56
+
57
+ /**
58
+ * Validates that value matches a pattern
59
+ */
60
+ exports.maxLength = maxLength;
61
+ const matches = (pattern, message = 'Invalid format') => {
62
+ return value => {
63
+ if (!value) return null;
64
+ if (!pattern.test(value)) {
65
+ return message;
66
+ }
67
+ return null;
68
+ };
69
+ };
70
+
71
+ /**
72
+ * Validates email format
73
+ */
74
+ exports.matches = matches;
75
+ const isEmail = (message = 'Invalid email') => {
76
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
77
+ return matches(emailRegex, message);
78
+ };
79
+
80
+ /**
81
+ * Validates minimum value
82
+ */
83
+ exports.isEmail = isEmail;
84
+ const min = (minValue, message) => {
85
+ return value => {
86
+ if (value === null || value === undefined) return null;
87
+ if (value < minValue) {
88
+ return message || `Must be at least ${minValue}`;
89
+ }
90
+ return null;
91
+ };
92
+ };
93
+
94
+ /**
95
+ * Validates maximum value
96
+ */
97
+ exports.min = min;
98
+ const max = (maxValue, message) => {
99
+ return value => {
100
+ if (value === null || value === undefined) return null;
101
+ if (value > maxValue) {
102
+ return message || `Must be at most ${maxValue}`;
103
+ }
104
+ return null;
105
+ };
106
+ };
107
+
108
+ /**
109
+ * Validates that value is in a range
110
+ */
111
+ exports.max = max;
112
+ const inRange = (minValue, maxValue, message) => {
113
+ return value => {
114
+ if (value === null || value === undefined) return null;
115
+ if (value < minValue || value > maxValue) {
116
+ return message || `Must be between ${minValue} and ${maxValue}`;
117
+ }
118
+ return null;
119
+ };
120
+ };
121
+
122
+ /**
123
+ * Validates that value is in a list
124
+ */
125
+ exports.inRange = inRange;
126
+ const isInArray = (array, message = 'Invalid value') => {
127
+ return value => {
128
+ if (!array.includes(value)) {
129
+ return message;
130
+ }
131
+ return null;
132
+ };
133
+ };
134
+ exports.isInArray = isInArray;
135
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isNotEmpty","message","value","undefined","Array","isArray","length","trim","exports","minLength","min","maxLength","max","matches","pattern","test","isEmail","emailRegex","minValue","maxValue","inRange","isInArray","array","includes"],"sourceRoot":"../../../../src","sources":["hooks/use-form/validators.ts"],"mappings":";;;;;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAMA,UAAU,GAAGA,CAACC,OAAO,GAAG,wBAAwB,KAAyB;EACpF,OAAQC,KAAU,IAAK;IACrB,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKC,SAAS,IAAID,KAAK,KAAK,EAAE,EAAE;MACzD,OAAOD,OAAO;IAChB;IACA,IAAI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,EAAE;MACxC,OAAOlB,OAAO,IAAI,mBAAmBiB,QAAQ,QAAQC,QAAQ,EAAE;IACjE;IACA,OAAO,IAAI;EACb,CAAC;AACH,CAAC;;AAED;AACA;AACA;AAFAX,OAAA,CAAAY,OAAA,GAAAA,OAAA;AAGO,MAAMC,SAAS,GAAGA,CACvBC,KAAU,EACVrB,OAAO,GAAG,eAAe,KACJ;EACrB,OAAQC,KAAQ,IAAK;IACnB,IAAI,CAACoB,KAAK,CAACC,QAAQ,CAACrB,KAAK,CAAC,EAAE;MAC1B,OAAOD,OAAO;IAChB;IACA,OAAO,IAAI;EACb,CAAC;AACH,CAAC;AAACO,OAAA,CAAAa,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -25,4 +25,15 @@ Object.keys(_index2).forEach(function (key) {
25
25
  }
26
26
  });
27
27
  });
28
+ var _index3 = require("./hooks/index.js");
29
+ Object.keys(_index3).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _index3[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _index3[key];
36
+ }
37
+ });
38
+ });
28
39
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_index","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_index2"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,OAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,OAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,OAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,OAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_index","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_index2","_index3"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,OAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,OAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,OAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,OAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,OAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,OAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,OAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,OAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "em", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _rem.em;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "rem", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _rem.rem;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "withTextWrapper", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _withTextWrapper.withTextWrapper;
22
+ }
23
+ });
24
+ var _rem = require("./rem.js");
25
+ var _withTextWrapper = require("./withTextWrapper.js");
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_rem","require","_withTextWrapper"],"sourceRoot":"../../../../src","sources":["theme/utils/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA","ignoreList":[]}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.withTextWrapper = withTextWrapper;
7
+ var _index = require("../../components/Text/index.js");
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ /**
10
+ * Conditionally wraps content in a Text component based on the withTextWrapper prop.
11
+ *
12
+ * In React Native, all text must be wrapped in a Text component. However, some
13
+ * components may need flexibility to render with or without this wrapper depending
14
+ * on whether their content is text or other components (like icons, views, etc.).
15
+ *
16
+ * @param children - The content to potentially wrap
17
+ * @param shouldWrap - Whether to wrap the content in a Text component
18
+ * @param textStyle - Optional style to apply to the Text wrapper
19
+ * @param textProps - Optional additional props to pass to the Text component
20
+ * @returns The children wrapped in Text if shouldWrap is true, otherwise just the children
21
+ *
22
+ * @example
23
+ * // Wrap text content
24
+ * withTextWrapper('Hello', true, styles.text)
25
+ *
26
+ * @example
27
+ * // Don't wrap components
28
+ * withTextWrapper(<Icon />, false)
29
+ *
30
+ * @example
31
+ * // Default behavior (wrap)
32
+ * withTextWrapper('Text', true, styles.text, { numberOfLines: 1 })
33
+ */
34
+ function withTextWrapper(children, shouldWrap = true, textStyle, textProps) {
35
+ if (!shouldWrap) {
36
+ return children;
37
+ }
38
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Text, {
39
+ style: textStyle,
40
+ ...textProps,
41
+ children: children
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Type helper for components that support the withTextWrapper pattern.
47
+ * Add this to your component props interface.
48
+ */
49
+ //# sourceMappingURL=withTextWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_index","require","_jsxRuntime","withTextWrapper","children","shouldWrap","textStyle","textProps","jsx","Text","style"],"sourceRoot":"../../../../src","sources":["theme/utils/withTextWrapper.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAA6C,IAAAC,WAAA,GAAAD,OAAA;AAG7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAC7BC,QAAmB,EACnBC,UAAmB,GAAG,IAAI,EAC1BC,SAAe,EACfC,SAAiD,EACtC;EACX,IAAI,CAACF,UAAU,EAAE;IACf,OAAOD,QAAQ;EACjB;EAEA,oBACE,IAAAF,WAAA,CAAAM,GAAA,EAACR,MAAA,CAAAS,IAAI;IAACC,KAAK,EAAEJ,SAAU;IAAA,GAAKC,SAAS;IAAAH,QAAA,EAClCA;EAAQ,CACL,CAAC;AAEX;;AAEA;AACA;AACA;AACA","ignoreList":[]}