@mehdashti/forms 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +634 -0
- package/dist/index.js +788 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import * as react_hook_form from 'react-hook-form';
|
|
2
|
+
import { FieldValues, DefaultValues, Path, UseFormReturn, Control, ArrayPath, FieldErrors } from 'react-hook-form';
|
|
3
|
+
export { FieldErrors, FieldValues, Path, PathValue } from 'react-hook-form';
|
|
4
|
+
import { z, ZodTypeAny } from 'zod';
|
|
5
|
+
export { z } from 'zod';
|
|
6
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
|
+
import * as React$1 from 'react';
|
|
8
|
+
|
|
9
|
+
interface SmartFormOptions<TFieldValues extends FieldValues = FieldValues> {
|
|
10
|
+
schema: z.ZodSchema<TFieldValues>;
|
|
11
|
+
onSubmit: (data: TFieldValues) => void | Promise<void>;
|
|
12
|
+
onError?: (errors: Record<string, unknown>) => void;
|
|
13
|
+
realtimeValidation?: boolean;
|
|
14
|
+
defaultValues?: DefaultValues<TFieldValues>;
|
|
15
|
+
mode?: 'onSubmit' | 'onBlur' | 'onChange' | 'onTouched' | 'all';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Enhanced React Hook Form with Zod validation and smart defaults
|
|
19
|
+
*/
|
|
20
|
+
declare function useSmartForm<TFieldValues extends FieldValues = FieldValues>(options: SmartFormOptions<TFieldValues>): {
|
|
21
|
+
handleSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;
|
|
22
|
+
isSubmitting: boolean;
|
|
23
|
+
hasErrors: boolean;
|
|
24
|
+
getError: (name: Path<TFieldValues>) => string | undefined;
|
|
25
|
+
watch: react_hook_form.UseFormWatch<TFieldValues>;
|
|
26
|
+
getValues: react_hook_form.UseFormGetValues<TFieldValues>;
|
|
27
|
+
getFieldState: react_hook_form.UseFormGetFieldState<TFieldValues>;
|
|
28
|
+
setError: react_hook_form.UseFormSetError<TFieldValues>;
|
|
29
|
+
clearErrors: react_hook_form.UseFormClearErrors<TFieldValues>;
|
|
30
|
+
setValue: react_hook_form.UseFormSetValue<TFieldValues>;
|
|
31
|
+
trigger: react_hook_form.UseFormTrigger<TFieldValues>;
|
|
32
|
+
formState: react_hook_form.FormState<TFieldValues>;
|
|
33
|
+
resetField: react_hook_form.UseFormResetField<TFieldValues>;
|
|
34
|
+
reset: react_hook_form.UseFormReset<TFieldValues>;
|
|
35
|
+
unregister: react_hook_form.UseFormUnregister<TFieldValues>;
|
|
36
|
+
control: react_hook_form.Control<TFieldValues, any, TFieldValues>;
|
|
37
|
+
register: react_hook_form.UseFormRegister<TFieldValues>;
|
|
38
|
+
setFocus: react_hook_form.UseFormSetFocus<TFieldValues>;
|
|
39
|
+
subscribe: react_hook_form.UseFormSubscribe<TFieldValues>;
|
|
40
|
+
};
|
|
41
|
+
type SmartFormReturn<TFieldValues extends FieldValues = FieldValues> = ReturnType<typeof useSmartForm<TFieldValues>>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Form field component props
|
|
45
|
+
*/
|
|
46
|
+
interface FormFieldProps<TFieldValues extends FieldValues = FieldValues> {
|
|
47
|
+
name: Path<TFieldValues>;
|
|
48
|
+
label: string;
|
|
49
|
+
type?: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url';
|
|
50
|
+
placeholder?: string;
|
|
51
|
+
required?: boolean;
|
|
52
|
+
helpText?: string;
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
className?: string;
|
|
55
|
+
control: UseFormReturn<TFieldValues>['control'];
|
|
56
|
+
render?: (field: {
|
|
57
|
+
value: unknown;
|
|
58
|
+
onChange: (...event: unknown[]) => void;
|
|
59
|
+
onBlur: () => void;
|
|
60
|
+
name: string;
|
|
61
|
+
}) => React.ReactElement;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Select field option
|
|
65
|
+
*/
|
|
66
|
+
interface SelectOption {
|
|
67
|
+
label: string;
|
|
68
|
+
value: string | number;
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Select field component props
|
|
73
|
+
*/
|
|
74
|
+
interface FormSelectProps<TFieldValues extends FieldValues = FieldValues> extends Omit<FormFieldProps<TFieldValues>, 'type' | 'placeholder'> {
|
|
75
|
+
options: SelectOption[];
|
|
76
|
+
placeholder?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Checkbox field component props
|
|
80
|
+
*/
|
|
81
|
+
interface FormCheckboxProps<TFieldValues extends FieldValues = FieldValues> extends Omit<FormFieldProps<TFieldValues>, 'type' | 'placeholder'> {
|
|
82
|
+
description?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Smart Form Field component with automatic error handling
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* <FormField
|
|
91
|
+
* name="email"
|
|
92
|
+
* label="Email"
|
|
93
|
+
* type="email"
|
|
94
|
+
* required
|
|
95
|
+
* control={form.control}
|
|
96
|
+
* placeholder="Enter your email"
|
|
97
|
+
* />
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function FormField<TFieldValues extends FieldValues = FieldValues>({ name, label, type, placeholder, required, helpText, disabled, className, control, render, }: FormFieldProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Smart Form Select component
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```tsx
|
|
107
|
+
* <FormSelect
|
|
108
|
+
* name="country"
|
|
109
|
+
* label="Country"
|
|
110
|
+
* required
|
|
111
|
+
* control={form.control}
|
|
112
|
+
* options={[
|
|
113
|
+
* { value: 'us', label: 'United States' },
|
|
114
|
+
* { value: 'uk', label: 'United Kingdom' },
|
|
115
|
+
* ]}
|
|
116
|
+
* />
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function FormSelect<TFieldValues extends FieldValues = FieldValues>({ name, label, options, placeholder, required, helpText, disabled, className, control, }: FormSelectProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Smart Form Checkbox component
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* <FormCheckbox
|
|
127
|
+
* name="acceptTerms"
|
|
128
|
+
* label="I accept the terms and conditions"
|
|
129
|
+
* required
|
|
130
|
+
* control={form.control}
|
|
131
|
+
* description="You must accept the terms to continue"
|
|
132
|
+
* />
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function FormCheckbox<TFieldValues extends FieldValues = FieldValues>({ name, label, description, required, helpText, disabled, className, control, }: FormCheckboxProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
136
|
+
|
|
137
|
+
interface FormTextareaProps<TFieldValues extends FieldValues = FieldValues> {
|
|
138
|
+
name: Path<TFieldValues>;
|
|
139
|
+
label: string;
|
|
140
|
+
placeholder?: string;
|
|
141
|
+
required?: boolean;
|
|
142
|
+
helpText?: string;
|
|
143
|
+
disabled?: boolean;
|
|
144
|
+
className?: string;
|
|
145
|
+
control: Control<TFieldValues>;
|
|
146
|
+
rows?: number;
|
|
147
|
+
maxLength?: number;
|
|
148
|
+
showCharacterCount?: boolean;
|
|
149
|
+
resize?: 'none' | 'vertical' | 'horizontal' | 'both';
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Smart Form Textarea component with character counter
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```tsx
|
|
156
|
+
* <FormTextarea
|
|
157
|
+
* name="description"
|
|
158
|
+
* label="Description"
|
|
159
|
+
* control={form.control}
|
|
160
|
+
* rows={4}
|
|
161
|
+
* maxLength={500}
|
|
162
|
+
* showCharacterCount
|
|
163
|
+
* />
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
declare function FormTextarea<TFieldValues extends FieldValues = FieldValues>({ name, label, placeholder, required, helpText, disabled, className, control, rows, maxLength, showCharacterCount, resize, }: FormTextareaProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
167
|
+
|
|
168
|
+
interface FormFileUploadProps<TFieldValues extends FieldValues = FieldValues> {
|
|
169
|
+
name: Path<TFieldValues>;
|
|
170
|
+
label: string;
|
|
171
|
+
required?: boolean;
|
|
172
|
+
helpText?: string;
|
|
173
|
+
disabled?: boolean;
|
|
174
|
+
className?: string;
|
|
175
|
+
control: Control<TFieldValues>;
|
|
176
|
+
accept?: string;
|
|
177
|
+
multiple?: boolean;
|
|
178
|
+
maxSize?: number;
|
|
179
|
+
showPreview?: boolean;
|
|
180
|
+
onFileChange?: (files: FileList | null) => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Smart Form File Upload component with preview
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```tsx
|
|
187
|
+
* <FormFileUpload
|
|
188
|
+
* name="avatar"
|
|
189
|
+
* label="Profile Picture"
|
|
190
|
+
* control={form.control}
|
|
191
|
+
* accept="image/*"
|
|
192
|
+
* maxSize={5 * 1024 * 1024} // 5MB
|
|
193
|
+
* showPreview
|
|
194
|
+
* />
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare function FormFileUpload<TFieldValues extends FieldValues = FieldValues>({ name, label, required, helpText, disabled, className, control, accept, multiple, maxSize, showPreview, onFileChange, }: FormFileUploadProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
198
|
+
|
|
199
|
+
interface FormDatePickerProps<TFieldValues extends FieldValues = FieldValues> {
|
|
200
|
+
name: Path<TFieldValues>;
|
|
201
|
+
label: string;
|
|
202
|
+
placeholder?: string;
|
|
203
|
+
required?: boolean;
|
|
204
|
+
helpText?: string;
|
|
205
|
+
disabled?: boolean;
|
|
206
|
+
className?: string;
|
|
207
|
+
control: Control<TFieldValues>;
|
|
208
|
+
min?: string;
|
|
209
|
+
max?: string;
|
|
210
|
+
mode?: 'single' | 'range';
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Smart Form Date Picker component
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```tsx
|
|
217
|
+
* <FormDatePicker
|
|
218
|
+
* name="birthDate"
|
|
219
|
+
* label="Birth Date"
|
|
220
|
+
* control={form.control}
|
|
221
|
+
* max={new Date().toISOString().split('T')[0]}
|
|
222
|
+
* />
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
declare function FormDatePicker<TFieldValues extends FieldValues = FieldValues>({ name, label, placeholder, required, helpText, disabled, className, control, min, max, mode, }: FormDatePickerProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
226
|
+
|
|
227
|
+
interface MultiSelectOption {
|
|
228
|
+
value: string | number;
|
|
229
|
+
label: string;
|
|
230
|
+
disabled?: boolean;
|
|
231
|
+
}
|
|
232
|
+
interface FormMultiSelectProps<TFieldValues extends FieldValues = FieldValues> {
|
|
233
|
+
name: Path<TFieldValues>;
|
|
234
|
+
label: string;
|
|
235
|
+
options: MultiSelectOption[];
|
|
236
|
+
required?: boolean;
|
|
237
|
+
helpText?: string;
|
|
238
|
+
disabled?: boolean;
|
|
239
|
+
className?: string;
|
|
240
|
+
control: Control<TFieldValues>;
|
|
241
|
+
layout?: 'vertical' | 'horizontal' | 'grid';
|
|
242
|
+
maxSelection?: number;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Smart Form Multi-Select component
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```tsx
|
|
249
|
+
* <FormMultiSelect
|
|
250
|
+
* name="interests"
|
|
251
|
+
* label="Interests"
|
|
252
|
+
* control={form.control}
|
|
253
|
+
* options={[
|
|
254
|
+
* { value: 'sports', label: 'Sports' },
|
|
255
|
+
* { value: 'music', label: 'Music' },
|
|
256
|
+
* { value: 'tech', label: 'Technology' },
|
|
257
|
+
* ]}
|
|
258
|
+
* layout="grid"
|
|
259
|
+
* />
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
declare function FormMultiSelect<TFieldValues extends FieldValues = FieldValues>({ name, label, options, required, helpText, disabled, className, control, layout, maxSelection, }: FormMultiSelectProps<TFieldValues>): react_jsx_runtime.JSX.Element;
|
|
263
|
+
|
|
264
|
+
interface FormLayoutProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
265
|
+
/**
|
|
266
|
+
* Number of columns for the form layout
|
|
267
|
+
* @default 1
|
|
268
|
+
*/
|
|
269
|
+
columns?: 1 | 2 | 3 | 4;
|
|
270
|
+
/**
|
|
271
|
+
* Spacing between form fields
|
|
272
|
+
* @default "md"
|
|
273
|
+
*/
|
|
274
|
+
spacing?: 'sm' | 'md' | 'lg';
|
|
275
|
+
/**
|
|
276
|
+
* Make the layout responsive (mobile: 1 col, tablet: 2 cols, desktop: specified cols)
|
|
277
|
+
* @default true
|
|
278
|
+
*/
|
|
279
|
+
responsive?: boolean;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* FormLayout - Ready-to-use form grid layout
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```tsx
|
|
286
|
+
* <FormLayout columns={2}>
|
|
287
|
+
* <FormField name="firstName" label="First Name" control={form.control} />
|
|
288
|
+
* <FormField name="lastName" label="Last Name" control={form.control} />
|
|
289
|
+
* </FormLayout>
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
declare function FormLayout({ columns, spacing, responsive, className, children, ...props }: FormLayoutProps): react_jsx_runtime.JSX.Element;
|
|
293
|
+
declare namespace FormLayout {
|
|
294
|
+
var displayName: string;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
interface FormSectionProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
298
|
+
/**
|
|
299
|
+
* Section title
|
|
300
|
+
*/
|
|
301
|
+
title?: string;
|
|
302
|
+
/**
|
|
303
|
+
* Section description
|
|
304
|
+
*/
|
|
305
|
+
description?: string;
|
|
306
|
+
/**
|
|
307
|
+
* Number of columns for this section
|
|
308
|
+
* @default 1
|
|
309
|
+
*/
|
|
310
|
+
columns?: 1 | 2 | 3 | 4;
|
|
311
|
+
/**
|
|
312
|
+
* Spacing between fields
|
|
313
|
+
* @default "md"
|
|
314
|
+
*/
|
|
315
|
+
spacing?: 'sm' | 'md' | 'lg';
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* FormSection - Section with title and grid layout
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```tsx
|
|
322
|
+
* <FormSection title="Personal Info" description="Enter your details" columns={2}>
|
|
323
|
+
* <FormField name="name" label="Name" control={form.control} />
|
|
324
|
+
* <FormField name="email" label="Email" control={form.control} />
|
|
325
|
+
* </FormSection>
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
declare function FormSection({ title, description, columns, spacing, className, children, ...props }: FormSectionProps): react_jsx_runtime.JSX.Element;
|
|
329
|
+
declare namespace FormSection {
|
|
330
|
+
var displayName: string;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
interface FormGridProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
334
|
+
/**
|
|
335
|
+
* Spacing between items
|
|
336
|
+
* @default "md"
|
|
337
|
+
*/
|
|
338
|
+
spacing?: 'sm' | 'md' | 'lg';
|
|
339
|
+
}
|
|
340
|
+
interface FormGridItemProps extends React$1.HTMLAttributes<HTMLDivElement> {
|
|
341
|
+
/**
|
|
342
|
+
* Column span for the item
|
|
343
|
+
* @default 1
|
|
344
|
+
*/
|
|
345
|
+
colSpan?: 1 | 2 | 3 | 4 | 'full';
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* FormGrid - Advanced grid layout with col-span support
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```tsx
|
|
352
|
+
* <FormGrid>
|
|
353
|
+
* <FormGridItem>
|
|
354
|
+
* <FormField name="firstName" label="First Name" control={form.control} />
|
|
355
|
+
* </FormGridItem>
|
|
356
|
+
* <FormGridItem>
|
|
357
|
+
* <FormField name="lastName" label="Last Name" control={form.control} />
|
|
358
|
+
* </FormGridItem>
|
|
359
|
+
* <FormGridItem colSpan="full">
|
|
360
|
+
* <FormField name="bio" label="Bio" control={form.control} />
|
|
361
|
+
* </FormGridItem>
|
|
362
|
+
* </FormGrid>
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
declare function FormGrid({ spacing, className, children, ...props }: FormGridProps): react_jsx_runtime.JSX.Element;
|
|
366
|
+
declare namespace FormGrid {
|
|
367
|
+
var displayName: string;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* FormGridItem - Item within FormGrid with custom column span
|
|
371
|
+
*/
|
|
372
|
+
declare function FormGridItem({ colSpan, className, children, ...props }: FormGridItemProps): react_jsx_runtime.JSX.Element;
|
|
373
|
+
declare namespace FormGridItem {
|
|
374
|
+
var displayName: string;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
interface FormWizardStep {
|
|
378
|
+
title: string;
|
|
379
|
+
description?: string;
|
|
380
|
+
content: React$1.ReactNode;
|
|
381
|
+
onValidate?: () => boolean | Promise<boolean>;
|
|
382
|
+
}
|
|
383
|
+
interface FormWizardProps {
|
|
384
|
+
steps: FormWizardStep[];
|
|
385
|
+
onComplete: () => void | Promise<void>;
|
|
386
|
+
onCancel?: () => void;
|
|
387
|
+
className?: string;
|
|
388
|
+
showStepNumbers?: boolean;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Form Wizard component for multi-step forms
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```tsx
|
|
395
|
+
* <FormWizard
|
|
396
|
+
* steps={[
|
|
397
|
+
* {
|
|
398
|
+
* title: 'Personal Info',
|
|
399
|
+
* content: <PersonalInfoForm />,
|
|
400
|
+
* onValidate: () => form.trigger(['name', 'email']),
|
|
401
|
+
* },
|
|
402
|
+
* {
|
|
403
|
+
* title: 'Address',
|
|
404
|
+
* content: <AddressForm />,
|
|
405
|
+
* },
|
|
406
|
+
* ]}
|
|
407
|
+
* onComplete={() => form.handleSubmit(onSubmit)()}
|
|
408
|
+
* />
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
declare function FormWizard({ steps, onComplete, onCancel, className, showStepNumbers, }: FormWizardProps): react_jsx_runtime.JSX.Element;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Field array options
|
|
415
|
+
*/
|
|
416
|
+
interface FieldArrayOptions<TFieldValues extends FieldValues = FieldValues> {
|
|
417
|
+
/**
|
|
418
|
+
* Field array name
|
|
419
|
+
*/
|
|
420
|
+
name: ArrayPath<TFieldValues>;
|
|
421
|
+
/**
|
|
422
|
+
* Form control instance
|
|
423
|
+
*/
|
|
424
|
+
control: UseFormReturn<TFieldValues>['control'];
|
|
425
|
+
/**
|
|
426
|
+
* Default value for new items
|
|
427
|
+
*/
|
|
428
|
+
defaultValue?: unknown;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Wrapper around React Hook Form's useFieldArray with smart defaults
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```tsx
|
|
435
|
+
* const { fields, append, remove } = useSmartFieldArray({
|
|
436
|
+
* name: 'items',
|
|
437
|
+
* control: form.control,
|
|
438
|
+
* defaultValue: { name: '', quantity: 0 }
|
|
439
|
+
* })
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare function useSmartFieldArray<TFieldValues extends FieldValues = FieldValues>({ name, control, defaultValue, }: FieldArrayOptions<TFieldValues>): {
|
|
443
|
+
append: (value?: unknown) => void;
|
|
444
|
+
swap: react_hook_form.UseFieldArraySwap;
|
|
445
|
+
move: react_hook_form.UseFieldArrayMove;
|
|
446
|
+
prepend: react_hook_form.UseFieldArrayPrepend<TFieldValues, ArrayPath<TFieldValues>>;
|
|
447
|
+
remove: react_hook_form.UseFieldArrayRemove;
|
|
448
|
+
insert: react_hook_form.UseFieldArrayInsert<TFieldValues, ArrayPath<TFieldValues>>;
|
|
449
|
+
update: react_hook_form.UseFieldArrayUpdate<TFieldValues, ArrayPath<TFieldValues>>;
|
|
450
|
+
replace: react_hook_form.UseFieldArrayReplace<TFieldValues, ArrayPath<TFieldValues>>;
|
|
451
|
+
fields: react_hook_form.FieldArrayWithId<TFieldValues, ArrayPath<TFieldValues>, "id">[];
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Common Validation Schemas
|
|
456
|
+
*
|
|
457
|
+
* Reusable Zod schemas for common validation patterns.
|
|
458
|
+
*/
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Email validation schema
|
|
462
|
+
*/
|
|
463
|
+
declare const emailSchema: z.ZodString;
|
|
464
|
+
/**
|
|
465
|
+
* Password validation schema
|
|
466
|
+
* At least 8 characters, 1 uppercase, 1 lowercase, 1 number
|
|
467
|
+
*/
|
|
468
|
+
declare const passwordSchema: z.ZodString;
|
|
469
|
+
/**
|
|
470
|
+
* Strong password validation schema
|
|
471
|
+
* At least 12 characters, 1 uppercase, 1 lowercase, 1 number, 1 special character
|
|
472
|
+
*/
|
|
473
|
+
declare const strongPasswordSchema: z.ZodString;
|
|
474
|
+
/**
|
|
475
|
+
* Phone number validation schema (international format)
|
|
476
|
+
*/
|
|
477
|
+
declare const phoneSchema: z.ZodString;
|
|
478
|
+
/**
|
|
479
|
+
* URL validation schema
|
|
480
|
+
*/
|
|
481
|
+
declare const urlSchema: z.ZodString;
|
|
482
|
+
/**
|
|
483
|
+
* Username validation schema
|
|
484
|
+
* 3-20 characters, alphanumeric and underscores only
|
|
485
|
+
*/
|
|
486
|
+
declare const usernameSchema: z.ZodString;
|
|
487
|
+
/**
|
|
488
|
+
* Slug validation schema
|
|
489
|
+
* Lowercase letters, numbers, and hyphens only
|
|
490
|
+
*/
|
|
491
|
+
declare const slugSchema: z.ZodString;
|
|
492
|
+
/**
|
|
493
|
+
* Positive number schema
|
|
494
|
+
*/
|
|
495
|
+
declare const positiveNumberSchema: z.ZodNumber;
|
|
496
|
+
/**
|
|
497
|
+
* Positive integer schema
|
|
498
|
+
*/
|
|
499
|
+
declare const positiveIntegerSchema: z.ZodNumber;
|
|
500
|
+
/**
|
|
501
|
+
* Price schema (two decimal places)
|
|
502
|
+
*/
|
|
503
|
+
declare const priceSchema: z.ZodNumber;
|
|
504
|
+
/**
|
|
505
|
+
* Percentage schema (0-100)
|
|
506
|
+
*/
|
|
507
|
+
declare const percentageSchema: z.ZodNumber;
|
|
508
|
+
/**
|
|
509
|
+
* Date string schema (ISO format)
|
|
510
|
+
*/
|
|
511
|
+
declare const dateStringSchema: z.ZodString;
|
|
512
|
+
/**
|
|
513
|
+
* Future date schema
|
|
514
|
+
*/
|
|
515
|
+
declare const futureDateSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
516
|
+
/**
|
|
517
|
+
* Past date schema
|
|
518
|
+
*/
|
|
519
|
+
declare const pastDateSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
520
|
+
/**
|
|
521
|
+
* File size validation helper
|
|
522
|
+
*/
|
|
523
|
+
declare const createFileSizeSchema: (maxSizeInBytes: number, message?: string) => z.ZodEffects<z.ZodType<File, z.ZodTypeDef, File>, File, File>;
|
|
524
|
+
/**
|
|
525
|
+
* File type validation helper
|
|
526
|
+
*/
|
|
527
|
+
declare const createFileTypeSchema: (allowedTypes: string[], message?: string) => z.ZodEffects<z.ZodType<File, z.ZodTypeDef, File>, File, File>;
|
|
528
|
+
/**
|
|
529
|
+
* Image file schema (common image types, max 5MB)
|
|
530
|
+
*/
|
|
531
|
+
declare const imageFileSchema: z.ZodEffects<z.ZodEffects<z.ZodType<File, z.ZodTypeDef, File>, File, File>, File, File>;
|
|
532
|
+
/**
|
|
533
|
+
* Confirm password schema helper
|
|
534
|
+
*/
|
|
535
|
+
declare const createConfirmPasswordSchema: (passwordField: string) => z.ZodEffects<z.ZodObject<{
|
|
536
|
+
[x: string]: z.ZodString;
|
|
537
|
+
confirmPassword: z.ZodString;
|
|
538
|
+
}, "strip", z.ZodTypeAny, {
|
|
539
|
+
[x: string]: string;
|
|
540
|
+
confirmPassword?: unknown;
|
|
541
|
+
}, {
|
|
542
|
+
[x: string]: string;
|
|
543
|
+
confirmPassword?: unknown;
|
|
544
|
+
}>, {
|
|
545
|
+
[x: string]: string;
|
|
546
|
+
confirmPassword?: unknown;
|
|
547
|
+
}, {
|
|
548
|
+
[x: string]: string;
|
|
549
|
+
confirmPassword?: unknown;
|
|
550
|
+
}>;
|
|
551
|
+
/**
|
|
552
|
+
* Optional email schema (can be empty or valid email)
|
|
553
|
+
*/
|
|
554
|
+
declare const optionalEmailSchema: z.ZodUnion<[z.ZodString, z.ZodString]>;
|
|
555
|
+
/**
|
|
556
|
+
* Optional URL schema
|
|
557
|
+
*/
|
|
558
|
+
declare const optionalUrlSchema: z.ZodUnion<[z.ZodString, z.ZodString]>;
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Validation Helper Utilities
|
|
562
|
+
*
|
|
563
|
+
* Helper functions for common validation patterns.
|
|
564
|
+
*/
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Get error message from field errors
|
|
568
|
+
*/
|
|
569
|
+
declare function getErrorMessage(errors: FieldErrors, fieldName: string): string | undefined;
|
|
570
|
+
/**
|
|
571
|
+
* Check if field has error
|
|
572
|
+
*/
|
|
573
|
+
declare function hasError(errors: FieldErrors, fieldName: string): boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Get all error messages as array
|
|
576
|
+
*/
|
|
577
|
+
declare function getAllErrors(errors: FieldErrors): string[];
|
|
578
|
+
/**
|
|
579
|
+
* Create a conditional schema based on another field
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```ts
|
|
583
|
+
* const schema = z.object({
|
|
584
|
+
* type: z.enum(['individual', 'company']),
|
|
585
|
+
* companyName: conditionalSchema(
|
|
586
|
+
* 'type',
|
|
587
|
+
* (type) => type === 'company',
|
|
588
|
+
* z.string().min(1, 'Company name is required')
|
|
589
|
+
* ),
|
|
590
|
+
* })
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
declare function conditionalSchema<T extends ZodTypeAny>(_dependentField: string, _condition: (value: any) => boolean, schema: T): ZodTypeAny;
|
|
594
|
+
/**
|
|
595
|
+
* Create min/max length message
|
|
596
|
+
*/
|
|
597
|
+
declare function lengthMessage(field: string, min?: number, max?: number): string;
|
|
598
|
+
/**
|
|
599
|
+
* Create required field message
|
|
600
|
+
*/
|
|
601
|
+
declare function requiredMessage(field: string): string;
|
|
602
|
+
/**
|
|
603
|
+
* Create invalid format message
|
|
604
|
+
*/
|
|
605
|
+
declare function invalidFormatMessage(field: string): string;
|
|
606
|
+
/**
|
|
607
|
+
* Validate credit card using Luhn algorithm
|
|
608
|
+
*/
|
|
609
|
+
declare function validateCreditCard(cardNumber: string): boolean;
|
|
610
|
+
/**
|
|
611
|
+
* Validate IBAN (International Bank Account Number)
|
|
612
|
+
*/
|
|
613
|
+
declare function validateIBAN(iban: string): boolean;
|
|
614
|
+
/**
|
|
615
|
+
* Validate strong password requirements
|
|
616
|
+
*/
|
|
617
|
+
declare function validatePasswordStrength(password: string): {
|
|
618
|
+
isStrong: boolean;
|
|
619
|
+
missingRequirements: string[];
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* Sanitize string input (remove HTML, trim, normalize whitespace)
|
|
623
|
+
*/
|
|
624
|
+
declare function sanitizeString(input: string): string;
|
|
625
|
+
/**
|
|
626
|
+
* Validate file extension
|
|
627
|
+
*/
|
|
628
|
+
declare function validateFileExtension(filename: string, allowedExtensions: string[]): boolean;
|
|
629
|
+
/**
|
|
630
|
+
* Format validation error for display
|
|
631
|
+
*/
|
|
632
|
+
declare function formatValidationError(error: z.ZodError): Record<string, string>;
|
|
633
|
+
|
|
634
|
+
export { type FieldArrayOptions, FormCheckbox, type FormCheckboxProps, FormDatePicker, type FormDatePickerProps, FormField, type FormFieldProps, FormFileUpload, type FormFileUploadProps, FormGrid, FormGridItem, type FormGridItemProps, type FormGridProps, FormLayout, type FormLayoutProps, FormMultiSelect, type FormMultiSelectProps, FormSection, type FormSectionProps, FormSelect, type FormSelectProps, FormTextarea, type FormTextareaProps, FormWizard, type FormWizardProps, type FormWizardStep, type MultiSelectOption, type SelectOption, type SmartFormOptions, type SmartFormReturn, conditionalSchema, createConfirmPasswordSchema, createFileSizeSchema, createFileTypeSchema, dateStringSchema, emailSchema, formatValidationError, futureDateSchema, getAllErrors, getErrorMessage, hasError, imageFileSchema, invalidFormatMessage, lengthMessage, optionalEmailSchema, optionalUrlSchema, passwordSchema, pastDateSchema, percentageSchema, phoneSchema, positiveIntegerSchema, positiveNumberSchema, priceSchema, requiredMessage, sanitizeString, slugSchema, strongPasswordSchema, urlSchema, useSmartFieldArray, useSmartForm, usernameSchema, validateCreditCard, validateFileExtension, validateIBAN, validatePasswordStrength };
|