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,414 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useRef, useState } from 'react';
4
+ /**
5
+ * Validates a single field value against validation rules
6
+ */
7
+ function validateFieldValue(field, value, rules) {
8
+ if (!rules || !rules[field]) {
9
+ return null;
10
+ }
11
+ const validators = rules[field];
12
+ if (!validators) {
13
+ return null;
14
+ }
15
+
16
+ // Handle single validator
17
+ if (typeof validators === 'function') {
18
+ return validators(value);
19
+ }
20
+
21
+ // Handle array of validators
22
+ if (Array.isArray(validators)) {
23
+ for (const validator of validators) {
24
+ const error = validator(value);
25
+ if (error) {
26
+ return error;
27
+ }
28
+ }
29
+ }
30
+ return null;
31
+ }
32
+
33
+ /**
34
+ * Validates all form values
35
+ */
36
+ function validateAllValues(values, rules) {
37
+ if (!rules) {
38
+ return {};
39
+ }
40
+ const errors = {};
41
+ for (const field in rules) {
42
+ const error = validateFieldValue(field, values[field], rules);
43
+ if (error) {
44
+ errors[field] = error;
45
+ }
46
+ }
47
+ return errors;
48
+ }
49
+
50
+ /**
51
+ * Form state management hook for React Native
52
+ *
53
+ * @example
54
+ * ```tsx
55
+ * const form = useForm({
56
+ * initialValues: {
57
+ * email: '',
58
+ * password: '',
59
+ * },
60
+ * validate: {
61
+ * email: isEmail('Invalid email'),
62
+ * password: minLength(6, 'Password must be at least 6 characters'),
63
+ * },
64
+ * });
65
+ *
66
+ * return (
67
+ * <View>
68
+ * <TextInput {...form.getInputProps('email')} />
69
+ * <TextInput {...form.getInputProps('password')} />
70
+ * <Button onPress={form.onSubmit((values) => console.log(values))}>
71
+ * Submit
72
+ * </Button>
73
+ * </View>
74
+ * );
75
+ * ```
76
+ */
77
+ export function useForm({
78
+ initialValues = {},
79
+ initialErrors = {},
80
+ initialTouched = {},
81
+ initialDirty = {},
82
+ validate: validationRules,
83
+ clearInputErrorOnChange = true,
84
+ validateInputOnChange = false,
85
+ validateInputOnBlur = false,
86
+ transformValues = values => values
87
+ } = {}) {
88
+ // Form state
89
+ const [values, setValuesState] = useState(initialValues);
90
+ const [errors, setErrorsState] = useState(initialErrors);
91
+ const [touched, setTouchedState] = useState(initialTouched);
92
+ const [dirty, setDirtyState] = useState(initialDirty);
93
+
94
+ // Keep track of initial values for reset
95
+ const initialValuesRef = useRef(initialValues);
96
+
97
+ /**
98
+ * Set a single field value
99
+ */
100
+ const setFieldValue = useCallback((field, value) => {
101
+ setValuesState(prev => ({
102
+ ...prev,
103
+ [field]: value
104
+ }));
105
+ setDirtyState(prev => ({
106
+ ...prev,
107
+ [field]: true
108
+ }));
109
+
110
+ // Validate on change if enabled
111
+ if (validateInputOnChange && validationRules) {
112
+ const error = validateFieldValue(field, value, validationRules);
113
+ if (error) {
114
+ setErrorsState(prev => ({
115
+ ...prev,
116
+ [field]: error
117
+ }));
118
+ } else {
119
+ setErrorsState(prev => {
120
+ const newErrors = {
121
+ ...prev
122
+ };
123
+ delete newErrors[field];
124
+ return newErrors;
125
+ });
126
+ }
127
+ } else if (clearInputErrorOnChange) {
128
+ // Clear error on change if enabled
129
+ setErrorsState(prev => {
130
+ const newErrors = {
131
+ ...prev
132
+ };
133
+ delete newErrors[field];
134
+ return newErrors;
135
+ });
136
+ }
137
+ }, [validateInputOnChange, clearInputErrorOnChange, validationRules]);
138
+
139
+ /**
140
+ * Set multiple field values
141
+ */
142
+ const setValues = useCallback(newValues => {
143
+ setValuesState(prev => ({
144
+ ...prev,
145
+ ...newValues
146
+ }));
147
+
148
+ // Mark all updated fields as dirty
149
+ const dirtyFields = {};
150
+ for (const key in newValues) {
151
+ dirtyFields[key] = true;
152
+ }
153
+ setDirtyState(prev => ({
154
+ ...prev,
155
+ ...dirtyFields
156
+ }));
157
+ if (clearInputErrorOnChange) {
158
+ setErrorsState(prev => {
159
+ const newErrors = {
160
+ ...prev
161
+ };
162
+ for (const key in newValues) {
163
+ delete newErrors[key];
164
+ }
165
+ return newErrors;
166
+ });
167
+ }
168
+ }, [clearInputErrorOnChange]);
169
+
170
+ /**
171
+ * Set a single field error
172
+ */
173
+ const setFieldError = useCallback((field, error) => {
174
+ if (error === null) {
175
+ setErrorsState(prev => {
176
+ const newErrors = {
177
+ ...prev
178
+ };
179
+ delete newErrors[field];
180
+ return newErrors;
181
+ });
182
+ } else {
183
+ setErrorsState(prev => ({
184
+ ...prev,
185
+ [field]: error
186
+ }));
187
+ }
188
+ }, []);
189
+
190
+ /**
191
+ * Set multiple errors
192
+ */
193
+ const setErrors = useCallback(newErrors => {
194
+ setErrorsState(newErrors);
195
+ }, []);
196
+
197
+ /**
198
+ * Clear a specific field error
199
+ */
200
+ const clearFieldError = useCallback(field => {
201
+ setErrorsState(prev => {
202
+ const newErrors = {
203
+ ...prev
204
+ };
205
+ delete newErrors[field];
206
+ return newErrors;
207
+ });
208
+ }, []);
209
+
210
+ /**
211
+ * Clear all errors
212
+ */
213
+ const clearErrors = useCallback(() => {
214
+ setErrorsState({});
215
+ }, []);
216
+
217
+ /**
218
+ * Reset form to initial values
219
+ */
220
+ const reset = useCallback(() => {
221
+ setValuesState(initialValuesRef.current);
222
+ setErrorsState({});
223
+ setTouchedState({});
224
+ setDirtyState({});
225
+ }, []);
226
+
227
+ /**
228
+ * Validate a specific field
229
+ */
230
+ const validateField = useCallback(field => {
231
+ if (!validationRules) {
232
+ return true;
233
+ }
234
+ const error = validateFieldValue(field, values[field], validationRules);
235
+ if (error) {
236
+ setFieldError(field, error);
237
+ return false;
238
+ }
239
+ clearFieldError(field);
240
+ return true;
241
+ }, [values, validationRules, setFieldError, clearFieldError]);
242
+
243
+ /**
244
+ * Validate entire form
245
+ */
246
+ const validate = useCallback(() => {
247
+ if (!validationRules) {
248
+ return true;
249
+ }
250
+ const newErrors = validateAllValues(values, validationRules);
251
+ setErrorsState(newErrors);
252
+ return Object.keys(newErrors).length === 0;
253
+ }, [values, validationRules]);
254
+
255
+ /**
256
+ * Check if form is valid
257
+ */
258
+ const isValid = useCallback(() => {
259
+ if (!validationRules) {
260
+ return true;
261
+ }
262
+ const validationErrors = validateAllValues(values, validationRules);
263
+ return Object.keys(validationErrors).length === 0;
264
+ }, [values, validationRules]);
265
+
266
+ /**
267
+ * Check if form is dirty
268
+ */
269
+ const isDirty = useCallback(() => {
270
+ return Object.values(dirty).some(isDirty => isDirty === true);
271
+ }, [dirty]);
272
+
273
+ /**
274
+ * Get field status
275
+ */
276
+ const getFieldStatus = useCallback(field => {
277
+ return {
278
+ hasError: !!errors[field],
279
+ isTouched: !!touched[field],
280
+ isDirty: !!dirty[field]
281
+ };
282
+ }, [errors, touched, dirty]);
283
+
284
+ /**
285
+ * Mark field as touched
286
+ */
287
+ const setFieldTouched = useCallback((field, isTouched = true) => {
288
+ setTouchedState(prev => ({
289
+ ...prev,
290
+ [field]: isTouched
291
+ }));
292
+
293
+ // Validate on blur if enabled
294
+ if (isTouched && validateInputOnBlur && validationRules) {
295
+ const error = validateFieldValue(field, values[field], validationRules);
296
+ if (error) {
297
+ setFieldError(field, error);
298
+ } else {
299
+ clearFieldError(field);
300
+ }
301
+ }
302
+ }, [validateInputOnBlur, validationRules, values, setFieldError, clearFieldError]);
303
+
304
+ /**
305
+ * Reset touched state
306
+ */
307
+ const resetTouched = useCallback(() => {
308
+ setTouchedState({});
309
+ }, []);
310
+
311
+ /**
312
+ * Reset dirty state
313
+ */
314
+ const resetDirty = useCallback(() => {
315
+ setDirtyState({});
316
+ }, []);
317
+
318
+ /**
319
+ * Get props to spread on input component
320
+ */
321
+ const getInputProps = useCallback((field, options = {}) => {
322
+ const {
323
+ type = 'input',
324
+ withError = true,
325
+ withFocus = true
326
+ } = options;
327
+ const baseProps = {
328
+ value: values[field]
329
+ };
330
+
331
+ // Add error if needed
332
+ if (withError && errors[field]) {
333
+ baseProps.error = errors[field];
334
+ }
335
+
336
+ // Add blur handler if focus tracking is enabled
337
+ if (withFocus) {
338
+ baseProps.onBlur = () => {
339
+ setFieldTouched(field, true);
340
+ };
341
+ }
342
+
343
+ // Handle different input types
344
+ if (type === 'checkbox') {
345
+ return {
346
+ ...baseProps,
347
+ onChange: value => {
348
+ setFieldValue(field, value);
349
+ }
350
+ };
351
+ }
352
+ if (type === 'radio' || type === 'select') {
353
+ return {
354
+ ...baseProps,
355
+ onChange: value => {
356
+ setFieldValue(field, value);
357
+ }
358
+ };
359
+ }
360
+
361
+ // Default text input
362
+ return {
363
+ ...baseProps,
364
+ onChangeText: text => {
365
+ setFieldValue(field, text);
366
+ }
367
+ };
368
+ }, [values, errors, setFieldValue, setFieldTouched]);
369
+
370
+ /**
371
+ * Handle form submit
372
+ */
373
+ const onSubmit = useCallback(handleSubmit => {
374
+ return async event => {
375
+ event?.preventDefault?.();
376
+
377
+ // Validate form
378
+ const isFormValid = validate();
379
+ if (!isFormValid) {
380
+ return;
381
+ }
382
+
383
+ // Transform values if needed
384
+ const transformedValues = transformValues(values);
385
+
386
+ // Call submit handler
387
+ await handleSubmit(transformedValues, event);
388
+ };
389
+ }, [validate, values, transformValues]);
390
+ return {
391
+ values,
392
+ errors,
393
+ touched,
394
+ dirty,
395
+ setFieldValue,
396
+ setValues,
397
+ setFieldError,
398
+ setErrors,
399
+ clearFieldError,
400
+ clearErrors,
401
+ reset,
402
+ validateField,
403
+ validate,
404
+ isValid,
405
+ isDirty,
406
+ getFieldStatus,
407
+ getInputProps,
408
+ onSubmit,
409
+ resetTouched,
410
+ resetDirty,
411
+ setFieldTouched
412
+ };
413
+ }
414
+ //# sourceMappingURL=useForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useRef","useState","validateFieldValue","field","value","rules","validators","Array","isArray","validator","error","validateAllValues","values","errors","useForm","initialValues","initialErrors","initialTouched","initialDirty","validate","validationRules","clearInputErrorOnChange","validateInputOnChange","validateInputOnBlur","transformValues","setValuesState","setErrorsState","touched","setTouchedState","dirty","setDirtyState","initialValuesRef","setFieldValue","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,SAASA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAarD;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,EACdP,KAAmC,EACf;EACpB,IAAI,CAACA,KAAK,EAAE;IACV,OAAO,CAAC,CAAC;EACX;EAEA,MAAMQ,MAA0B,GAAG,CAAC,CAAC;EAErC,KAAK,MAAMV,KAAK,IAAIE,KAAK,EAAE;IACzB,MAAMK,KAAK,GAAGR,kBAAkB,CAACC,KAAK,EAAES,MAAM,CAACT,KAAK,CAAC,EAAEE,KAAK,CAAC;IAC7D,IAAIK,KAAK,EAAE;MACTG,MAAM,CAACV,KAAK,CAAC,GAAGO,KAAK;IACvB;EACF;EAEA,OAAOG,MAAM;AACf;;AAEA;AACA;A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AC;MACnC;IACF,CAAC;EACH,CAAC,EACD,CAACxD,MAAM,EAAEC,MAAM,EAAEmB,aAAa,EAAEwB,eAAe,CACjD,CAAC;;EAED;AACF;AACA;EACE,MAAMa,QAAQ,GAAGtE,WAAW,CACzBuE,YAAuC,IAAK;IAC3C,OAAO,MAAOC,KAAW,IAAK;MAC5BA,KAAK,EAAEC,cAAc,GAAG,CAAC;;MAEzB;MACA,MAAMC,WAAW,GAAGtD,QAAQ,CAAC,CAAC;MAC9B,IAAI,CAACsD,WAAW,EAAE;QAChB;MACF;;MAEA;MACA,MAAMC,iBAAiB,GAAGlD,eAAe,CAACZ,MAAM,CAAC;;MAEjD;MACA,MAAM0D,YAAY,CAACI,iBAAiB,EAAEH,KAAK,CAAC;IAC9C,CAAC;EACH,CAAC,EACD,CAACpD,QAAQ,EAAEP,MAAM,EAAEY,eAAe,CACpC,CAAC;EAED,OAAO;IACLZ,MAAM;IACNC,MAAM;IACNc,OAAO;IACPE,KAAK;IACLG,aAAa;IACbG,SAAS;IACTI,aAAa;IACbC,SAAS;IACTC,eAAe;IACfC,WAAW;IACXC,KAAK;IACLE,aAAa;IACb1B,QAAQ;IACR8B,OAAO;IACPE,OAAO;IACPE,cAAc;IACdM,aAAa;IACbU,QAAQ;IACRZ,YAAY;IACZC,UAAU;IACVF;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Built-in validators
5
+ */
6
+
7
+ /**
8
+ * Validates that a value is not empty
9
+ */
10
+ export const isNotEmpty = (message = 'This field is required') => {
11
+ return value => {
12
+ if (value === null || value === undefined || value === '') {
13
+ return message;
14
+ }
15
+ if (Array.isArray(value) && value.length === 0) {
16
+ return message;
17
+ }
18
+ if (typeof value === 'string' && value.trim().length === 0) {
19
+ return message;
20
+ }
21
+ return null;
22
+ };
23
+ };
24
+
25
+ /**
26
+ * Validates minimum length
27
+ */
28
+ export const minLength = (min, message) => {
29
+ return value => {
30
+ if (!value) return null;
31
+ if (value.length < min) {
32
+ return message || `Must be at least ${min} characters`;
33
+ }
34
+ return null;
35
+ };
36
+ };
37
+
38
+ /**
39
+ * Validates maximum length
40
+ */
41
+ export const maxLength = (max, message) => {
42
+ return value => {
43
+ if (!value) return null;
44
+ if (value.length > max) {
45
+ return message || `Must be at most ${max} characters`;
46
+ }
47
+ return null;
48
+ };
49
+ };
50
+
51
+ /**
52
+ * Validates that value matches a pattern
53
+ */
54
+ export const matches = (pattern, message = 'Invalid format') => {
55
+ return value => {
56
+ if (!value) return null;
57
+ if (!pattern.test(value)) {
58
+ return message;
59
+ }
60
+ return null;
61
+ };
62
+ };
63
+
64
+ /**
65
+ * Validates email format
66
+ */
67
+ export const isEmail = (message = 'Invalid email') => {
68
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
69
+ return matches(emailRegex, message);
70
+ };
71
+
72
+ /**
73
+ * Validates minimum value
74
+ */
75
+ export const min = (minValue, message) => {
76
+ return value => {
77
+ if (value === null || value === undefined) return null;
78
+ if (value < minValue) {
79
+ return message || `Must be at least ${minValue}`;
80
+ }
81
+ return null;
82
+ };
83
+ };
84
+
85
+ /**
86
+ * Validates maximum value
87
+ */
88
+ export const max = (maxValue, message) => {
89
+ return value => {
90
+ if (value === null || value === undefined) return null;
91
+ if (value > maxValue) {
92
+ return message || `Must be at most ${maxValue}`;
93
+ }
94
+ return null;
95
+ };
96
+ };
97
+
98
+ /**
99
+ * Validates that value is in a range
100
+ */
101
+ export const inRange = (minValue, maxValue, message) => {
102
+ return value => {
103
+ if (value === null || value === undefined) return null;
104
+ if (value < minValue || value > maxValue) {
105
+ return message || `Must be between ${minValue} and ${maxValue}`;
106
+ }
107
+ return null;
108
+ };
109
+ };
110
+
111
+ /**
112
+ * Validates that value is in a list
113
+ */
114
+ export const isInArray = (array, message = 'Invalid value') => {
115
+ return value => {
116
+ if (!array.includes(value)) {
117
+ return message;
118
+ }
119
+ return null;
120
+ };
121
+ };
122
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isNotEmpty","message","value","undefined","Array","isArray","length","trim","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;AACA,OAAO,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,IAAIG,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,IAAIA,KAAK,CAACI,MAAM,KAAK,CAAC,EAAE;MAC9C,OAAOL,OAAO;IAChB;IACA,IAAI,OAAOC,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACK,IAAI,CAAC,CAAC,CAACD,MAAM,KAAK,CAAC,EAAE;MAC1D,OAAOL,OAAO;IAChB;IACA,OAAO,IAAI;EACb,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMO,SAAS,GAAGA,CACvBC,GAAW,EACXR,OAAgB,KACU;EAC1B,OAAQC,KAAa,IAAK;IACxB,IAAI,CAACA,KAAK,EAAE,OAAO,IAAI;IACvB,IAAIA,KAAK,CAACI,MAAM,GAAGG,GAAG,EAAE;MACtB,OAAOR,OAAO,IAAI,oBAAoBQ,GAAG,aAAa;IACxD;IACA,OAAO,IAAI;EACb,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGA,CACvBC,GAAW,EACXV,OAAgB,KACU;EAC1B,OAAQC,KAAa,IAAK;IACxB,IAAI,CAACA,KAAK,EAAE,OAAO,IAAI;IACvB,IAAIA,KAAK,CAACI,MAAM,GAAGK,GAAG,EAAE;MACtB,OAAOV,OAAO,I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gB,EAChBC,QAAgB,EAChBjB,OAAgB,KACU;EAC1B,OAAQC,KAAa,IAAK;IACxB,IAAIA,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKC,SAAS,EAAE,OAAO,IAAI;IACtD,IAAID,KAAK,GAAGe,QAAQ,IAAIf,KAAK,GAAGgB,QAAQ,EAAE;MACxC,OAAOjB,OAAO,IAAI,mBAAmBgB,QAAQ,QAAQC,QAAQ,EAAE;IACjE;IACA,OAAO,IAAI;EACb,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAME,SAAS,GAAGA,CACvBC,KAAU,EACVpB,OAAO,GAAG,eAAe,KACJ;EACrB,OAAQC,KAAQ,IAAK;IACnB,IAAI,CAACmB,KAAK,CAACC,QAAQ,CAACpB,KAAK,CAAC,EAAE;MAC1B,OAAOD,OAAO;IAChB;IACA,OAAO,IAAI;EACb,CAAC;AACH,CAAC","ignoreList":[]}
@@ -2,4 +2,5 @@
2
2
 
3
3
  export * from "./theme/index.js";
4
4
  export * from "./components/index.js";
5
+ export * from "./hooks/index.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,cAAc,kBAAS;AACvB,cAAc,uBAAc","ignoreList":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,cAAc,kBAAS;AACvB,cAAc,uBAAc;AAC5B,cAAc,kBAAS","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ export { rem, em } from "./rem.js";
4
+ export { withTextWrapper } from "./withTextWrapper.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["rem","em","withTextWrapper"],"sourceRoot":"../../../../src","sources":["theme/utils/index.ts"],"mappings":";;AAAA,SAASA,GAAG,EAAEC,EAAE,QAAQ,UAAO;AAC/B,SAASC,eAAe,QAAmC,sBAAmB","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ import { Text } from "../../components/Text/index.js";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ /**
6
+ * Conditionally wraps content in a Text component based on the withTextWrapper prop.
7
+ *
8
+ * In React Native, all text must be wrapped in a Text component. However, some
9
+ * components may need flexibility to render with or without this wrapper depending
10
+ * on whether their content is text or other components (like icons, views, etc.).
11
+ *
12
+ * @param children - The content to potentially wrap
13
+ * @param shouldWrap - Whether to wrap the content in a Text component
14
+ * @param textStyle - Optional style to apply to the Text wrapper
15
+ * @param textProps - Optional additional props to pass to the Text component
16
+ * @returns The children wrapped in Text if shouldWrap is true, otherwise just the children
17
+ *
18
+ * @example
19
+ * // Wrap text content
20
+ * withTextWrapper('Hello', true, styles.text)
21
+ *
22
+ * @example
23
+ * // Don't wrap components
24
+ * withTextWrapper(<Icon />, false)
25
+ *
26
+ * @example
27
+ * // Default behavior (wrap)
28
+ * withTextWrapper('Text', true, styles.text, { numberOfLines: 1 })
29
+ */
30
+ export function withTextWrapper(children, shouldWrap = true, textStyle, textProps) {
31
+ if (!shouldWrap) {
32
+ return children;
33
+ }
34
+ return /*#__PURE__*/_jsx(Text, {
35
+ style: textStyle,
36
+ ...textProps,
37
+ children: children
38
+ });
39
+ }
40
+
41
+ /**
42
+ * Type helper for components that support the withTextWrapper pattern.
43
+ * Add this to your component props interface.
44
+ */
45
+ //# sourceMappingURL=withTextWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Text","jsx","_jsx","withTextWrapper","children","shouldWrap","textStyle","textProps","style"],"sourceRoot":"../../../../src","sources":["theme/utils/withTextWrapper.tsx"],"mappings":";;AACA,SAASA,IAAI,QAAQ,gCAAuB;AAAC,SAAAC,GAAA,IAAAC,IAAA;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;AACA,OAAO,SAASC,eAAeA,CAC7BC,QAAmB,EACnBC,UAAmB,GAAG,IAAI,EAC1BC,SAAe,EACfC,SAAiD,EACtC;EACX,IAAI,CAACF,UAAU,EAAE;IACf,OAAOD,QAAQ;EACjB;EAEA,oBACEF,IAAA,CAACF,IAAI;IAACQ,KAAK,EAAEF,SAAU;IAAA,GAAKC,SAAS;IAAAH,QAAA,EAClCA;EAAQ,CACL,CAAC;AAEX;;AAEA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
2
  import { Text as RNText, type TextStyle } from 'react-native';
3
3
  import type { DefaultProps, MantineColor, MantineSize, Variants } from '../../theme/types';
4
- export interface AnchorProps extends DefaultProps {
4
+ import type { WithTextWrapperProps } from '../../theme/utils/withTextWrapper';
5
+ export interface AnchorProps extends DefaultProps, WithTextWrapperProps {
5
6
  /** Anchor text color from theme */
6
7
  color?: MantineColor;
7
8
  /** Anchor text size */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Anchor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,IAAI,IAAI,MAAM,EAAW,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAK3B,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,mCAAmC;IACnC,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB,uBAAuB;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,yBAAyB;IACzB,MAAM,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;IAEjC,sBAAsB;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,wBAAwB;IACxB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,MAA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AO,MAAM,MAAM,4EAiCjB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { DefaultProps, MantineColor, MantineNumberSize, MantineSize, Variants } from '../../theme/types';
3
- export interface BadgeProps extends DefaultProps {
3
+ import { type WithTextWrapperProps } from '../../theme/utils/withTextWrapper';
4
+ export interface BadgeProps extends DefaultProps, WithTextWrapperProps {
4
5
  /** Badge color from theme */
5
6
  color?: MantineColor;
6
7
  /** Controls badge appearance */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Badge/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAG1C,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAK3B,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,6BAA6B;IAC7B,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB,gCAAgC;IAChC,OAAO,CAAC,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC;IAE3D,iBAAiB;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,kEAAkE;IAClE,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B,iDAAiD;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,kDAAkD;IAClD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE9B,mDAAmD;IACnD,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE/B,oBAAoB;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE3B,wBAAwB;IACxB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAwHD,eAAO,MAAM,KAAK,wEA6BhB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Badge/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAE1C,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAE/F,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,oBAAoB;IACpE,6BAA6B;IAC7B,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB,gCAAgC;IAChC,OAAO,CAAC,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC;IAE3D,iBAAiB;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB,kEAAkE;IAClE,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B,iDAAiD;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,kDAAkD;IAClD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE9B,mDAAmD;IACnD,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE/B,oBAAoB;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE3B,wBAAwB;IACxB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAyHD,eAAO,MAAM,KAAK,wEA8BhB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { DefaultProps, MantineColor, MantineNumberSize } from '../../theme/types';
3
- export interface BlockquoteProps extends DefaultProps {
3
+ import { type WithTextWrapperProps } from '../../theme/utils/withTextWrapper';
4
+ export interface BlockquoteProps extends DefaultProps, WithTextWrapperProps {
4
5
  /** Blockquote color from theme */
5
6
  color?: MantineColor;
6
7
  /** Icon to display on the left side */