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