@rachelallyson/hero-hook-form 1.2.0 → 2.1.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.
- package/CHANGELOG.md +96 -0
- package/README.md +115 -351
- package/dist/cypress/index.d.ts +141 -0
- package/dist/cypress/index.js +897 -0
- package/dist/index.d.ts +789 -15
- package/dist/index.js +2414 -422
- package/dist/react/index.d.ts +789 -15
- package/dist/react/index.js +2414 -422
- package/package.json +65 -33
package/dist/react/index.d.ts
CHANGED
|
@@ -95,7 +95,27 @@ interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFi
|
|
|
95
95
|
isSubmitting: boolean;
|
|
96
96
|
}) => React.ReactNode;
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
interface ConditionalFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
99
|
+
type: "conditional";
|
|
100
|
+
condition: (formData: Partial<TFieldValues>) => boolean;
|
|
101
|
+
field: ZodFormFieldConfig<TFieldValues>;
|
|
102
|
+
}
|
|
103
|
+
interface FieldArrayConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
104
|
+
type: "fieldArray";
|
|
105
|
+
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
106
|
+
min?: number;
|
|
107
|
+
max?: number;
|
|
108
|
+
addButtonText?: string;
|
|
109
|
+
removeButtonText?: string;
|
|
110
|
+
}
|
|
111
|
+
interface DynamicSectionConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
112
|
+
type: "dynamicSection";
|
|
113
|
+
title?: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
condition: (formData: Partial<TFieldValues>) => boolean;
|
|
116
|
+
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
117
|
+
}
|
|
118
|
+
type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | FontPickerFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues> | ConditionalFieldConfig<TFieldValues> | FieldArrayConfig<TFieldValues> | DynamicSectionConfig<TFieldValues>;
|
|
99
119
|
interface FormConfig<TFieldValues extends FieldValues> {
|
|
100
120
|
fields: FormFieldConfig<TFieldValues>[];
|
|
101
121
|
layout?: "vertical" | "horizontal" | "grid" | "custom";
|
|
@@ -109,7 +129,7 @@ interface FormConfig<TFieldValues extends FieldValues> {
|
|
|
109
129
|
className?: string;
|
|
110
130
|
defaultValues?: Partial<TFieldValues>;
|
|
111
131
|
}
|
|
112
|
-
type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules"> | Omit<FontPickerFieldConfig<TFieldValues>, "rules"> | Omit<CustomFieldConfig<TFieldValues>, "rules">;
|
|
132
|
+
type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules"> | Omit<FontPickerFieldConfig<TFieldValues>, "rules"> | Omit<CustomFieldConfig<TFieldValues>, "rules"> | Omit<ConditionalFieldConfig<TFieldValues>, "rules"> | Omit<FieldArrayConfig<TFieldValues>, "rules"> | Omit<DynamicSectionConfig<TFieldValues>, "rules">;
|
|
113
133
|
interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
|
|
114
134
|
schema: zod.ZodSchema<TFieldValues>;
|
|
115
135
|
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
@@ -212,7 +232,76 @@ interface FormFieldProps<TFieldValues extends FieldValues> {
|
|
|
212
232
|
form: UseFormReturn<TFieldValues>;
|
|
213
233
|
submissionState: FormSubmissionState;
|
|
214
234
|
}
|
|
215
|
-
declare
|
|
235
|
+
declare const FormField: <TFieldValues extends FieldValues>(props: FormFieldProps<TFieldValues>) => React$1.JSX.Element;
|
|
236
|
+
|
|
237
|
+
type ServerAction<TState = unknown, TFormData = FormData> = (state: TState | undefined, formData: TFormData) => Promise<TState>;
|
|
238
|
+
interface ActionState {
|
|
239
|
+
errors?: Record<string, string[]>;
|
|
240
|
+
message?: string;
|
|
241
|
+
success?: boolean;
|
|
242
|
+
}
|
|
243
|
+
interface ServerActionFormProps<T extends FieldValues> {
|
|
244
|
+
/** Server Action function (Next.js pattern) */
|
|
245
|
+
action: ServerAction<ActionState, FormData>;
|
|
246
|
+
/** Optional: Zod schema for client-side validation before submission */
|
|
247
|
+
clientValidationSchema?: z.ZodSchema<T>;
|
|
248
|
+
className?: string;
|
|
249
|
+
columns?: 1 | 2 | 3;
|
|
250
|
+
/** Default values for form fields */
|
|
251
|
+
defaultValues?: Partial<T>;
|
|
252
|
+
fields: FormFieldConfig<T>[];
|
|
253
|
+
/** Initial state for useActionState */
|
|
254
|
+
initialState?: ActionState;
|
|
255
|
+
layout?: "vertical" | "horizontal" | "grid";
|
|
256
|
+
/** Callback when form submission encounters an error */
|
|
257
|
+
onError?: (error: {
|
|
258
|
+
errors?: Record<string, string[]>;
|
|
259
|
+
message?: string;
|
|
260
|
+
}) => void;
|
|
261
|
+
/** Callback when form submission succeeds */
|
|
262
|
+
onSuccess?: (data: FormData) => void;
|
|
263
|
+
resetButtonText?: string;
|
|
264
|
+
showResetButton?: boolean;
|
|
265
|
+
spacing?: "2" | "4" | "6" | "8" | "lg";
|
|
266
|
+
submitButtonProps?: Partial<React$1.ComponentProps<typeof Button>>;
|
|
267
|
+
submitButtonText?: string;
|
|
268
|
+
subtitle?: string;
|
|
269
|
+
title?: string;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* ServerActionForm - A form component compatible with Next.js Server Actions
|
|
273
|
+
*
|
|
274
|
+
* This component works with Next.js authentication patterns by using native
|
|
275
|
+
* HTML form submission with Server Actions, while still providing the
|
|
276
|
+
* beautiful HeroUI field components.
|
|
277
|
+
*
|
|
278
|
+
* **Validation Options:**
|
|
279
|
+
* - **Server-side only (default)**: Form submits directly to Server Action
|
|
280
|
+
* - **Client + Server (optional)**: Pass `clientValidationSchema` for client-side
|
|
281
|
+
* validation before submission. Server Action still validates (defense in depth).
|
|
282
|
+
*
|
|
283
|
+
* **Important Notes:**
|
|
284
|
+
* - If your Server Action calls `redirect()`, success messages won't display
|
|
285
|
+
* (the page navigates away). Use URL params or cookies for success messages
|
|
286
|
+
* when redirecting.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```tsx
|
|
290
|
+
* // Server-side only validation
|
|
291
|
+
* <ServerActionForm
|
|
292
|
+
* action={signup}
|
|
293
|
+
* fields={[...]}
|
|
294
|
+
* />
|
|
295
|
+
*
|
|
296
|
+
* // Client + Server validation
|
|
297
|
+
* <ServerActionForm
|
|
298
|
+
* action={signup}
|
|
299
|
+
* clientValidationSchema={signupSchema}
|
|
300
|
+
* fields={[...]}
|
|
301
|
+
* />
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
declare function ServerActionForm<T extends FieldValues>({ action, className, clientValidationSchema, columns, defaultValues, fields, initialState, layout, onError, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ServerActionFormProps<T>): React$1.JSX.Element;
|
|
216
305
|
|
|
217
306
|
type CheckboxFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
218
307
|
checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
@@ -248,7 +337,7 @@ type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldVa
|
|
|
248
337
|
inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
249
338
|
transform?: (value: string) => string;
|
|
250
339
|
};
|
|
251
|
-
declare
|
|
340
|
+
declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
|
|
252
341
|
|
|
253
342
|
interface RadioOption<TValue extends string | number> {
|
|
254
343
|
label: string;
|
|
@@ -410,9 +499,38 @@ interface FormProps<TFieldValues extends FieldValues> {
|
|
|
410
499
|
}
|
|
411
500
|
declare function FormProvider<TFieldValues extends FieldValues>(props: FormProps<TFieldValues>): React$1.JSX.Element;
|
|
412
501
|
|
|
502
|
+
interface EnhancedFormState<T extends FieldValues> {
|
|
503
|
+
status: "idle" | "submitting" | "success" | "error";
|
|
504
|
+
isSubmitting: boolean;
|
|
505
|
+
isSuccess: boolean;
|
|
506
|
+
isError: boolean;
|
|
507
|
+
error?: string;
|
|
508
|
+
submittedData?: T;
|
|
509
|
+
touchedFields: Set<Path<T>>;
|
|
510
|
+
dirtyFields: Set<Path<T>>;
|
|
511
|
+
hasErrors: boolean;
|
|
512
|
+
errorCount: number;
|
|
513
|
+
handleSuccess: (data: T) => void;
|
|
514
|
+
handleError: (error: string) => void;
|
|
515
|
+
reset: () => void;
|
|
516
|
+
}
|
|
517
|
+
interface UseEnhancedFormStateOptions<T extends FieldValues> {
|
|
518
|
+
onSuccess?: (data: T) => void;
|
|
519
|
+
onError?: (error: string) => void;
|
|
520
|
+
successMessage?: string;
|
|
521
|
+
errorMessage?: string;
|
|
522
|
+
autoReset?: boolean;
|
|
523
|
+
resetDelay?: number;
|
|
524
|
+
}
|
|
525
|
+
declare function useEnhancedFormState<T extends FieldValues>(form: UseFormReturn<T>, options?: UseEnhancedFormStateOptions<T>): EnhancedFormState<T>;
|
|
526
|
+
|
|
413
527
|
interface SubmitButtonProps {
|
|
414
528
|
children: React$1.ReactNode;
|
|
415
529
|
isLoading?: boolean;
|
|
530
|
+
isSuccess?: boolean;
|
|
531
|
+
successText?: string;
|
|
532
|
+
loadingText?: string;
|
|
533
|
+
enhancedState?: EnhancedFormState<any>;
|
|
416
534
|
buttonProps?: Omit<React$1.ComponentProps<typeof Button>, "type" | "isLoading">;
|
|
417
535
|
}
|
|
418
536
|
declare function SubmitButton(props: SubmitButtonProps): React$1.JSX.Element;
|
|
@@ -505,10 +623,6 @@ declare const createPhoneSchema: () => z.ZodString;
|
|
|
505
623
|
* Creates a password validation schema with common requirements
|
|
506
624
|
*/
|
|
507
625
|
declare const createPasswordSchema: (minLength?: number) => z.ZodString;
|
|
508
|
-
/**
|
|
509
|
-
* Creates a confirm password validation schema
|
|
510
|
-
*/
|
|
511
|
-
declare const createConfirmPasswordSchema: (passwordField: string) => z.ZodString;
|
|
512
626
|
/**
|
|
513
627
|
* Creates a number validation schema with range
|
|
514
628
|
*/
|
|
@@ -534,15 +648,35 @@ declare const createFileSchema: (maxSizeInMB?: number, allowedTypes?: string[])
|
|
|
534
648
|
*/
|
|
535
649
|
declare const createRequiredCheckboxSchema: (fieldName: string) => z.ZodBoolean;
|
|
536
650
|
/**
|
|
537
|
-
*
|
|
651
|
+
* Cross-field validation helpers
|
|
538
652
|
*/
|
|
539
|
-
declare const
|
|
653
|
+
declare const crossFieldValidation: {
|
|
654
|
+
/**
|
|
655
|
+
* Conditional required field validation
|
|
656
|
+
*/
|
|
657
|
+
conditionalRequired: (field: string, conditionField: string, conditionValue: any) => z.ZodObject<{
|
|
658
|
+
[x: string]: z.ZodString | z.ZodAny;
|
|
659
|
+
}, z.core.$strip>;
|
|
660
|
+
/**
|
|
661
|
+
* Date range validation
|
|
662
|
+
*/
|
|
663
|
+
dateRange: (startField: string, endField: string) => z.ZodObject<{
|
|
664
|
+
[x: string]: z.ZodString;
|
|
665
|
+
}, z.core.$strip>;
|
|
666
|
+
/**
|
|
667
|
+
* Password confirmation validation
|
|
668
|
+
*/
|
|
669
|
+
passwordConfirmation: (passwordField: string, confirmField: string) => z.ZodObject<{
|
|
670
|
+
[x: string]: z.ZodString;
|
|
671
|
+
}, z.core.$strip>;
|
|
672
|
+
};
|
|
540
673
|
/**
|
|
541
674
|
* Common validation patterns for forms
|
|
542
675
|
*/
|
|
543
676
|
declare const commonValidations: {
|
|
544
|
-
|
|
545
|
-
|
|
677
|
+
confirmPassword: (passwordField: string, confirmField: string) => z.ZodObject<{
|
|
678
|
+
[x: string]: z.ZodString;
|
|
679
|
+
}, z.core.$strip>;
|
|
546
680
|
date: (fieldName: string) => z.ZodDate;
|
|
547
681
|
email: z.ZodEmail;
|
|
548
682
|
file: (maxSizeInMB?: number, allowedTypes?: string[]) => z.ZodCustom<File, File>;
|
|
@@ -573,7 +707,6 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
573
707
|
submitButtonText?: string;
|
|
574
708
|
subtitle?: string;
|
|
575
709
|
title?: string;
|
|
576
|
-
errorDisplay?: "inline" | "toast" | "modal" | "none";
|
|
577
710
|
render?: (formState: {
|
|
578
711
|
form: UseFormReturn<T>;
|
|
579
712
|
isSubmitting: boolean;
|
|
@@ -583,7 +716,7 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
583
716
|
values: T;
|
|
584
717
|
}) => React$1.ReactNode;
|
|
585
718
|
}
|
|
586
|
-
declare function ZodForm<T extends FieldValues>({ className, columns, config,
|
|
719
|
+
declare function ZodForm<T extends FieldValues>({ className, columns, config, layout, onError, onSubmit, onSuccess, render, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ZodFormProps<T>): string | number | bigint | boolean | Iterable<React$1.ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<React$1.ReactNode> | null | undefined> | React$1.JSX.Element | null | undefined;
|
|
587
720
|
|
|
588
721
|
/**
|
|
589
722
|
* Hook for using Zod validation with React Hook Form
|
|
@@ -594,4 +727,645 @@ declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormCon
|
|
|
594
727
|
*/
|
|
595
728
|
declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: Partial<TFieldValues>): ZodFormConfig<TFieldValues>;
|
|
596
729
|
|
|
597
|
-
|
|
730
|
+
/**
|
|
731
|
+
* Basic form field builder that eliminates "as const" assertions
|
|
732
|
+
* Focuses on the most common use cases
|
|
733
|
+
*/
|
|
734
|
+
declare class BasicFormBuilder<T extends FieldValues> {
|
|
735
|
+
private fields;
|
|
736
|
+
/**
|
|
737
|
+
* Add an input field
|
|
738
|
+
*/
|
|
739
|
+
input(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password"): this;
|
|
740
|
+
/**
|
|
741
|
+
* Add a textarea field
|
|
742
|
+
*/
|
|
743
|
+
textarea(name: Path<T>, label: string, placeholder?: string): this;
|
|
744
|
+
/**
|
|
745
|
+
* Add a select field
|
|
746
|
+
*/
|
|
747
|
+
select(name: Path<T>, label: string, options: {
|
|
748
|
+
label: string;
|
|
749
|
+
value: string | number;
|
|
750
|
+
}[]): this;
|
|
751
|
+
/**
|
|
752
|
+
* Add a checkbox field
|
|
753
|
+
*/
|
|
754
|
+
checkbox(name: Path<T>, label: string): this;
|
|
755
|
+
/**
|
|
756
|
+
* Add a switch field
|
|
757
|
+
*/
|
|
758
|
+
switch(name: Path<T>, label: string): this;
|
|
759
|
+
/**
|
|
760
|
+
* Build the final field configuration array
|
|
761
|
+
*/
|
|
762
|
+
build(): ZodFormFieldConfig<T>[];
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Create a new simple form field builder
|
|
766
|
+
*/
|
|
767
|
+
declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuilder<T>;
|
|
768
|
+
/**
|
|
769
|
+
* Simple helper functions for common field types
|
|
770
|
+
*/
|
|
771
|
+
declare const FormFieldHelpers: {
|
|
772
|
+
/**
|
|
773
|
+
* Create a checkbox field
|
|
774
|
+
*/
|
|
775
|
+
checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
|
|
776
|
+
/**
|
|
777
|
+
* Create an input field
|
|
778
|
+
*/
|
|
779
|
+
input: <T extends FieldValues>(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password") => ZodFormFieldConfig<T>;
|
|
780
|
+
/**
|
|
781
|
+
* Create a select field
|
|
782
|
+
*/
|
|
783
|
+
select: <T extends FieldValues>(name: Path<T>, label: string, options: {
|
|
784
|
+
label: string;
|
|
785
|
+
value: string | number;
|
|
786
|
+
}[]) => ZodFormFieldConfig<T>;
|
|
787
|
+
/**
|
|
788
|
+
* Create a switch field
|
|
789
|
+
*/
|
|
790
|
+
switch: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
|
|
791
|
+
/**
|
|
792
|
+
* Create a textarea field
|
|
793
|
+
*/
|
|
794
|
+
textarea: <T extends FieldValues>(name: Path<T>, label: string, placeholder?: string) => ZodFormFieldConfig<T>;
|
|
795
|
+
};
|
|
796
|
+
/**
|
|
797
|
+
* Common field collections
|
|
798
|
+
*/
|
|
799
|
+
declare const CommonFields: {
|
|
800
|
+
/**
|
|
801
|
+
* Address fields
|
|
802
|
+
*/
|
|
803
|
+
address: <T extends FieldValues>() => ZodFormFieldConfig<T>[];
|
|
804
|
+
/**
|
|
805
|
+
* Personal information fields
|
|
806
|
+
*/
|
|
807
|
+
personal: <T extends FieldValues>() => ZodFormFieldConfig<T>[];
|
|
808
|
+
/**
|
|
809
|
+
* Terms and conditions fields
|
|
810
|
+
*/
|
|
811
|
+
terms: <T extends FieldValues>() => ZodFormFieldConfig<T>[];
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Unified field creation function
|
|
816
|
+
* Takes field type as first argument and delegates to appropriate helper
|
|
817
|
+
*/
|
|
818
|
+
declare function createField<T extends FieldValues>(type: string, name: Path<T>, label: string, optionsOrProps?: any, props?: any): ZodFormFieldConfig<T>;
|
|
819
|
+
/**
|
|
820
|
+
* Builder pattern for advanced field creation
|
|
821
|
+
*/
|
|
822
|
+
declare class AdvancedFieldBuilder<T extends FieldValues> {
|
|
823
|
+
private fields;
|
|
824
|
+
/**
|
|
825
|
+
* Add any field type using the unified API
|
|
826
|
+
*/
|
|
827
|
+
field(type: "input", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
|
|
828
|
+
field(type: "textarea", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
|
|
829
|
+
field(type: "select", name: Path<T>, label: string, options: {
|
|
830
|
+
label: string;
|
|
831
|
+
value: string | number;
|
|
832
|
+
}[], props?: Parameters<typeof createField<T>>[4]): this;
|
|
833
|
+
field(type: "checkbox", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
|
|
834
|
+
field(type: "switch", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
|
|
835
|
+
field(type: "radio", name: Path<T>, label: string, options: {
|
|
836
|
+
label: string;
|
|
837
|
+
value: string | number;
|
|
838
|
+
}[], props?: Parameters<typeof createField<T>>[4]): this;
|
|
839
|
+
field(type: "slider", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
|
|
840
|
+
field(type: "date", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
|
|
841
|
+
field(type: "file", name: Path<T>, label: string, props?: Parameters<typeof createField<T>>[3]): this;
|
|
842
|
+
/**
|
|
843
|
+
* Add a conditional field that shows/hides based on form data
|
|
844
|
+
*/
|
|
845
|
+
conditionalField(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>): this;
|
|
846
|
+
/**
|
|
847
|
+
* Add a field array for dynamic repeating field groups
|
|
848
|
+
*/
|
|
849
|
+
fieldArray(name: Path<T>, label: string, fields: ZodFormFieldConfig<any>[], options?: {
|
|
850
|
+
min?: number;
|
|
851
|
+
max?: number;
|
|
852
|
+
addButtonText?: string;
|
|
853
|
+
removeButtonText?: string;
|
|
854
|
+
}): this;
|
|
855
|
+
/**
|
|
856
|
+
* Add a dynamic section that shows/hides based on form data
|
|
857
|
+
*/
|
|
858
|
+
dynamicSection(name: Path<T>, condition: (formData: Partial<T>) => boolean, fields: ZodFormFieldConfig<T>[], options?: {
|
|
859
|
+
title?: string;
|
|
860
|
+
description?: string;
|
|
861
|
+
}): this;
|
|
862
|
+
/**
|
|
863
|
+
* Build the final field configuration array
|
|
864
|
+
*/
|
|
865
|
+
build(): ZodFormFieldConfig<T>[];
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Field Array Builder for strongly-typed array item fields
|
|
869
|
+
*/
|
|
870
|
+
declare class FieldArrayItemBuilder<TItem extends FieldValues> {
|
|
871
|
+
private fields;
|
|
872
|
+
/**
|
|
873
|
+
* Add any field type using the unified API for array items
|
|
874
|
+
*/
|
|
875
|
+
field(type: "input", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
876
|
+
field(type: "textarea", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
877
|
+
field(type: "select", name: Path<TItem>, label: string, options: {
|
|
878
|
+
label: string;
|
|
879
|
+
value: string | number;
|
|
880
|
+
}[], props?: Parameters<typeof createField<TItem>>[4]): this;
|
|
881
|
+
field(type: "checkbox", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
882
|
+
field(type: "switch", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
883
|
+
field(type: "radio", name: Path<TItem>, label: string, options: {
|
|
884
|
+
label: string;
|
|
885
|
+
value: string | number;
|
|
886
|
+
}[], props?: Parameters<typeof createField<TItem>>[4]): this;
|
|
887
|
+
field(type: "slider", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
888
|
+
field(type: "date", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
889
|
+
field(type: "file", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
890
|
+
field(type: "fontPicker", name: Path<TItem>, label: string, props?: Parameters<typeof createField<TItem>>[3]): this;
|
|
891
|
+
/**
|
|
892
|
+
* Build the field array item configuration
|
|
893
|
+
*/
|
|
894
|
+
build(): ZodFormFieldConfig<TItem>[];
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Create a field array item builder for strongly-typed array fields
|
|
898
|
+
*/
|
|
899
|
+
declare function createFieldArrayItemBuilder<TItem extends FieldValues>(): FieldArrayItemBuilder<TItem>;
|
|
900
|
+
/**
|
|
901
|
+
* Field Array Builder for constructing field arrays with proper paths
|
|
902
|
+
*/
|
|
903
|
+
declare class FieldArrayBuilder<T extends FieldValues, TArrayName extends Path<T>> {
|
|
904
|
+
private arrayName;
|
|
905
|
+
private fields;
|
|
906
|
+
constructor(arrayName: TArrayName);
|
|
907
|
+
field(type: string, name: string, label: string, optionsOrProps?: any, props?: any): this;
|
|
908
|
+
build(): ZodFormFieldConfig<any>[];
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Create a field array builder that constructs proper paths for array items
|
|
912
|
+
*/
|
|
913
|
+
declare function createFieldArrayBuilder<T extends FieldValues, TArrayName extends Path<T>>(arrayName: TArrayName): FieldArrayBuilder<T, TArrayName>;
|
|
914
|
+
/**
|
|
915
|
+
* Create a new advanced field builder
|
|
916
|
+
*/
|
|
917
|
+
declare function createAdvancedBuilder<T extends FieldValues>(): AdvancedFieldBuilder<T>;
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Type-inferred form builder that auto-generates both schema and field configs
|
|
921
|
+
*/
|
|
922
|
+
declare class TypeInferredBuilder<T extends FieldValues> {
|
|
923
|
+
private schemaFields;
|
|
924
|
+
private formFields;
|
|
925
|
+
/**
|
|
926
|
+
* Add a text field
|
|
927
|
+
*/
|
|
928
|
+
text(name: Path<T>, label: string, options?: {
|
|
929
|
+
placeholder?: string;
|
|
930
|
+
description?: string;
|
|
931
|
+
isDisabled?: boolean;
|
|
932
|
+
className?: string;
|
|
933
|
+
minLength?: number;
|
|
934
|
+
maxLength?: number;
|
|
935
|
+
pattern?: string;
|
|
936
|
+
}): this;
|
|
937
|
+
/**
|
|
938
|
+
* Add an email field
|
|
939
|
+
*/
|
|
940
|
+
email(name: Path<T>, label: string, options?: {
|
|
941
|
+
placeholder?: string;
|
|
942
|
+
description?: string;
|
|
943
|
+
isDisabled?: boolean;
|
|
944
|
+
className?: string;
|
|
945
|
+
}): this;
|
|
946
|
+
/**
|
|
947
|
+
* Add a number field
|
|
948
|
+
*/
|
|
949
|
+
number(name: Path<T>, label: string, options?: {
|
|
950
|
+
placeholder?: string;
|
|
951
|
+
description?: string;
|
|
952
|
+
isDisabled?: boolean;
|
|
953
|
+
className?: string;
|
|
954
|
+
min?: number;
|
|
955
|
+
max?: number;
|
|
956
|
+
step?: number;
|
|
957
|
+
}): this;
|
|
958
|
+
/**
|
|
959
|
+
* Add a textarea field
|
|
960
|
+
*/
|
|
961
|
+
textarea(name: Path<T>, label: string, options?: {
|
|
962
|
+
placeholder?: string;
|
|
963
|
+
description?: string;
|
|
964
|
+
isDisabled?: boolean;
|
|
965
|
+
className?: string;
|
|
966
|
+
rows?: number;
|
|
967
|
+
minLength?: number;
|
|
968
|
+
}): this;
|
|
969
|
+
/**
|
|
970
|
+
* Add a select field
|
|
971
|
+
*/
|
|
972
|
+
select(name: Path<T>, label: string, options: {
|
|
973
|
+
label: string;
|
|
974
|
+
value: string | number;
|
|
975
|
+
}[]): this;
|
|
976
|
+
/**
|
|
977
|
+
* Add a checkbox field
|
|
978
|
+
*/
|
|
979
|
+
checkbox(name: Path<T>, label: string, options?: {
|
|
980
|
+
description?: string;
|
|
981
|
+
isDisabled?: boolean;
|
|
982
|
+
className?: string;
|
|
983
|
+
required?: boolean;
|
|
984
|
+
}): this;
|
|
985
|
+
/**
|
|
986
|
+
* Add a switch field
|
|
987
|
+
*/
|
|
988
|
+
switch(name: Path<T>, label: string, options?: {
|
|
989
|
+
description?: string;
|
|
990
|
+
isDisabled?: boolean;
|
|
991
|
+
className?: string;
|
|
992
|
+
}): this;
|
|
993
|
+
/**
|
|
994
|
+
* Add a radio field
|
|
995
|
+
*/
|
|
996
|
+
radio(name: Path<T>, label: string, options: {
|
|
997
|
+
label: string;
|
|
998
|
+
value: string | number;
|
|
999
|
+
}[], fieldOptions?: {
|
|
1000
|
+
description?: string;
|
|
1001
|
+
isDisabled?: boolean;
|
|
1002
|
+
className?: string;
|
|
1003
|
+
orientation?: "horizontal" | "vertical";
|
|
1004
|
+
}): this;
|
|
1005
|
+
/**
|
|
1006
|
+
* Add a slider field
|
|
1007
|
+
*/
|
|
1008
|
+
slider(name: Path<T>, label: string, options?: {
|
|
1009
|
+
min?: number;
|
|
1010
|
+
max?: number;
|
|
1011
|
+
step?: number;
|
|
1012
|
+
description?: string;
|
|
1013
|
+
isDisabled?: boolean;
|
|
1014
|
+
className?: string;
|
|
1015
|
+
}): this;
|
|
1016
|
+
/**
|
|
1017
|
+
* Add a date field
|
|
1018
|
+
*/
|
|
1019
|
+
date(name: Path<T>, label: string, options?: {
|
|
1020
|
+
placeholder?: string;
|
|
1021
|
+
description?: string;
|
|
1022
|
+
isDisabled?: boolean;
|
|
1023
|
+
className?: string;
|
|
1024
|
+
}): this;
|
|
1025
|
+
/**
|
|
1026
|
+
* Add a file field
|
|
1027
|
+
*/
|
|
1028
|
+
file(name: Path<T>, label: string, options?: {
|
|
1029
|
+
accept?: string;
|
|
1030
|
+
multiple?: boolean;
|
|
1031
|
+
description?: string;
|
|
1032
|
+
isDisabled?: boolean;
|
|
1033
|
+
className?: string;
|
|
1034
|
+
}): this;
|
|
1035
|
+
/**
|
|
1036
|
+
* Build the final schema and fields
|
|
1037
|
+
*/
|
|
1038
|
+
build(): {
|
|
1039
|
+
schema: z.ZodSchema<T>;
|
|
1040
|
+
fields: ZodFormFieldConfig<T>[];
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Create a new type-inferred form builder
|
|
1045
|
+
*/
|
|
1046
|
+
declare function createTypeInferredBuilder<T extends FieldValues>(): TypeInferredBuilder<T>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Define a form with type inference
|
|
1049
|
+
*/
|
|
1050
|
+
declare function defineInferredForm<T extends FieldValues>(fieldDefinitions: (builder: TypeInferredBuilder<T>) => TypeInferredBuilder<T>): {
|
|
1051
|
+
schema: z.ZodSchema<T>;
|
|
1052
|
+
fields: ZodFormFieldConfig<T>[];
|
|
1053
|
+
};
|
|
1054
|
+
/**
|
|
1055
|
+
* Field type builders for individual field creation
|
|
1056
|
+
*/
|
|
1057
|
+
declare const field: {
|
|
1058
|
+
checkbox: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["checkbox"]>[2]) => TypeInferredBuilder<T>;
|
|
1059
|
+
date: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["date"]>[2]) => TypeInferredBuilder<T>;
|
|
1060
|
+
email: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["email"]>[2]) => TypeInferredBuilder<T>;
|
|
1061
|
+
file: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["file"]>[2]) => TypeInferredBuilder<T>;
|
|
1062
|
+
number: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["number"]>[2]) => TypeInferredBuilder<T>;
|
|
1063
|
+
radio: <T extends FieldValues>(name: Path<T>, label: string, options: {
|
|
1064
|
+
label: string;
|
|
1065
|
+
value: string | number;
|
|
1066
|
+
}[], fieldOptions?: Parameters<TypeInferredBuilder<T>["radio"]>[3]) => TypeInferredBuilder<T>;
|
|
1067
|
+
select: <T extends FieldValues>(name: Path<T>, label: string, options: {
|
|
1068
|
+
label: string;
|
|
1069
|
+
value: string | number;
|
|
1070
|
+
}[]) => TypeInferredBuilder<T>;
|
|
1071
|
+
slider: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["slider"]>[2]) => TypeInferredBuilder<T>;
|
|
1072
|
+
switch: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["switch"]>[2]) => TypeInferredBuilder<T>;
|
|
1073
|
+
text: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["text"]>[2]) => TypeInferredBuilder<T>;
|
|
1074
|
+
textarea: <T extends FieldValues>(name: Path<T>, label: string, options?: Parameters<TypeInferredBuilder<T>["textarea"]>[2]) => TypeInferredBuilder<T>;
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Enhanced nested path builder with better syntax for complex nested structures
|
|
1079
|
+
* Provides multiple approaches for handling nested field paths
|
|
1080
|
+
*/
|
|
1081
|
+
declare class NestedPathBuilder<T extends FieldValues> {
|
|
1082
|
+
private fields;
|
|
1083
|
+
/**
|
|
1084
|
+
* Create a nested object path builder
|
|
1085
|
+
* Usage: builder.nest("address").field("street", "Street Address")
|
|
1086
|
+
*/
|
|
1087
|
+
nest<TPath extends Path<T>>(path: TPath): NestedObjectBuilder<T, TPath>;
|
|
1088
|
+
/**
|
|
1089
|
+
* Create a section-based path builder
|
|
1090
|
+
* Usage: builder.section("shipping").field("street", "Street Address")
|
|
1091
|
+
*/
|
|
1092
|
+
section<TPath extends Path<T>>(path: TPath): SectionBuilder<T, TPath>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Add a field with single path
|
|
1095
|
+
* Usage: builder.field("firstName", "First Name")
|
|
1096
|
+
*/
|
|
1097
|
+
field(name: Path<T>, label: string, type?: string, props?: any): this;
|
|
1098
|
+
/**
|
|
1099
|
+
* Add a field with path segments
|
|
1100
|
+
* Usage: builder.fieldPath(["user", "profile", "name"], "Full Name")
|
|
1101
|
+
*/
|
|
1102
|
+
fieldPath(path: string[], label: string, type?: string, props?: any): this;
|
|
1103
|
+
/**
|
|
1104
|
+
* Add a field with template literal path
|
|
1105
|
+
* Usage: builder.field`user.profile.name`("Full Name")
|
|
1106
|
+
*/
|
|
1107
|
+
fieldTemplate(path: TemplateStringsArray): FieldTemplateBuilder<T>;
|
|
1108
|
+
/**
|
|
1109
|
+
* Return to the parent builder (no-op for root builder)
|
|
1110
|
+
*/
|
|
1111
|
+
end(): this;
|
|
1112
|
+
build(): ZodFormFieldConfig<T>[];
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Nested object builder for chaining nested paths
|
|
1116
|
+
*/
|
|
1117
|
+
declare class NestedObjectBuilder<T extends FieldValues, TPath extends Path<T>> {
|
|
1118
|
+
private parent;
|
|
1119
|
+
private path;
|
|
1120
|
+
constructor(parent: NestedPathBuilder<T>, path: TPath);
|
|
1121
|
+
/**
|
|
1122
|
+
* Add a field to the current nested path
|
|
1123
|
+
*/
|
|
1124
|
+
field<FName extends string>(fieldName: FName, label: string, type?: string, props?: any): NestedObjectBuilder<T, TPath>;
|
|
1125
|
+
/**
|
|
1126
|
+
* Nest deeper into the object
|
|
1127
|
+
*/
|
|
1128
|
+
nest<SubPath extends string>(subPath: SubPath): NestedObjectBuilder<T, TPath>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Return to the parent builder
|
|
1131
|
+
*/
|
|
1132
|
+
end(): NestedPathBuilder<T>;
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Section builder for grouping related fields
|
|
1136
|
+
*/
|
|
1137
|
+
declare class SectionBuilder<T extends FieldValues, TPath extends Path<T>> {
|
|
1138
|
+
private parent;
|
|
1139
|
+
private path;
|
|
1140
|
+
constructor(parent: NestedPathBuilder<T>, path: TPath);
|
|
1141
|
+
/**
|
|
1142
|
+
* Add a field to the current section
|
|
1143
|
+
*/
|
|
1144
|
+
field<FName extends string>(fieldName: FName, label: string, type?: string, props?: any): SectionBuilder<T, TPath>;
|
|
1145
|
+
/**
|
|
1146
|
+
* Add multiple fields to the section
|
|
1147
|
+
*/
|
|
1148
|
+
fields(fieldDefinitions: {
|
|
1149
|
+
name: string;
|
|
1150
|
+
label: string;
|
|
1151
|
+
type?: string;
|
|
1152
|
+
props?: any;
|
|
1153
|
+
}[]): SectionBuilder<T, TPath>;
|
|
1154
|
+
/**
|
|
1155
|
+
* Nest deeper into the section
|
|
1156
|
+
*/
|
|
1157
|
+
nest<SubPath extends string>(subPath: SubPath): NestedObjectBuilder<T, TPath>;
|
|
1158
|
+
/**
|
|
1159
|
+
* Return to the parent builder
|
|
1160
|
+
*/
|
|
1161
|
+
end(): NestedPathBuilder<T>;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Template literal field builder
|
|
1165
|
+
*/
|
|
1166
|
+
declare class FieldTemplateBuilder<T extends FieldValues> {
|
|
1167
|
+
private parent;
|
|
1168
|
+
private path;
|
|
1169
|
+
constructor(parent: NestedPathBuilder<T>, path: string);
|
|
1170
|
+
/**
|
|
1171
|
+
* Complete the field definition
|
|
1172
|
+
*/
|
|
1173
|
+
complete(label: string, type?: string, props?: any): NestedPathBuilder<T>;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Factory function for creating the nested path builder
|
|
1177
|
+
*/
|
|
1178
|
+
declare function createNestedPathBuilder<T extends FieldValues>(): NestedPathBuilder<T>;
|
|
1179
|
+
|
|
1180
|
+
interface UseDebouncedValidationOptions {
|
|
1181
|
+
delay?: number;
|
|
1182
|
+
fields?: string[];
|
|
1183
|
+
enabled?: boolean;
|
|
1184
|
+
}
|
|
1185
|
+
declare function useDebouncedValidation<T extends Record<string, any>>(form: UseFormReturn<T>, options?: UseDebouncedValidationOptions): {
|
|
1186
|
+
debouncedTrigger: () => void;
|
|
1187
|
+
isDebouncing: boolean;
|
|
1188
|
+
};
|
|
1189
|
+
declare function useDebouncedFieldValidation<T extends Record<string, any>>(form: UseFormReturn<T>, fieldName: keyof T, options?: {
|
|
1190
|
+
delay?: number;
|
|
1191
|
+
enabled?: boolean;
|
|
1192
|
+
}): {
|
|
1193
|
+
debouncedFieldTrigger: () => void;
|
|
1194
|
+
isDebouncing: boolean;
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
interface UseInferredFormOptions<T extends FieldValues> {
|
|
1198
|
+
defaultValues?: Partial<T>;
|
|
1199
|
+
mode?: "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
|
|
1200
|
+
reValidateMode?: "onChange" | "onBlur" | "onSubmit";
|
|
1201
|
+
shouldFocusError?: boolean;
|
|
1202
|
+
shouldUnregister?: boolean;
|
|
1203
|
+
delayError?: number;
|
|
1204
|
+
}
|
|
1205
|
+
declare function useInferredForm<T extends FieldValues>(schema: any, fields: ZodFormFieldConfig<T>[], options?: UseInferredFormOptions<T>): UseFormReturn<T>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Hook that works with type-inferred forms
|
|
1208
|
+
*/
|
|
1209
|
+
declare function useTypeInferredForm<T extends FieldValues>(formConfig: {
|
|
1210
|
+
schema: any;
|
|
1211
|
+
fields: ZodFormFieldConfig<T>[];
|
|
1212
|
+
}, options?: UseInferredFormOptions<T>): UseFormReturn<T>;
|
|
1213
|
+
|
|
1214
|
+
interface ConditionalFieldProps<TFieldValues extends FieldValues> {
|
|
1215
|
+
config: ConditionalFieldConfig<TFieldValues>;
|
|
1216
|
+
control: Control<TFieldValues>;
|
|
1217
|
+
className?: string;
|
|
1218
|
+
}
|
|
1219
|
+
declare function ConditionalField<TFieldValues extends FieldValues>({ className, config, control, }: ConditionalFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
1220
|
+
|
|
1221
|
+
interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
|
|
1222
|
+
config: FieldArrayConfig<TFieldValues>;
|
|
1223
|
+
className?: string;
|
|
1224
|
+
}
|
|
1225
|
+
declare function FieldArrayField<TFieldValues extends FieldValues>({ className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
1226
|
+
|
|
1227
|
+
interface DynamicSectionFieldProps<TFieldValues extends FieldValues> {
|
|
1228
|
+
config: DynamicSectionConfig<TFieldValues>;
|
|
1229
|
+
control: Control<TFieldValues>;
|
|
1230
|
+
className?: string;
|
|
1231
|
+
}
|
|
1232
|
+
declare function DynamicSectionField<TFieldValues extends FieldValues>({ className, config, control, }: DynamicSectionFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
1233
|
+
|
|
1234
|
+
interface FormStatusProps<T extends Record<string, any>> {
|
|
1235
|
+
state: EnhancedFormState<T>;
|
|
1236
|
+
onDismiss?: () => void;
|
|
1237
|
+
className?: string;
|
|
1238
|
+
showDetails?: boolean;
|
|
1239
|
+
}
|
|
1240
|
+
declare function FormStatus<T extends Record<string, any>>({ className, onDismiss, showDetails, state, }: FormStatusProps<T>): React$1.JSX.Element | null;
|
|
1241
|
+
interface FormToastProps<T extends Record<string, any>> {
|
|
1242
|
+
state: EnhancedFormState<T>;
|
|
1243
|
+
onDismiss?: () => void;
|
|
1244
|
+
position?: "top-right" | "top-left" | "bottom-right" | "bottom-left";
|
|
1245
|
+
duration?: number;
|
|
1246
|
+
}
|
|
1247
|
+
declare function FormToast<T extends Record<string, any>>({ duration, onDismiss, position, state, }: FormToastProps<T>): React$1.JSX.Element | null;
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* Debounce function for field changes
|
|
1251
|
+
*/
|
|
1252
|
+
declare function debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void;
|
|
1253
|
+
/**
|
|
1254
|
+
* Throttle function for high-frequency events
|
|
1255
|
+
*/
|
|
1256
|
+
declare function throttle<T extends (...args: any[]) => any>(func: T, limit: number): (...args: Parameters<T>) => void;
|
|
1257
|
+
/**
|
|
1258
|
+
* Memoization helper for expensive computations
|
|
1259
|
+
*/
|
|
1260
|
+
declare function useMemoizedCallback<T extends (...args: any[]) => any>(callback: T, deps: React.DependencyList): T;
|
|
1261
|
+
/**
|
|
1262
|
+
* Shallow comparison for React.memo
|
|
1263
|
+
*/
|
|
1264
|
+
declare function shallowEqual<T extends Record<string, any>>(prevProps: T, nextProps: T): boolean;
|
|
1265
|
+
/**
|
|
1266
|
+
* Deep comparison for complex objects
|
|
1267
|
+
*/
|
|
1268
|
+
declare function deepEqual<T extends Record<string, any>>(prevProps: T, nextProps: T): boolean;
|
|
1269
|
+
/**
|
|
1270
|
+
* Performance monitoring utilities (dev mode only)
|
|
1271
|
+
*/
|
|
1272
|
+
declare function usePerformanceMonitor(componentName: string, enabled?: boolean): {
|
|
1273
|
+
renderCount: number;
|
|
1274
|
+
resetRenderCount: () => void;
|
|
1275
|
+
};
|
|
1276
|
+
/**
|
|
1277
|
+
* Optimized field change handler
|
|
1278
|
+
*/
|
|
1279
|
+
declare function createOptimizedFieldHandler<T>(onChange: (value: T) => void, options?: {
|
|
1280
|
+
debounce?: number;
|
|
1281
|
+
throttle?: number;
|
|
1282
|
+
}): (value: T) => void;
|
|
1283
|
+
/**
|
|
1284
|
+
* Memoized field props to prevent unnecessary re-renders
|
|
1285
|
+
*/
|
|
1286
|
+
declare function useMemoizedFieldProps<T extends Record<string, any>>(props: T, deps: React.DependencyList): T;
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Common validation patterns for forms
|
|
1290
|
+
*/
|
|
1291
|
+
declare const validationPatterns: {
|
|
1292
|
+
creditCard: z.ZodString;
|
|
1293
|
+
date: z.ZodString;
|
|
1294
|
+
email: z.ZodString;
|
|
1295
|
+
password: z.ZodString;
|
|
1296
|
+
phoneInternational: z.ZodString;
|
|
1297
|
+
phoneUS: z.ZodString;
|
|
1298
|
+
ssn: z.ZodString;
|
|
1299
|
+
strongPassword: z.ZodString;
|
|
1300
|
+
time: z.ZodString;
|
|
1301
|
+
url: z.ZodString;
|
|
1302
|
+
zipCode: z.ZodString;
|
|
1303
|
+
};
|
|
1304
|
+
/**
|
|
1305
|
+
* Async validation helpers
|
|
1306
|
+
*/
|
|
1307
|
+
declare const asyncValidation: {
|
|
1308
|
+
/**
|
|
1309
|
+
* Email availability check
|
|
1310
|
+
*/
|
|
1311
|
+
emailAvailability: (email: string) => Promise<boolean>;
|
|
1312
|
+
/**
|
|
1313
|
+
* Username availability check
|
|
1314
|
+
*/
|
|
1315
|
+
usernameAvailability: (username: string) => Promise<boolean>;
|
|
1316
|
+
};
|
|
1317
|
+
/**
|
|
1318
|
+
* Custom error messages
|
|
1319
|
+
*/
|
|
1320
|
+
declare const errorMessages: {
|
|
1321
|
+
date: () => string;
|
|
1322
|
+
email: () => string;
|
|
1323
|
+
max: (fieldName: string, max: number) => string;
|
|
1324
|
+
maxLength: (fieldName: string, max: number) => string;
|
|
1325
|
+
min: (fieldName: string, min: number) => string;
|
|
1326
|
+
minLength: (fieldName: string, min: number) => string;
|
|
1327
|
+
pattern: (fieldName: string) => string;
|
|
1328
|
+
phone: () => string;
|
|
1329
|
+
required: (fieldName: string) => string;
|
|
1330
|
+
time: () => string;
|
|
1331
|
+
url: () => string;
|
|
1332
|
+
};
|
|
1333
|
+
/**
|
|
1334
|
+
* Server-side validation integration
|
|
1335
|
+
*/
|
|
1336
|
+
declare const serverValidation: {
|
|
1337
|
+
/**
|
|
1338
|
+
* Apply server errors to form
|
|
1339
|
+
*/
|
|
1340
|
+
applyServerErrors: (errors: Record<string, string[]>, setError: any) => void;
|
|
1341
|
+
/**
|
|
1342
|
+
* Clear server errors
|
|
1343
|
+
*/
|
|
1344
|
+
clearServerErrors: (fields: string[], clearErrors: any) => void;
|
|
1345
|
+
};
|
|
1346
|
+
/**
|
|
1347
|
+
* Form validation utilities
|
|
1348
|
+
*/
|
|
1349
|
+
declare const validationUtils: {
|
|
1350
|
+
/**
|
|
1351
|
+
* Debounced validation
|
|
1352
|
+
*/
|
|
1353
|
+
debounceValidation: (fn: (...args: any[]) => void, delay?: number) => (...args: any[]) => void;
|
|
1354
|
+
/**
|
|
1355
|
+
* Get field error message
|
|
1356
|
+
*/
|
|
1357
|
+
getFieldError: (errors: Record<string, string>, field: string) => string | undefined;
|
|
1358
|
+
/**
|
|
1359
|
+
* Check if field has error
|
|
1360
|
+
*/
|
|
1361
|
+
hasFieldError: (errors: Record<string, string>, field: string) => boolean;
|
|
1362
|
+
/**
|
|
1363
|
+
* Validate form data against schema
|
|
1364
|
+
*/
|
|
1365
|
+
validateForm: (data: any, schema: z.ZodSchema) => Promise<{
|
|
1366
|
+
errors: Record<string, string>;
|
|
1367
|
+
success: boolean;
|
|
1368
|
+
}>;
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
export { AdvancedFieldBuilder, type BaseFormFieldConfig, BasicFormBuilder, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, CommonFields, ConditionalField, type ConditionalFieldConfig, type ConditionalFieldProps, type ConditionalValidation, ConfigurableForm, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type DynamicSectionConfig, DynamicSectionField, type DynamicSectionFieldProps, type EnhancedFormState, FieldArrayBuilder, type FieldArrayConfig, FieldArrayField, type FieldArrayFieldProps, FieldArrayItemBuilder, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, FormFieldHelpers, type FormProps, FormProvider, FormStatus, type FormStatusProps, type FormStep, type FormSubmissionState, type FormTestUtils, FormToast, type FormToastProps, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, ServerActionForm, type ServerFieldError, type ServerFormError, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, TypeInferredBuilder, type UseDebouncedValidationOptions, type UseEnhancedFormStateOptions, type UseInferredFormOptions, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, asyncValidation, commonValidations, createAdvancedBuilder, createBasicFormBuilder, createDateSchema, createEmailSchema, createField, createFieldArrayBuilder, createFieldArrayItemBuilder, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNestedPathBuilder, createNumberRangeSchema, createOptimizedFieldHandler, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createTypeInferredBuilder, createUrlSchema, createZodFormConfig, crossFieldValidation, debounce, deepEqual, defineInferredForm, errorMessages, field, getFieldError, getFormErrors, hasFieldError, hasFormErrors, serverValidation, shallowEqual, simulateFieldInput, simulateFormSubmission, throttle, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };
|