@rachelallyson/hero-hook-form 2.1.3 → 2.2.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 CHANGED
@@ -123,7 +123,19 @@ interface DynamicSectionConfig<TFieldValues extends FieldValues> extends BaseFor
123
123
  condition: (formData: Partial<TFieldValues>) => boolean;
124
124
  fields: ZodFormFieldConfig<TFieldValues>[];
125
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>;
126
+ interface ContentFieldConfig<TFieldValues extends FieldValues> {
127
+ type: "content";
128
+ name?: Path<TFieldValues>;
129
+ title?: string;
130
+ description?: string;
131
+ render?: (field: {
132
+ form: UseFormReturn<TFieldValues>;
133
+ errors: FieldErrors<TFieldValues>;
134
+ isSubmitting: boolean;
135
+ }) => React.ReactNode;
136
+ className?: string;
137
+ }
138
+ 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> | ContentFieldConfig<TFieldValues>;
127
139
  interface FormConfig<TFieldValues extends FieldValues> {
128
140
  fields: FormFieldConfig<TFieldValues>[];
129
141
  layout?: "vertical" | "horizontal" | "grid" | "custom";
@@ -137,7 +149,7 @@ interface FormConfig<TFieldValues extends FieldValues> {
137
149
  className?: string;
138
150
  defaultValues?: Partial<TFieldValues>;
139
151
  }
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">;
152
+ 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"> | ContentFieldConfig<TFieldValues>;
141
153
  interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
142
154
  schema: zod.ZodSchema<TFieldValues>;
143
155
  fields: ZodFormFieldConfig<TFieldValues>[];
@@ -216,6 +228,11 @@ interface FormTestUtils<TFieldValues extends FieldValues> {
216
228
  triggerValidation: (name?: Path<TFieldValues>) => Promise<boolean>;
217
229
  }
218
230
 
231
+ /**
232
+ * Props for the Form component.
233
+ *
234
+ * @template T - The form data type
235
+ */
219
236
  interface FormProps$1<T extends FieldValues> {
220
237
  className?: string;
221
238
  columns?: 1 | 2 | 3;
@@ -233,6 +250,57 @@ interface FormProps$1<T extends FieldValues> {
233
250
  title?: string;
234
251
  defaultValues?: Partial<T>;
235
252
  }
253
+ /**
254
+ * Base form component for building forms without Zod validation.
255
+ *
256
+ * @description
257
+ * This component provides a flexible form solution using React Hook Form
258
+ * without requiring Zod schemas. It's useful when you need more control over
259
+ * validation or want to use React Hook Form's built-in validation rules.
260
+ *
261
+ * @template T - The form data type
262
+ *
263
+ * @param {FormProps<T>} props - Component props
264
+ * @param {FormFieldConfig<T>[]} props.fields - Array of field configurations
265
+ * @param {SubmitHandler<T>} props.onSubmit - Submit handler function
266
+ * @param {Partial<T>} [props.defaultValues] - Default form values
267
+ * @param {string} [props.title] - Optional form title
268
+ * @param {string} [props.subtitle] - Optional form subtitle
269
+ * @param {"vertical"|"horizontal"|"grid"} [props.layout="vertical"] - Form layout
270
+ * @param {1|2|3} [props.columns=1] - Number of columns for grid layout
271
+ * @param {"2"|"4"|"6"|"8"|"lg"} [props.spacing="4"] - Spacing between fields
272
+ * @param {string} [props.submitButtonText="Submit"] - Submit button text
273
+ * @param {boolean} [props.showResetButton=false] - Whether to show reset button
274
+ * @param {(error: FormValidationError) => void} [props.onError] - Error callback
275
+ * @param {(data: T) => void} [props.onSuccess] - Success callback
276
+ *
277
+ * @returns {JSX.Element} The rendered form component
278
+ *
279
+ * @example
280
+ * ```tsx
281
+ * import { ConfigurableForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
282
+ *
283
+ * function MyForm() {
284
+ * return (
285
+ * <ConfigurableForm
286
+ * fields={[
287
+ * FormFieldHelpers.input("name", "Name"),
288
+ * FormFieldHelpers.input("email", "Email", "email"),
289
+ * ]}
290
+ * defaultValues={{ name: "", email: "" }}
291
+ * onSubmit={async (data) => {
292
+ * console.log("Submitted:", data);
293
+ * }}
294
+ * title="Contact Form"
295
+ * />
296
+ * );
297
+ * }
298
+ * ```
299
+ *
300
+ * @see {@link ZodForm} for Zod-integrated form with automatic validation
301
+ * @see {@link FormFieldHelpers} for field creation helpers
302
+ * @category Components
303
+ */
236
304
  declare function ConfigurableForm<T extends FieldValues>({ className, columns, defaultValues, fields, layout, onError, onSubmit, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: FormProps$1<T>): React$1.JSX.Element;
237
305
 
238
306
  interface FormFieldProps<TFieldValues extends FieldValues> {
@@ -277,11 +345,13 @@ interface ServerActionFormProps<T extends FieldValues> {
277
345
  title?: string;
278
346
  }
279
347
  /**
280
- * ServerActionForm - A form component compatible with Next.js Server Actions
348
+ * ServerActionForm - A form component compatible with Next.js Server Actions.
281
349
  *
350
+ * @description
282
351
  * This component works with Next.js authentication patterns by using native
283
352
  * HTML form submission with Server Actions, while still providing the
284
- * beautiful HeroUI field components.
353
+ * beautiful HeroUI field components. It uses React's useActionState hook
354
+ * to manage form state and handle server responses.
285
355
  *
286
356
  * **Validation Options:**
287
357
  * - **Server-side only (default)**: Form submits directly to Server Action
@@ -292,22 +362,77 @@ interface ServerActionFormProps<T extends FieldValues> {
292
362
  * - If your Server Action calls `redirect()`, success messages won't display
293
363
  * (the page navigates away). Use URL params or cookies for success messages
294
364
  * when redirecting.
365
+ * - Server Actions receive FormData, not JSON, so field values are strings
366
+ *
367
+ * @template T - The form data type
368
+ *
369
+ * @param {ServerActionFormProps<T>} props - Component props
370
+ * @param {ServerAction<ActionState, FormData>} props.action - Next.js Server Action function
371
+ * @param {FormFieldConfig<T>[]} props.fields - Array of field configurations
372
+ * @param {z.ZodSchema<T>} [props.clientValidationSchema] - Optional Zod schema for client-side validation
373
+ * @param {Partial<T>} [props.defaultValues] - Default form values
374
+ * @param {ActionState} [props.initialState] - Initial state for useActionState
375
+ * @param {string} [props.title] - Optional form title
376
+ * @param {string} [props.subtitle] - Optional form subtitle
377
+ * @param {"vertical"|"horizontal"|"grid"} [props.layout="vertical"] - Form layout style
378
+ * @param {1|2|3} [props.columns=1] - Number of columns for grid layout
379
+ * @param {"2"|"4"|"6"|"8"|"lg"} [props.spacing="4"] - Spacing between form fields
380
+ * @param {string} [props.submitButtonText="Submit"] - Text for the submit button
381
+ * @param {boolean} [props.showResetButton=false] - Whether to show a reset button
382
+ * @param {(error: {...}) => void} [props.onError] - Error callback
383
+ * @param {(data: FormData) => void} [props.onSuccess] - Success callback
384
+ *
385
+ * @returns {JSX.Element} The rendered form component
295
386
  *
296
387
  * @example
388
+ * Server-side only validation:
297
389
  * ```tsx
298
- * // Server-side only validation
390
+ * import { ServerActionForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
391
+ * import { signup } from "@/app/actions/auth";
392
+ *
299
393
  * <ServerActionForm
300
394
  * action={signup}
301
- * fields={[...]}
395
+ * fields={[
396
+ * FormFieldHelpers.input("name", "Name"),
397
+ * FormFieldHelpers.input("email", "Email", "email"),
398
+ * FormFieldHelpers.input("password", "Password", "password"),
399
+ * ]}
302
400
  * />
401
+ * ```
402
+ *
403
+ * @example
404
+ * Client + Server validation:
405
+ * ```tsx
406
+ * import { ServerActionForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
407
+ * import { signup } from "@/app/actions/auth";
408
+ * import { z } from "zod";
409
+ *
410
+ * const signupSchema = z.object({
411
+ * name: z.string().min(2),
412
+ * email: z.string().email(),
413
+ * password: z.string().min(8),
414
+ * });
303
415
  *
304
- * // Client + Server validation
305
416
  * <ServerActionForm
306
417
  * action={signup}
307
418
  * clientValidationSchema={signupSchema}
308
- * fields={[...]}
419
+ * fields={[
420
+ * FormFieldHelpers.input("name", "Name"),
421
+ * FormFieldHelpers.input("email", "Email", "email"),
422
+ * FormFieldHelpers.input("password", "Password", "password"),
423
+ * ]}
424
+ * onError={(error) => {
425
+ * console.error("Form errors:", error.errors);
426
+ * }}
427
+ * onSuccess={(data) => {
428
+ * console.log("Form submitted:", data);
429
+ * }}
309
430
  * />
310
431
  * ```
432
+ *
433
+ * @see {@link ZodForm} for client-side only forms with Zod validation
434
+ * @see {@link ConfigurableForm} for forms without Server Actions
435
+ * @category Components
311
436
  */
312
437
  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;
313
438
 
@@ -341,10 +466,63 @@ type FontPickerFieldProps<TFieldValues extends FieldValues, TValue extends strin
341
466
  };
342
467
  declare function FontPickerField<TFieldValues extends FieldValues, TValue extends string = string>(props: FontPickerFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
343
468
 
469
+ /**
470
+ * Props for the InputField component.
471
+ *
472
+ * @template TFieldValues - The form data type
473
+ */
344
474
  type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
345
475
  inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
346
476
  transform?: (value: string) => string;
347
477
  };
478
+ /**
479
+ * Input field component for text, email, password, tel, and number inputs.
480
+ *
481
+ * @description
482
+ * A memoized input field component that integrates with React Hook Form
483
+ * and HeroUI Input component. Supports all standard input types and
484
+ * includes automatic validation error display.
485
+ *
486
+ * @template TFieldValues - The form data type
487
+ *
488
+ * @param {InputFieldProps<TFieldValues>} props - Component props
489
+ * @param {Path<TFieldValues>} props.name - Field name path
490
+ * @param {string} [props.label] - Field label
491
+ * @param {string} [props.description] - Field description/help text
492
+ * @param {Control<TFieldValues>} props.control - React Hook Form control
493
+ * @param {boolean} [props.isDisabled] - Whether field is disabled
494
+ * @param {RegisterOptions<TFieldValues>} [props.rules] - Validation rules
495
+ * @param {Partial<InputProps>} [props.inputProps] - Additional Input component props
496
+ * @param {(value: string) => string} [props.transform] - Value transformation function
497
+ *
498
+ * @returns {JSX.Element} The rendered input field
499
+ *
500
+ * @example
501
+ * ```tsx
502
+ * import { InputField } from "@rachelallyson/hero-hook-form";
503
+ * import { useForm, Controller } from "react-hook-form";
504
+ *
505
+ * function MyForm() {
506
+ * const { control } = useForm();
507
+ *
508
+ * return (
509
+ * <InputField
510
+ * name="email"
511
+ * label="Email Address"
512
+ * description="Enter your email address"
513
+ * control={control}
514
+ * inputProps={{
515
+ * type: "email",
516
+ * placeholder: "you@example.com",
517
+ * }}
518
+ * />
519
+ * );
520
+ * }
521
+ * ```
522
+ *
523
+ * @see {@link FormFieldHelpers.input} for helper function to create input field config
524
+ * @category Fields
525
+ */
348
526
  declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
349
527
 
350
528
  interface RadioOption<TValue extends string | number> {
@@ -388,6 +566,11 @@ type TextareaFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFiel
388
566
  };
389
567
  declare function TextareaField<TFieldValues extends FieldValues>(props: TextareaFieldProps<TFieldValues>): React$1.JSX.Element;
390
568
 
569
+ /**
570
+ * Options for the useFormHelper hook.
571
+ *
572
+ * @template T - The form data type
573
+ */
391
574
  interface UseFormHelperOptions<T extends FieldValues> {
392
575
  onError?: (error: FormValidationError) => void;
393
576
  onSubmit: SubmitHandler<T>;
@@ -395,6 +578,86 @@ interface UseFormHelperOptions<T extends FieldValues> {
395
578
  defaultValues?: Partial<T>;
396
579
  methods?: UseFormReturn<T>;
397
580
  }
581
+ /**
582
+ * Hook for managing form state with enhanced features.
583
+ *
584
+ * @description
585
+ * Provides form state management with loading states, error handling,
586
+ * and submission tracking. Automatically handles form validation and
587
+ * provides callbacks for success and error cases. This hook wraps
588
+ * React Hook Form's useForm with additional state management.
589
+ *
590
+ * @template T - The form data type
591
+ *
592
+ * @param {UseFormHelperOptions<T>} options - Hook options
593
+ * @param {Partial<T>} [options.defaultValues] - Default form values
594
+ * @param {UseFormReturn<T>} [options.methods] - Optional existing form instance
595
+ * @param {SubmitHandler<T>} options.onSubmit - Submit handler function
596
+ * @param {(error: FormValidationError) => void} [options.onError] - Error handler callback
597
+ * @param {(data: T) => void} [options.onSuccess] - Success handler callback
598
+ *
599
+ * @returns {Object} Form helper with state and methods
600
+ * @returns {UseFormReturn<T>} form - React Hook Form instance
601
+ * @returns {() => Promise<void>} handleSubmit - Submit handler function
602
+ * @returns {() => void} resetForm - Reset form function
603
+ * @returns {boolean} isSubmitting - Whether form is currently submitting
604
+ * @returns {boolean} isSubmitted - Whether form has been submitted
605
+ * @returns {boolean} isSuccess - Whether last submission was successful
606
+ * @returns {string|undefined} error - Error message if submission failed
607
+ * @returns {FormSubmissionState} submissionState - Complete submission state object
608
+ *
609
+ * @example
610
+ * ```tsx
611
+ * import { useFormHelper } from "@rachelallyson/hero-hook-form";
612
+ *
613
+ * function MyForm() {
614
+ * const { form, handleSubmit, isSubmitting, error } = useFormHelper({
615
+ * defaultValues: { email: "", name: "" },
616
+ * onSubmit: async (data) => {
617
+ * await submitToServer(data);
618
+ * },
619
+ * onError: (error) => {
620
+ * console.error("Validation errors:", error);
621
+ * },
622
+ * onSuccess: (data) => {
623
+ * console.log("Success:", data);
624
+ * },
625
+ * });
626
+ *
627
+ * return (
628
+ * <form onSubmit={(e) => { e.preventDefault(); handleSubmit(); }}>
629
+ * <button disabled={isSubmitting}>
630
+ * {isSubmitting ? "Submitting..." : "Submit"}
631
+ * </button>
632
+ * {error && <div className="error">{error}</div>}
633
+ * </form>
634
+ * );
635
+ * }
636
+ * ```
637
+ *
638
+ * @example
639
+ * Using with existing form instance:
640
+ * ```tsx
641
+ * import { useForm } from "react-hook-form";
642
+ * import { useFormHelper } from "@rachelallyson/hero-hook-form";
643
+ *
644
+ * function MyForm() {
645
+ * const existingForm = useForm({ defaultValues: { email: "" } });
646
+ * const { handleSubmit, isSubmitting } = useFormHelper({
647
+ * methods: existingForm,
648
+ * onSubmit: async (data) => {
649
+ * await submitToServer(data);
650
+ * },
651
+ * });
652
+ *
653
+ * // Use existingForm and handleSubmit together
654
+ * }
655
+ * ```
656
+ *
657
+ * @see {@link useHeroForm} for alternative hook with different API
658
+ * @see {@link ConfigurableForm} for component that uses this hook
659
+ * @category Hooks
660
+ */
398
661
  declare function useFormHelper<T extends FieldValues>({ defaultValues, methods, onError, onSubmit, onSuccess, }: UseFormHelperOptions<T>): {
399
662
  error: string | undefined;
400
663
  form: UseFormReturn<T>;
@@ -407,11 +670,19 @@ declare function useFormHelper<T extends FieldValues>({ defaultValues, methods,
407
670
  };
408
671
 
409
672
  /**
410
- * Enhanced hook that provides both form methods and styling defaults
673
+ * Enhanced hook that provides both form methods and styling defaults.
411
674
  *
675
+ * @description
412
676
  * This hook combines React Hook Form's useFormContext with Hero Hook Form's
413
677
  * styling defaults, giving you access to both form functionality and
414
- * component styling in one convenient hook.
678
+ * component styling in one convenient hook. Must be used within a FormProvider
679
+ * context (provided by ZodForm, ConfigurableForm, or manual FormProvider).
680
+ *
681
+ * @template TFieldValues - The form data type
682
+ *
683
+ * @returns {Object} Enhanced form object with all React Hook Form methods and Hero Hook Form defaults
684
+ * @returns {UseFormReturn<TFieldValues>} All React Hook Form methods (formState, getValues, setValue, etc.)
685
+ * @returns {HeroHookFormDefaultsConfig} defaults - Hero Hook Form styling defaults
415
686
  *
416
687
  * @example
417
688
  * ```tsx
@@ -433,6 +704,10 @@ declare function useFormHelper<T extends FieldValues>({ defaultValues, methods,
433
704
  * const buttonDefaults = defaults.submitButton;
434
705
  * }
435
706
  * ```
707
+ *
708
+ * @see {@link useFormHelper} for form state management with callbacks
709
+ * @see {@link useFormContext} from React Hook Form for base functionality
710
+ * @category Hooks
436
711
  */
437
712
  declare function useHeroForm<TFieldValues extends FieldValues>(): {
438
713
  defaults: Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "select" | "switch" | "radioGroup" | "checkbox" | "slider" | "dateInput" | "submitButton">>;
@@ -507,6 +782,11 @@ interface FormProps<TFieldValues extends FieldValues> {
507
782
  }
508
783
  declare function FormProvider<TFieldValues extends FieldValues>(props: FormProps<TFieldValues>): React$1.JSX.Element;
509
784
 
785
+ /**
786
+ * Enhanced form state with submission tracking and error management.
787
+ *
788
+ * @template T - The form data type
789
+ */
510
790
  interface EnhancedFormState<T extends FieldValues> {
511
791
  status: "idle" | "submitting" | "success" | "error";
512
792
  isSubmitting: boolean;
@@ -522,6 +802,11 @@ interface EnhancedFormState<T extends FieldValues> {
522
802
  handleError: (error: string) => void;
523
803
  reset: () => void;
524
804
  }
805
+ /**
806
+ * Options for the useEnhancedFormState hook.
807
+ *
808
+ * @template T - The form data type
809
+ */
525
810
  interface UseEnhancedFormStateOptions<T extends FieldValues> {
526
811
  onSuccess?: (data: T) => void;
527
812
  onError?: (error: string) => void;
@@ -530,6 +815,81 @@ interface UseEnhancedFormStateOptions<T extends FieldValues> {
530
815
  autoReset?: boolean;
531
816
  resetDelay?: number;
532
817
  }
818
+ /**
819
+ * Hook for managing enhanced form state with submission tracking.
820
+ *
821
+ * @description
822
+ * Provides advanced form state management including submission status,
823
+ * error tracking, touched/dirty field tracking, and automatic reset
824
+ * functionality. Useful for building forms with rich UI feedback.
825
+ *
826
+ * @template T - The form data type
827
+ *
828
+ * @param {UseFormReturn<T>} form - React Hook Form instance
829
+ * @param {UseEnhancedFormStateOptions<T>} [options] - Configuration options
830
+ * @param {(data: T) => void} [options.onSuccess] - Success callback
831
+ * @param {(error: string) => void} [options.onError] - Error callback
832
+ * @param {string} [options.successMessage] - Custom success message
833
+ * @param {string} [options.errorMessage] - Custom error message
834
+ * @param {boolean} [options.autoReset=true] - Automatically reset after success
835
+ * @param {number} [options.resetDelay=3000] - Delay before auto-reset (ms)
836
+ *
837
+ * @returns {EnhancedFormState<T>} Enhanced form state object
838
+ * @returns {"idle"|"submitting"|"success"|"error"} status - Current submission status
839
+ * @returns {boolean} isSubmitting - Whether form is currently submitting
840
+ * @returns {boolean} isSuccess - Whether last submission was successful
841
+ * @returns {boolean} isError - Whether last submission had an error
842
+ * @returns {string|undefined} error - Error message if submission failed
843
+ * @returns {T|undefined} submittedData - Data from last successful submission
844
+ * @returns {Set<Path<T>>} touchedFields - Set of touched field paths
845
+ * @returns {Set<Path<T>>} dirtyFields - Set of dirty field paths
846
+ * @returns {boolean} hasErrors - Whether form has validation errors
847
+ * @returns {number} errorCount - Number of validation errors
848
+ * @returns {(data: T) => void} handleSuccess - Function to mark submission as successful
849
+ * @returns {(error: string) => void} handleError - Function to mark submission as failed
850
+ * @returns {() => void} reset - Function to reset state to idle
851
+ *
852
+ * @example
853
+ * ```tsx
854
+ * import { useEnhancedFormState } from "@rachelallyson/hero-hook-form";
855
+ * import { useForm } from "react-hook-form";
856
+ *
857
+ * function MyForm() {
858
+ * const form = useForm();
859
+ * const state = useEnhancedFormState(form, {
860
+ * onSuccess: (data) => {
861
+ * console.log("Success:", data);
862
+ * },
863
+ * onError: (error) => {
864
+ * console.error("Error:", error);
865
+ * },
866
+ * autoReset: true,
867
+ * resetDelay: 3000,
868
+ * });
869
+ *
870
+ * const handleSubmit = async (data) => {
871
+ * try {
872
+ * await submitToServer(data);
873
+ * state.handleSuccess(data);
874
+ * } catch (error) {
875
+ * state.handleError(error.message);
876
+ * }
877
+ * };
878
+ *
879
+ * return (
880
+ * <form onSubmit={form.handleSubmit(handleSubmit)}>
881
+ * {/* form fields *\/}
882
+ * {state.isSubmitting && <div>Submitting...</div>}
883
+ * {state.isSuccess && <div>Success!</div>}
884
+ * {state.error && <div>Error: {state.error}</div>}
885
+ * </form>
886
+ * );
887
+ * }
888
+ * ```
889
+ *
890
+ * @see {@link ZodForm} which uses this hook internally
891
+ * @category Hooks
892
+ */
533
893
  declare function useEnhancedFormState<T extends FieldValues>(form: UseFormReturn<T>, options?: UseEnhancedFormStateOptions<T>): EnhancedFormState<T>;
534
894
 
535
895
  interface SubmitButtonProps {
@@ -543,15 +903,99 @@ interface SubmitButtonProps {
543
903
  }
544
904
  declare function SubmitButton(props: SubmitButtonProps): React$1.JSX.Element;
545
905
 
906
+ /**
907
+ * Server field error structure.
908
+ *
909
+ * @template TFieldValues - The form data type
910
+ */
546
911
  interface ServerFieldError<TFieldValues extends FieldValues> {
547
912
  path: Path<TFieldValues>;
548
913
  message: string;
549
914
  type?: string;
550
915
  }
916
+ /**
917
+ * Server form error structure containing field errors.
918
+ *
919
+ * @template TFieldValues - The form data type
920
+ */
551
921
  interface ServerFormError<TFieldValues extends FieldValues> {
552
922
  message?: string;
553
923
  fieldErrors?: readonly ServerFieldError<TFieldValues>[];
554
924
  }
925
+ /**
926
+ * Applies server-side validation errors to a React Hook Form instance.
927
+ *
928
+ * @description
929
+ * Maps server-returned field errors to React Hook Form's error state.
930
+ * Useful for displaying validation errors from API responses. This function
931
+ * iterates through the field errors and sets them on the form using
932
+ * React Hook Form's setError function.
933
+ *
934
+ * @template TFieldValues - The form data type
935
+ *
936
+ * @param {UseFormSetError<TFieldValues>} setError - React Hook Form's setError function
937
+ * @param {ServerFormError<TFieldValues>} serverError - Server error containing field errors
938
+ *
939
+ * @example
940
+ * ```tsx
941
+ * import { applyServerErrors } from "@rachelallyson/hero-hook-form";
942
+ * import { useForm } from "react-hook-form";
943
+ *
944
+ * function MyForm() {
945
+ * const form = useForm();
946
+ *
947
+ * const handleSubmit = async (data) => {
948
+ * try {
949
+ * const response = await fetch("/api/submit", {
950
+ * method: "POST",
951
+ * body: JSON.stringify(data),
952
+ * });
953
+ *
954
+ * if (!response.ok) {
955
+ * const errorData = await response.json();
956
+ * applyServerErrors(form.setError, errorData);
957
+ * }
958
+ * } catch (error) {
959
+ * console.error("Error:", error);
960
+ * }
961
+ * };
962
+ *
963
+ * return (
964
+ * <form onSubmit={form.handleSubmit(handleSubmit)}>
965
+ * {/* form fields go here *\/}
966
+ * </form>
967
+ * );
968
+ * }
969
+ * ```
970
+ *
971
+ * @example
972
+ * With ZodForm error handling:
973
+ * ```tsx
974
+ * import { ZodForm, applyServerErrors } from "@rachelallyson/hero-hook-form";
975
+ *
976
+ * function MyForm() {
977
+ * const form = useForm();
978
+ *
979
+ * const handleSubmit = async (data) => {
980
+ * try {
981
+ * await submitToServer(data);
982
+ * } catch (error) {
983
+ * if (error.fieldErrors) {
984
+ * applyServerErrors(form.setError, {
985
+ * fieldErrors: error.fieldErrors,
986
+ * });
987
+ * }
988
+ * }
989
+ * };
990
+ *
991
+ * return <ZodForm config={{ schema, fields }} onSubmit={handleSubmit} />;
992
+ * }
993
+ * ```
994
+ *
995
+ * @see {@link ServerFormError} for error structure
996
+ * @see {@link ServerFieldError} for field error structure
997
+ * @category Utilities
998
+ */
555
999
  declare function applyServerErrors<TFieldValues extends FieldValues>(setError: UseFormSetError<TFieldValues>, serverError: ServerFormError<TFieldValues>): void;
556
1000
 
557
1001
  /**
@@ -700,6 +1144,11 @@ declare const commonValidations: {
700
1144
  url: z.ZodString;
701
1145
  };
702
1146
 
1147
+ /**
1148
+ * Props for the ZodForm component.
1149
+ *
1150
+ * @template T - The form data type inferred from the Zod schema
1151
+ */
703
1152
  interface ZodFormProps<T extends FieldValues> {
704
1153
  className?: string;
705
1154
  columns?: 1 | 2 | 3;
@@ -724,6 +1173,101 @@ interface ZodFormProps<T extends FieldValues> {
724
1173
  values: T;
725
1174
  }) => React$1.ReactNode;
726
1175
  }
1176
+ /**
1177
+ * ZodForm component for building type-safe forms with Zod validation.
1178
+ *
1179
+ * @description
1180
+ * This component provides a complete form solution with automatic validation,
1181
+ * error handling, and type safety. It integrates React Hook Form with Zod
1182
+ * schemas and HeroUI components. The form automatically validates inputs based
1183
+ * on the provided Zod schema and displays error messages inline.
1184
+ *
1185
+ * @template T - The form data type inferred from the Zod schema
1186
+ *
1187
+ * @param {ZodFormProps<T>} props - Component props
1188
+ * @param {ZodFormConfig<T>} props.config - Form configuration with schema and fields
1189
+ * @param {SubmitHandler<T>} props.onSubmit - Submit handler function called with validated data
1190
+ * @param {string} [props.title] - Optional form title displayed above the form
1191
+ * @param {string} [props.subtitle] - Optional form subtitle displayed below the title
1192
+ * @param {"vertical"|"horizontal"|"grid"} [props.layout="vertical"] - Form layout style
1193
+ * @param {1|2|3} [props.columns=1] - Number of columns for grid layout (only applies when layout="grid")
1194
+ * @param {"2"|"4"|"6"|"8"|"lg"} [props.spacing="4"] - Spacing between form fields
1195
+ * @param {string} [props.submitButtonText="Submit"] - Text for the submit button
1196
+ * @param {boolean} [props.showResetButton=false] - Whether to show a reset button
1197
+ * @param {string} [props.resetButtonText="Reset"] - Text for the reset button
1198
+ * @param {(error: FormValidationError) => void} [props.onError] - Error callback for validation errors
1199
+ * @param {(data: T) => void} [props.onSuccess] - Success callback called after successful submission
1200
+ * @param {(formState: {...}) => React.ReactNode} [props.render] - Custom render function for advanced use cases
1201
+ *
1202
+ * @returns {JSX.Element} The rendered form component with validation and error handling
1203
+ *
1204
+ * @example
1205
+ * ```tsx
1206
+ * import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
1207
+ * import { z } from "zod";
1208
+ *
1209
+ * const schema = z.object({
1210
+ * email: z.string().email("Please enter a valid email"),
1211
+ * name: z.string().min(2, "Name must be at least 2 characters"),
1212
+ * message: z.string().min(10, "Message must be at least 10 characters"),
1213
+ * });
1214
+ *
1215
+ * function ContactForm() {
1216
+ * const handleSubmit = async (data) => {
1217
+ * console.log("Form submitted:", data);
1218
+ * // Handle form submission (e.g., API call)
1219
+ * };
1220
+ *
1221
+ * return (
1222
+ * <ZodForm
1223
+ * config={{
1224
+ * schema,
1225
+ * fields: [
1226
+ * FormFieldHelpers.input("name", "Name"),
1227
+ * FormFieldHelpers.input("email", "Email", "email"),
1228
+ * FormFieldHelpers.textarea("message", "Message"),
1229
+ * ],
1230
+ * }}
1231
+ * onSubmit={handleSubmit}
1232
+ * title="Contact Us"
1233
+ * subtitle="Send us a message and we'll get back to you"
1234
+ * />
1235
+ * );
1236
+ * }
1237
+ * ```
1238
+ *
1239
+ * @example
1240
+ * Grid layout with multiple columns:
1241
+ * ```tsx
1242
+ * <ZodForm
1243
+ * config={{ schema, fields }}
1244
+ * layout="grid"
1245
+ * columns={2}
1246
+ * spacing="6"
1247
+ * />
1248
+ * ```
1249
+ *
1250
+ * @example
1251
+ * Custom render function for advanced control:
1252
+ * ```tsx
1253
+ * <ZodForm
1254
+ * config={{ schema, fields }}
1255
+ * onSubmit={handleSubmit}
1256
+ * render={({ form, isSubmitting, errors, values }) => (
1257
+ * <div>
1258
+ * <button disabled={isSubmitting}>
1259
+ * {isSubmitting ? "Submitting..." : "Submit"}
1260
+ * </button>
1261
+ * </div>
1262
+ * )}
1263
+ * />
1264
+ * ```
1265
+ *
1266
+ * @see {@link Form} for the base form component without Zod
1267
+ * @see {@link FormFieldHelpers} for field creation helpers
1268
+ * @see {@link createBasicFormBuilder} for builder pattern alternative
1269
+ * @category Components
1270
+ */
727
1271
  declare function ZodForm<T extends FieldValues>({ className, columns, config, layout, onError, onSubmit, onSuccess, render, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ZodFormProps<T>): React$1.JSX.Element;
728
1272
 
729
1273
  /**
@@ -736,8 +1280,34 @@ declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormCon
736
1280
  declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: Partial<TFieldValues>): ZodFormConfig<TFieldValues>;
737
1281
 
738
1282
  /**
739
- * Basic form field builder that eliminates "as const" assertions
740
- * Focuses on the most common use cases
1283
+ * Basic form field builder for creating form field configurations.
1284
+ *
1285
+ * @description
1286
+ * Provides a fluent API for building form field configurations. This builder
1287
+ * focuses on the most common use cases and eliminates the need for "as const"
1288
+ * assertions. Use this for simple forms with standard field types.
1289
+ *
1290
+ * @template T - The form data type
1291
+ *
1292
+ * @example
1293
+ * ```tsx
1294
+ * import { createBasicFormBuilder } from "@rachelallyson/hero-hook-form";
1295
+ *
1296
+ * const fields = createBasicFormBuilder()
1297
+ * .input("name", "Name")
1298
+ * .input("email", "Email", "email")
1299
+ * .textarea("message", "Message")
1300
+ * .select("country", "Country", [
1301
+ * { label: "US", value: "us" },
1302
+ * { label: "CA", value: "ca" },
1303
+ * ])
1304
+ * .checkbox("newsletter", "Subscribe to newsletter")
1305
+ * .build();
1306
+ * ```
1307
+ *
1308
+ * @see {@link createAdvancedBuilder} for more advanced features
1309
+ * @see {@link FormFieldHelpers} for helper function alternative
1310
+ * @category Builders
741
1311
  */
742
1312
  declare class BasicFormBuilder<T extends FieldValues> {
743
1313
  private fields;
@@ -760,6 +1330,18 @@ declare class BasicFormBuilder<T extends FieldValues> {
760
1330
  * Add a checkbox field
761
1331
  */
762
1332
  checkbox(name: Path<T>, label: string): this;
1333
+ /**
1334
+ * Add a content field for headers, questions, or custom content between fields
1335
+ */
1336
+ content(title?: string | null, description?: string | null, options?: {
1337
+ render?: (field: {
1338
+ form: any;
1339
+ errors: any;
1340
+ isSubmitting: boolean;
1341
+ }) => React$1.ReactNode;
1342
+ className?: string;
1343
+ name?: Path<T>;
1344
+ }): this;
763
1345
  /**
764
1346
  * Add a switch field
765
1347
  */
@@ -770,17 +1352,97 @@ declare class BasicFormBuilder<T extends FieldValues> {
770
1352
  build(): ZodFormFieldConfig<T>[];
771
1353
  }
772
1354
  /**
773
- * Create a new simple form field builder
1355
+ * Creates a basic form builder for simple form construction.
1356
+ *
1357
+ * @description
1358
+ * Provides a fluent API for building form field configurations. Best for
1359
+ * simple forms with standard field types. Returns a builder instance with
1360
+ * chainable methods for adding fields.
1361
+ *
1362
+ * @template T - The form data type
1363
+ *
1364
+ * @returns {BasicFormBuilder<T>} Builder instance with chainable methods
1365
+ *
1366
+ * @example
1367
+ * ```tsx
1368
+ * import { createBasicFormBuilder } from "@rachelallyson/hero-hook-form";
1369
+ *
1370
+ * const fields = createBasicFormBuilder()
1371
+ * .input("name", "Name")
1372
+ * .input("email", "Email", "email")
1373
+ * .textarea("message", "Message")
1374
+ * .select("country", "Country", [
1375
+ * { label: "US", value: "us" },
1376
+ * { label: "CA", value: "ca" },
1377
+ * ])
1378
+ * .checkbox("newsletter", "Subscribe to newsletter")
1379
+ * .build();
1380
+ *
1381
+ * // Use with ZodForm
1382
+ * <ZodForm config={{ schema, fields }} onSubmit={handleSubmit} />
1383
+ * ```
1384
+ *
1385
+ * @see {@link createAdvancedBuilder} for more advanced features
1386
+ * @see {@link FormFieldHelpers} for helper function alternative
1387
+ * @see {@link defineInferredForm} for type-inferred forms
1388
+ * @category Builders
774
1389
  */
775
1390
  declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuilder<T>;
776
1391
  /**
777
- * Simple helper functions for common field types
1392
+ * Helper functions for creating form field configurations.
1393
+ *
1394
+ * @description
1395
+ * Simple helper functions for common field types. This is the recommended
1396
+ * approach for most use cases as it's straightforward and doesn't require
1397
+ * method chaining. Each helper returns a field configuration object.
1398
+ *
1399
+ * @example
1400
+ * ```tsx
1401
+ * import { FormFieldHelpers } from "@rachelallyson/hero-hook-form";
1402
+ *
1403
+ * const fields = [
1404
+ * FormFieldHelpers.input("name", "Name"),
1405
+ * FormFieldHelpers.input("email", "Email", "email"),
1406
+ * FormFieldHelpers.textarea("message", "Message"),
1407
+ * FormFieldHelpers.select("country", "Country", [
1408
+ * { label: "US", value: "us" },
1409
+ * { label: "CA", value: "ca" },
1410
+ * ]),
1411
+ * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter"),
1412
+ * ];
1413
+ * ```
1414
+ *
1415
+ * @see {@link createBasicFormBuilder} for builder pattern alternative
1416
+ * @category Builders
778
1417
  */
779
1418
  declare const FormFieldHelpers: {
780
1419
  /**
781
1420
  * Create a checkbox field
782
1421
  */
783
1422
  checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
1423
+ /**
1424
+ * Create a content field for headers, questions, or custom content between fields
1425
+ *
1426
+ * @example
1427
+ * ```tsx
1428
+ * // Simple header
1429
+ * FormFieldHelpers.content("Personal Information", "Please provide your details")
1430
+ *
1431
+ * // Custom render
1432
+ * FormFieldHelpers.content(null, null, {
1433
+ * render: () => <div>Custom content</div>
1434
+ * })
1435
+ * ```
1436
+ */
1437
+ content: <T extends FieldValues>(title?: string | null, description?: string | null, options?: {
1438
+ render?: (field: {
1439
+ form: any;
1440
+ errors: any;
1441
+ isSubmitting: boolean;
1442
+ }) => React$1.ReactNode;
1443
+ className?: string;
1444
+ name?: Path<T>;
1445
+ }) => ContentFieldConfig<T>;
784
1446
  /**
785
1447
  * Create a date field
786
1448
  */
@@ -1189,15 +1851,115 @@ declare class FieldTemplateBuilder<T extends FieldValues> {
1189
1851
  */
1190
1852
  declare function createNestedPathBuilder<T extends FieldValues>(): NestedPathBuilder<T>;
1191
1853
 
1854
+ /**
1855
+ * Options for the useDebouncedValidation hook.
1856
+ */
1192
1857
  interface UseDebouncedValidationOptions {
1193
1858
  delay?: number;
1194
1859
  fields?: string[];
1195
1860
  enabled?: boolean;
1196
1861
  }
1862
+ /**
1863
+ * Hook for debouncing form validation to improve performance.
1864
+ *
1865
+ * @description
1866
+ * Delays validation until the user stops typing, reducing unnecessary
1867
+ * validation calls and improving form performance. Useful for forms with
1868
+ * expensive validation logic or many fields.
1869
+ *
1870
+ * @template T - The form data type
1871
+ *
1872
+ * @param {UseFormReturn<T>} form - React Hook Form instance
1873
+ * @param {UseDebouncedValidationOptions} [options] - Configuration options
1874
+ * @param {number} [options.delay=300] - Delay in milliseconds before validation
1875
+ * @param {string[]} [options.fields] - Specific fields to watch (if not provided, watches all)
1876
+ * @param {boolean} [options.enabled=true] - Whether debouncing is enabled
1877
+ *
1878
+ * @returns {Object} Debounced validation utilities
1879
+ * @returns {() => void} debouncedTrigger - Function to trigger debounced validation
1880
+ * @returns {boolean} isDebouncing - Whether validation is currently debouncing
1881
+ *
1882
+ * @example
1883
+ * ```tsx
1884
+ * import { useDebouncedValidation } from "@rachelallyson/hero-hook-form";
1885
+ * import { useForm } from "react-hook-form";
1886
+ *
1887
+ * function MyForm() {
1888
+ * const form = useForm();
1889
+ * const { debouncedTrigger, isDebouncing } = useDebouncedValidation(form, {
1890
+ * delay: 500,
1891
+ * fields: ["email", "username"], // Only watch these fields
1892
+ * });
1893
+ *
1894
+ * return (
1895
+ * <form>
1896
+ * <input
1897
+ * {...form.register("email")}
1898
+ * onChange={(e) => {
1899
+ * form.setValue("email", e.target.value);
1900
+ * debouncedTrigger();
1901
+ * }}
1902
+ * />
1903
+ * {isDebouncing && <span>Validating...</span>}
1904
+ * </form>
1905
+ * );
1906
+ * }
1907
+ * ```
1908
+ *
1909
+ * @see {@link useDebouncedFieldValidation} for single field debouncing
1910
+ * @category Hooks
1911
+ */
1197
1912
  declare function useDebouncedValidation<T extends Record<string, any>>(form: UseFormReturn<T>, options?: UseDebouncedValidationOptions): {
1198
1913
  debouncedTrigger: () => void;
1199
1914
  isDebouncing: boolean;
1200
1915
  };
1916
+ /**
1917
+ * Hook for debouncing validation of a single field.
1918
+ *
1919
+ * @description
1920
+ * Similar to useDebouncedValidation but optimized for a single field.
1921
+ * Automatically triggers validation when the specified field changes.
1922
+ *
1923
+ * @template T - The form data type
1924
+ *
1925
+ * @param {UseFormReturn<T>} form - React Hook Form instance
1926
+ * @param {keyof T} fieldName - Name of the field to debounce
1927
+ * @param {Object} [options] - Configuration options
1928
+ * @param {number} [options.delay=300] - Delay in milliseconds before validation
1929
+ * @param {boolean} [options.enabled=true] - Whether debouncing is enabled
1930
+ *
1931
+ * @returns {Object} Debounced field validation utilities
1932
+ * @returns {() => void} debouncedFieldTrigger - Function to trigger debounced validation for this field
1933
+ * @returns {boolean} isDebouncing - Whether validation is currently debouncing
1934
+ *
1935
+ * @example
1936
+ * ```tsx
1937
+ * import { useDebouncedFieldValidation } from "@rachelallyson/hero-hook-form";
1938
+ * import { useForm } from "react-hook-form";
1939
+ *
1940
+ * function MyForm() {
1941
+ * const form = useForm();
1942
+ * const { debouncedFieldTrigger, isDebouncing } = useDebouncedFieldValidation(
1943
+ * form,
1944
+ * "email",
1945
+ * { delay: 500 }
1946
+ * );
1947
+ *
1948
+ * return (
1949
+ * <input
1950
+ * {...form.register("email")}
1951
+ * onChange={(e) => {
1952
+ * form.setValue("email", e.target.value);
1953
+ * debouncedFieldTrigger();
1954
+ * }}
1955
+ * />
1956
+ * );
1957
+ * }
1958
+ * ```
1959
+ *
1960
+ * @see {@link useDebouncedValidation} for multiple fields
1961
+ * @category Hooks
1962
+ */
1201
1963
  declare function useDebouncedFieldValidation<T extends Record<string, any>>(form: UseFormReturn<T>, fieldName: keyof T, options?: {
1202
1964
  delay?: number;
1203
1965
  enabled?: boolean;
@@ -1206,6 +1968,11 @@ declare function useDebouncedFieldValidation<T extends Record<string, any>>(form
1206
1968
  isDebouncing: boolean;
1207
1969
  };
1208
1970
 
1971
+ /**
1972
+ * Options for the useInferredForm hook.
1973
+ *
1974
+ * @template T - The form data type
1975
+ */
1209
1976
  interface UseInferredFormOptions<T extends FieldValues> {
1210
1977
  defaultValues?: Partial<T>;
1211
1978
  mode?: "onChange" | "onBlur" | "onSubmit" | "onTouched" | "all";
@@ -1214,33 +1981,323 @@ interface UseInferredFormOptions<T extends FieldValues> {
1214
1981
  shouldUnregister?: boolean;
1215
1982
  delayError?: number;
1216
1983
  }
1984
+ /**
1985
+ * Hook for creating a form instance from an inferred form configuration.
1986
+ *
1987
+ * @description
1988
+ * Creates a React Hook Form instance with Zod validation resolver
1989
+ * from a type-inferred form configuration. Automatically sets up
1990
+ * validation based on the provided schema and fields.
1991
+ *
1992
+ * @template T - The form data type
1993
+ *
1994
+ * @param {any} schema - Zod schema for validation
1995
+ * @param {ZodFormFieldConfig<T>[]} fields - Field configurations
1996
+ * @param {UseInferredFormOptions<T>} [options] - Form options
1997
+ * @param {Partial<T>} [options.defaultValues] - Default form values
1998
+ * @param {"onChange"|"onBlur"|"onSubmit"|"onTouched"|"all"} [options.mode="onChange"] - Validation mode
1999
+ * @param {"onChange"|"onBlur"|"onSubmit"} [options.reValidateMode="onChange"] - Re-validation mode
2000
+ * @param {boolean} [options.shouldFocusError=true] - Focus first error field
2001
+ * @param {boolean} [options.shouldUnregister=false] - Unregister fields on unmount
2002
+ * @param {number} [options.delayError=0] - Delay before showing errors
2003
+ *
2004
+ * @returns {UseFormReturn<T>} React Hook Form instance
2005
+ *
2006
+ * @example
2007
+ * ```tsx
2008
+ * import { useInferredForm, defineInferredForm, field } from "@rachelallyson/hero-hook-form";
2009
+ *
2010
+ * const formConfig = defineInferredForm({
2011
+ * name: field.string("Name").min(2),
2012
+ * email: field.email("Email"),
2013
+ * });
2014
+ *
2015
+ * function MyForm() {
2016
+ * const form = useInferredForm(
2017
+ * formConfig.schema,
2018
+ * formConfig.fields,
2019
+ * { mode: "onBlur" }
2020
+ * );
2021
+ *
2022
+ * return (
2023
+ * <form onSubmit={form.handleSubmit(handleSubmit)}>
2024
+ * {/* form fields *\/}
2025
+ * </form>
2026
+ * );
2027
+ * }
2028
+ * ```
2029
+ *
2030
+ * @see {@link defineInferredForm} for creating type-inferred form configurations
2031
+ * @see {@link useTypeInferredForm} for alternative API
2032
+ * @category Hooks
2033
+ */
1217
2034
  declare function useInferredForm<T extends FieldValues>(schema: any, fields: ZodFormFieldConfig<T>[], options?: UseInferredFormOptions<T>): UseFormReturn<T>;
1218
2035
  /**
1219
- * Hook that works with type-inferred forms
2036
+ * Hook that works with type-inferred form configurations.
2037
+ *
2038
+ * @description
2039
+ * Alternative API for useInferredForm that accepts a form configuration
2040
+ * object instead of separate schema and fields parameters. Useful when
2041
+ * working with defineInferredForm results.
2042
+ *
2043
+ * @template T - The form data type
2044
+ *
2045
+ * @param {Object} formConfig - Form configuration object
2046
+ * @param {any} formConfig.schema - Zod schema for validation
2047
+ * @param {ZodFormFieldConfig<T>[]} formConfig.fields - Field configurations
2048
+ * @param {UseInferredFormOptions<T>} [options] - Form options
2049
+ *
2050
+ * @returns {UseFormReturn<T>} React Hook Form instance
2051
+ *
2052
+ * @example
2053
+ * ```tsx
2054
+ * import { useTypeInferredForm, defineInferredForm, field } from "@rachelallyson/hero-hook-form";
2055
+ *
2056
+ * const formConfig = defineInferredForm({
2057
+ * name: field.string("Name").min(2),
2058
+ * email: field.email("Email"),
2059
+ * });
2060
+ *
2061
+ * function MyForm() {
2062
+ * const form = useTypeInferredForm(formConfig);
2063
+ *
2064
+ * return (
2065
+ * <form onSubmit={form.handleSubmit(handleSubmit)}>
2066
+ * {/* form fields *\/}
2067
+ * </form>
2068
+ * );
2069
+ * }
2070
+ * ```
2071
+ *
2072
+ * @see {@link useInferredForm} for direct schema/fields API
2073
+ * @see {@link defineInferredForm} for creating type-inferred form configurations
2074
+ * @category Hooks
1220
2075
  */
1221
2076
  declare function useTypeInferredForm<T extends FieldValues>(formConfig: {
1222
2077
  schema: any;
1223
2078
  fields: ZodFormFieldConfig<T>[];
1224
2079
  }, options?: UseInferredFormOptions<T>): UseFormReturn<T>;
1225
2080
 
2081
+ /**
2082
+ * Props for the ConditionalField component.
2083
+ *
2084
+ * @template TFieldValues - The form data type
2085
+ */
1226
2086
  interface ConditionalFieldProps<TFieldValues extends FieldValues> {
1227
2087
  config: ConditionalFieldConfig<TFieldValues>;
1228
2088
  control: Control<TFieldValues>;
1229
2089
  className?: string;
1230
2090
  }
2091
+ /**
2092
+ * Conditional field component that shows/hides fields based on form values.
2093
+ *
2094
+ * @description
2095
+ * Renders a field only when a condition function returns true based on
2096
+ * current form values. Useful for creating dynamic forms that adapt to
2097
+ * user input. The field is completely removed from the DOM when hidden.
2098
+ *
2099
+ * @template TFieldValues - The form data type
2100
+ *
2101
+ * @param {ConditionalFieldProps<TFieldValues>} props - Component props
2102
+ * @param {ConditionalFieldConfig<TFieldValues>} props.config - Conditional field configuration
2103
+ * @param {Control<TFieldValues>} props.control - React Hook Form control
2104
+ * @param {string} [props.className] - Additional CSS class name
2105
+ *
2106
+ * @returns {JSX.Element|null} The rendered field or null if condition is not met
2107
+ *
2108
+ * @example
2109
+ * ```tsx
2110
+ * import { ConditionalField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
2111
+ *
2112
+ * const fields = [
2113
+ * FormFieldHelpers.checkbox("hasPhone", "I have a phone number"),
2114
+ * ConditionalField({
2115
+ * config: {
2116
+ * name: "phone",
2117
+ * condition: (values) => values.hasPhone === true,
2118
+ * field: FormFieldHelpers.input("phone", "Phone Number", "tel"),
2119
+ * },
2120
+ * control: form.control,
2121
+ * }),
2122
+ * ];
2123
+ * ```
2124
+ *
2125
+ * @example
2126
+ * Multiple conditions:
2127
+ * ```tsx
2128
+ * ConditionalField({
2129
+ * config: {
2130
+ * name: "businessDetails",
2131
+ * condition: (values) =>
2132
+ * values.userType === "business" && values.isRegistered === true,
2133
+ * field: FormFieldHelpers.input("taxId", "Tax ID"),
2134
+ * },
2135
+ * control: form.control,
2136
+ * }),
2137
+ * ```
2138
+ *
2139
+ * @see {@link DynamicSectionField} for grouping multiple conditional fields
2140
+ * @see {@link FieldArrayField} for repeating fields
2141
+ * @category Fields
2142
+ */
1231
2143
  declare function ConditionalField<TFieldValues extends FieldValues>({ className, config, control, }: ConditionalFieldProps<TFieldValues>): React$1.JSX.Element | null;
1232
2144
 
2145
+ interface ContentFieldProps<TFieldValues extends FieldValues> {
2146
+ config: ContentFieldConfig<TFieldValues>;
2147
+ form: UseFormReturn<TFieldValues>;
2148
+ submissionState: FormSubmissionState;
2149
+ }
2150
+ declare function ContentField<TFieldValues extends FieldValues>({ config, form, submissionState, }: ContentFieldProps<TFieldValues>): React$1.JSX.Element;
2151
+
2152
+ /**
2153
+ * Props for the FieldArrayField component.
2154
+ *
2155
+ * @template TFieldValues - The form data type
2156
+ */
1233
2157
  interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
1234
2158
  config: FieldArrayConfig<TFieldValues>;
1235
2159
  className?: string;
1236
2160
  }
2161
+ /**
2162
+ * Field array component for dynamic repeating field groups.
2163
+ *
2164
+ * @description
2165
+ * Allows users to add and remove multiple instances of a field group.
2166
+ * Useful for forms with repeating data like addresses, items, or contacts.
2167
+ * Automatically manages field array state and provides add/remove buttons.
2168
+ *
2169
+ * @template TFieldValues - The form data type
2170
+ *
2171
+ * @param {FieldArrayFieldProps<TFieldValues>} props - Component props
2172
+ * @param {FieldArrayConfig<TFieldValues>} props.config - Field array configuration
2173
+ * @param {string} [props.className] - Additional CSS class name
2174
+ *
2175
+ * @returns {JSX.Element} The rendered field array with add/remove controls
2176
+ *
2177
+ * @example
2178
+ * ```tsx
2179
+ * import { FieldArrayField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
2180
+ *
2181
+ * const fields = [
2182
+ * FormFieldHelpers.input("name", "Name"),
2183
+ * FieldArrayField({
2184
+ * config: {
2185
+ * name: "addresses",
2186
+ * label: "Address",
2187
+ * fields: [
2188
+ * FormFieldHelpers.input("street", "Street Address"),
2189
+ * FormFieldHelpers.input("city", "City"),
2190
+ * FormFieldHelpers.input("zipCode", "ZIP Code"),
2191
+ * ],
2192
+ * min: 1,
2193
+ * max: 5,
2194
+ * addButtonText: "Add Address",
2195
+ * removeButtonText: "Remove Address",
2196
+ * },
2197
+ * }),
2198
+ * ];
2199
+ * ```
2200
+ *
2201
+ * @example
2202
+ * With validation:
2203
+ * ```tsx
2204
+ * const schema = z.object({
2205
+ * addresses: z.array(z.object({
2206
+ * street: z.string().min(1, "Street is required"),
2207
+ * city: z.string().min(1, "City is required"),
2208
+ * })).min(1, "At least one address is required"),
2209
+ * });
2210
+ * ```
2211
+ *
2212
+ * @see {@link ConditionalField} for conditional single fields
2213
+ * @see {@link DynamicSectionField} for conditional field groups
2214
+ * @category Fields
2215
+ */
1237
2216
  declare function FieldArrayField<TFieldValues extends FieldValues>({ className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
1238
2217
 
2218
+ /**
2219
+ * Props for the DynamicSectionField component.
2220
+ *
2221
+ * @template TFieldValues - The form data type
2222
+ */
1239
2223
  interface DynamicSectionFieldProps<TFieldValues extends FieldValues> {
1240
2224
  config: DynamicSectionConfig<TFieldValues>;
1241
2225
  control: Control<TFieldValues>;
1242
2226
  className?: string;
1243
2227
  }
2228
+ /**
2229
+ * Dynamic section component that shows/hides groups of fields based on form values.
2230
+ *
2231
+ * @description
2232
+ * Similar to ConditionalField but for groups of fields. Renders a section
2233
+ * with title, description, and multiple fields when a condition is met.
2234
+ * Useful for creating multi-step-like experiences or conditional form sections.
2235
+ *
2236
+ * @template TFieldValues - The form data type
2237
+ *
2238
+ * @param {DynamicSectionFieldProps<TFieldValues>} props - Component props
2239
+ * @param {DynamicSectionConfig<TFieldValues>} props.config - Dynamic section configuration
2240
+ * @param {Control<TFieldValues>} props.control - React Hook Form control
2241
+ * @param {string} [props.className] - Additional CSS class name
2242
+ *
2243
+ * @returns {JSX.Element|null} The rendered section or null if condition is not met
2244
+ *
2245
+ * @example
2246
+ * ```tsx
2247
+ * import { DynamicSectionField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
2248
+ *
2249
+ * const fields = [
2250
+ * FormFieldHelpers.checkbox("hasEmergencyContact", "Has Emergency Contact"),
2251
+ * DynamicSectionField({
2252
+ * config: {
2253
+ * name: "emergencyContact",
2254
+ * title: "Emergency Contact Information",
2255
+ * description: "Please provide emergency contact details",
2256
+ * condition: (values) => values.hasEmergencyContact === true,
2257
+ * fields: [
2258
+ * FormFieldHelpers.input("name", "Contact Name"),
2259
+ * FormFieldHelpers.input("relationship", "Relationship"),
2260
+ * FormFieldHelpers.input("phone", "Phone Number", "tel"),
2261
+ * FormFieldHelpers.input("email", "Email", "email"),
2262
+ * ],
2263
+ * },
2264
+ * control: form.control,
2265
+ * }),
2266
+ * ];
2267
+ * ```
2268
+ *
2269
+ * @example
2270
+ * Nested dynamic sections:
2271
+ * ```tsx
2272
+ * DynamicSectionField({
2273
+ * config: {
2274
+ * name: "businessInfo",
2275
+ * title: "Business Information",
2276
+ * condition: (values) => values.accountType === "business",
2277
+ * fields: [
2278
+ * FormFieldHelpers.input("businessName", "Business Name"),
2279
+ * DynamicSectionField({
2280
+ * config: {
2281
+ * name: "billingAddress",
2282
+ * title: "Billing Address",
2283
+ * condition: (values) => values.businessName && values.taxId,
2284
+ * fields: [
2285
+ * FormFieldHelpers.input("street", "Street Address"),
2286
+ * FormFieldHelpers.input("city", "City"),
2287
+ * ],
2288
+ * },
2289
+ * control: form.control,
2290
+ * }),
2291
+ * ],
2292
+ * },
2293
+ * control: form.control,
2294
+ * }),
2295
+ * ```
2296
+ *
2297
+ * @see {@link ConditionalField} for single conditional fields
2298
+ * @see {@link FieldArrayField} for repeating fields
2299
+ * @category Fields
2300
+ */
1244
2301
  declare function DynamicSectionField<TFieldValues extends FieldValues>({ className, config, control, }: DynamicSectionFieldProps<TFieldValues>): React$1.JSX.Element | null;
1245
2302
 
1246
2303
  interface FormStatusProps<T extends Record<string, any>> {
@@ -1380,4 +2437,4 @@ declare const validationUtils: {
1380
2437
  }>;
1381
2438
  };
1382
2439
 
1383
- 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 };
2440
+ 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, ContentField, type ContentFieldConfig, 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 };