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