@rachelallyson/hero-hook-form 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/index.d.ts +922 -40
- package/dist/index.js +10 -19
- package/dist/react/index.d.ts +922 -40
- package/dist/react/index.js +10 -19
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -123,9 +123,9 @@ interface DynamicSectionConfig<TFieldValues extends FieldValues> extends BaseFor
|
|
|
123
123
|
condition: (formData: Partial<TFieldValues>) => boolean;
|
|
124
124
|
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
125
125
|
}
|
|
126
|
-
interface ContentFieldConfig<TFieldValues extends FieldValues> {
|
|
126
|
+
interface ContentFieldConfig<TFieldValues extends FieldValues = FieldValues> {
|
|
127
127
|
type: "content";
|
|
128
|
-
name?:
|
|
128
|
+
name?: string;
|
|
129
129
|
title?: string;
|
|
130
130
|
description?: string;
|
|
131
131
|
render?: (field: {
|
|
@@ -155,14 +155,6 @@ interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<T
|
|
|
155
155
|
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
156
156
|
onError?: (errors: FieldErrors<TFieldValues>) => void;
|
|
157
157
|
errorDisplay?: "inline" | "toast" | "modal" | "none";
|
|
158
|
-
render?: (formState: {
|
|
159
|
-
form: UseFormReturn<TFieldValues>;
|
|
160
|
-
isSubmitting: boolean;
|
|
161
|
-
isSubmitted: boolean;
|
|
162
|
-
isSuccess: boolean;
|
|
163
|
-
errors: FieldErrors<TFieldValues>;
|
|
164
|
-
values: TFieldValues;
|
|
165
|
-
}) => React.ReactNode;
|
|
166
158
|
}
|
|
167
159
|
interface FormValidationError {
|
|
168
160
|
message: string;
|
|
@@ -436,23 +428,262 @@ interface ServerActionFormProps<T extends FieldValues> {
|
|
|
436
428
|
*/
|
|
437
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;
|
|
438
430
|
|
|
431
|
+
/**
|
|
432
|
+
* Props for the CheckboxField component.
|
|
433
|
+
*
|
|
434
|
+
* @template TFieldValues - The form data type
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```tsx
|
|
438
|
+
* import { CheckboxField } from "@rachelallyson/hero-hook-form";
|
|
439
|
+
* import { useForm } from "react-hook-form";
|
|
440
|
+
*
|
|
441
|
+
* const form = useForm({
|
|
442
|
+
* defaultValues: { newsletter: false },
|
|
443
|
+
* });
|
|
444
|
+
*
|
|
445
|
+
* <CheckboxField
|
|
446
|
+
* control={form.control}
|
|
447
|
+
* name="newsletter"
|
|
448
|
+
* label="Subscribe to newsletter"
|
|
449
|
+
* description="Receive weekly updates"
|
|
450
|
+
* />
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
439
453
|
type CheckboxFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
454
|
+
/** Additional props to pass to the underlying Checkbox component */
|
|
440
455
|
checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
441
456
|
};
|
|
457
|
+
/**
|
|
458
|
+
* A checkbox field component that integrates React Hook Form with HeroUI Checkbox.
|
|
459
|
+
*
|
|
460
|
+
* This component provides a type-safe checkbox field with validation support,
|
|
461
|
+
* error handling, and accessibility features. The field value is a boolean.
|
|
462
|
+
*
|
|
463
|
+
* @template TFieldValues - The form data type
|
|
464
|
+
*
|
|
465
|
+
* @param props - The checkbox field props
|
|
466
|
+
* @returns The rendered checkbox field component
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```tsx
|
|
470
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
471
|
+
* import { z } from "zod";
|
|
472
|
+
*
|
|
473
|
+
* const schema = z.object({
|
|
474
|
+
* terms: z.boolean().refine((val) => val === true, {
|
|
475
|
+
* message: "You must accept the terms",
|
|
476
|
+
* }),
|
|
477
|
+
* newsletter: z.boolean().optional(),
|
|
478
|
+
* });
|
|
479
|
+
*
|
|
480
|
+
* function MyForm() {
|
|
481
|
+
* return (
|
|
482
|
+
* <ZodForm
|
|
483
|
+
* config={{
|
|
484
|
+
* schema,
|
|
485
|
+
* fields: [
|
|
486
|
+
* FormFieldHelpers.checkbox("terms", "I accept the terms and conditions"),
|
|
487
|
+
* FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter"),
|
|
488
|
+
* ],
|
|
489
|
+
* }}
|
|
490
|
+
* onSubmit={(data) => console.log(data)}
|
|
491
|
+
* />
|
|
492
|
+
* );
|
|
493
|
+
* }
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```tsx
|
|
498
|
+
* // With custom styling
|
|
499
|
+
* <CheckboxField
|
|
500
|
+
* control={form.control}
|
|
501
|
+
* name="newsletter"
|
|
502
|
+
* label="Subscribe"
|
|
503
|
+
* checkboxProps={{
|
|
504
|
+
* color: "primary",
|
|
505
|
+
* size: "lg",
|
|
506
|
+
* }}
|
|
507
|
+
* />
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
442
510
|
declare function CheckboxField<TFieldValues extends FieldValues>(props: CheckboxFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
443
511
|
|
|
512
|
+
/**
|
|
513
|
+
* Props for the DateField component.
|
|
514
|
+
*
|
|
515
|
+
* @template TFieldValues - The form data type
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```tsx
|
|
519
|
+
* import { DateField } from "@rachelallyson/hero-hook-form";
|
|
520
|
+
* import { useForm } from "react-hook-form";
|
|
521
|
+
* import { CalendarDate } from "@internationalized/date";
|
|
522
|
+
*
|
|
523
|
+
* const form = useForm({
|
|
524
|
+
* defaultValues: { birthDate: null as CalendarDate | null },
|
|
525
|
+
* });
|
|
526
|
+
*
|
|
527
|
+
* <DateField
|
|
528
|
+
* control={form.control}
|
|
529
|
+
* name="birthDate"
|
|
530
|
+
* label="Birth Date"
|
|
531
|
+
* description="Select your date of birth"
|
|
532
|
+
* />
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
444
535
|
type DateFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, CalendarDate | null> & WithControl<TFieldValues> & {
|
|
536
|
+
/** Additional props to pass to the underlying DateInput component */
|
|
445
537
|
dateProps?: Omit<React$1.ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
538
|
+
/** Transform function to modify the date value before it's set */
|
|
446
539
|
transform?: (value: CalendarDate | null) => CalendarDate | null;
|
|
447
540
|
};
|
|
541
|
+
/**
|
|
542
|
+
* A date input field component that integrates React Hook Form with HeroUI DateInput.
|
|
543
|
+
*
|
|
544
|
+
* This component provides a type-safe date field with validation support,
|
|
545
|
+
* error handling, and accessibility features. Uses `@internationalized/date`
|
|
546
|
+
* for date handling.
|
|
547
|
+
*
|
|
548
|
+
* @template TFieldValues - The form data type
|
|
549
|
+
*
|
|
550
|
+
* @param props - The date field props
|
|
551
|
+
* @returns The rendered date field component
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```tsx
|
|
555
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
556
|
+
* import { z } from "zod";
|
|
557
|
+
* import { CalendarDate } from "@internationalized/date";
|
|
558
|
+
*
|
|
559
|
+
* const schema = z.object({
|
|
560
|
+
* birthDate: z.instanceof(CalendarDate).nullable(),
|
|
561
|
+
* eventDate: z.instanceof(CalendarDate),
|
|
562
|
+
* });
|
|
563
|
+
*
|
|
564
|
+
* function MyForm() {
|
|
565
|
+
* return (
|
|
566
|
+
* <ZodForm
|
|
567
|
+
* config={{
|
|
568
|
+
* schema,
|
|
569
|
+
* fields: [
|
|
570
|
+
* FormFieldHelpers.date("birthDate", "Birth Date"),
|
|
571
|
+
* FormFieldHelpers.date("eventDate", "Event Date"),
|
|
572
|
+
* ],
|
|
573
|
+
* }}
|
|
574
|
+
* onSubmit={(data) => console.log(data)}
|
|
575
|
+
* />
|
|
576
|
+
* );
|
|
577
|
+
* }
|
|
578
|
+
* ```
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```tsx
|
|
582
|
+
* // With custom date format and min/max dates
|
|
583
|
+
* <DateField
|
|
584
|
+
* control={form.control}
|
|
585
|
+
* name="eventDate"
|
|
586
|
+
* label="Event Date"
|
|
587
|
+
* dateProps={{
|
|
588
|
+
* minValue: new CalendarDate(2024, 1, 1),
|
|
589
|
+
* maxValue: new CalendarDate(2024, 12, 31),
|
|
590
|
+
* }}
|
|
591
|
+
* />
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
448
594
|
declare function DateField<TFieldValues extends FieldValues>(props: DateFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
449
595
|
|
|
596
|
+
/**
|
|
597
|
+
* Props for the FileField component.
|
|
598
|
+
*
|
|
599
|
+
* @template TFieldValues - The form data type
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```tsx
|
|
603
|
+
* import { FileField } from "@rachelallyson/hero-hook-form";
|
|
604
|
+
* import { useForm } from "react-hook-form";
|
|
605
|
+
*
|
|
606
|
+
* const form = useForm({
|
|
607
|
+
* defaultValues: { avatar: null as FileList | null },
|
|
608
|
+
* });
|
|
609
|
+
*
|
|
610
|
+
* <FileField
|
|
611
|
+
* control={form.control}
|
|
612
|
+
* name="avatar"
|
|
613
|
+
* label="Upload Avatar"
|
|
614
|
+
* accept="image/*"
|
|
615
|
+
* description="Select an image file"
|
|
616
|
+
* />
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
450
619
|
type FileFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, FileList | null> & WithControl<TFieldValues> & {
|
|
620
|
+
/** Additional props to pass to the underlying Input component */
|
|
451
621
|
fileProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "type">;
|
|
622
|
+
/** Transform function to modify the file list before it's set */
|
|
452
623
|
transform?: (value: FileList | null) => FileList | null;
|
|
624
|
+
/** Whether multiple files can be selected */
|
|
453
625
|
multiple?: boolean;
|
|
626
|
+
/** Accepted file types (e.g., "image/*", ".pdf,.doc") */
|
|
454
627
|
accept?: string;
|
|
455
628
|
};
|
|
629
|
+
/**
|
|
630
|
+
* A file input field component that integrates React Hook Form with HeroUI Input.
|
|
631
|
+
*
|
|
632
|
+
* This component provides a type-safe file upload field with validation support,
|
|
633
|
+
* error handling, and accessibility features. The field value is a `FileList` or `null`.
|
|
634
|
+
*
|
|
635
|
+
* @template TFieldValues - The form data type
|
|
636
|
+
*
|
|
637
|
+
* @param props - The file field props
|
|
638
|
+
* @returns The rendered file field component
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```tsx
|
|
642
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
643
|
+
* import { z } from "zod";
|
|
644
|
+
*
|
|
645
|
+
* const schema = z.object({
|
|
646
|
+
* avatar: z.instanceof(FileList).nullable(),
|
|
647
|
+
* documents: z.instanceof(FileList).optional(),
|
|
648
|
+
* });
|
|
649
|
+
*
|
|
650
|
+
* function MyForm() {
|
|
651
|
+
* return (
|
|
652
|
+
* <ZodForm
|
|
653
|
+
* config={{
|
|
654
|
+
* schema,
|
|
655
|
+
* fields: [
|
|
656
|
+
* FormFieldHelpers.file("avatar", "Upload Avatar", { accept: "image/*" }),
|
|
657
|
+
* FormFieldHelpers.file("documents", "Upload Documents", {
|
|
658
|
+
* multiple: true,
|
|
659
|
+
* accept: ".pdf,.doc,.docx",
|
|
660
|
+
* }),
|
|
661
|
+
* ],
|
|
662
|
+
* }}
|
|
663
|
+
* onSubmit={(data) => console.log(data)}
|
|
664
|
+
* />
|
|
665
|
+
* );
|
|
666
|
+
* }
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```tsx
|
|
671
|
+
* // With file size validation
|
|
672
|
+
* <FileField
|
|
673
|
+
* control={form.control}
|
|
674
|
+
* name="avatar"
|
|
675
|
+
* label="Upload Avatar"
|
|
676
|
+
* accept="image/*"
|
|
677
|
+
* transform={(files) => {
|
|
678
|
+
* if (files && files[0] && files[0].size > 5 * 1024 * 1024) {
|
|
679
|
+
* // File too large
|
|
680
|
+
* return null;
|
|
681
|
+
* }
|
|
682
|
+
* return files;
|
|
683
|
+
* }}
|
|
684
|
+
* />
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
456
687
|
declare function FileField<TFieldValues extends FieldValues>(props: FileFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
457
688
|
|
|
458
689
|
interface FontPickerProps {
|
|
@@ -466,51 +697,532 @@ type FontPickerFieldProps<TFieldValues extends FieldValues, TValue extends strin
|
|
|
466
697
|
};
|
|
467
698
|
declare function FontPickerField<TFieldValues extends FieldValues, TValue extends string = string>(props: FontPickerFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
468
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Props for the InputField component.
|
|
702
|
+
*
|
|
703
|
+
* @template TFieldValues - The form data type
|
|
704
|
+
*/
|
|
469
705
|
type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
470
706
|
inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
471
707
|
transform?: (value: string) => string;
|
|
472
708
|
};
|
|
709
|
+
/**
|
|
710
|
+
* Input field component for text, email, password, tel, and number inputs.
|
|
711
|
+
*
|
|
712
|
+
* @description
|
|
713
|
+
* A memoized input field component that integrates with React Hook Form
|
|
714
|
+
* and HeroUI Input component. Supports all standard input types and
|
|
715
|
+
* includes automatic validation error display.
|
|
716
|
+
*
|
|
717
|
+
* @template TFieldValues - The form data type
|
|
718
|
+
*
|
|
719
|
+
* @param {InputFieldProps<TFieldValues>} props - Component props
|
|
720
|
+
* @param {Path<TFieldValues>} props.name - Field name path
|
|
721
|
+
* @param {string} [props.label] - Field label
|
|
722
|
+
* @param {string} [props.description] - Field description/help text
|
|
723
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
724
|
+
* @param {boolean} [props.isDisabled] - Whether field is disabled
|
|
725
|
+
* @param {RegisterOptions<TFieldValues>} [props.rules] - Validation rules
|
|
726
|
+
* @param {Partial<InputProps>} [props.inputProps] - Additional Input component props
|
|
727
|
+
* @param {(value: string) => string} [props.transform] - Value transformation function
|
|
728
|
+
*
|
|
729
|
+
* @returns {JSX.Element} The rendered input field
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```tsx
|
|
733
|
+
* import { InputField } from "@rachelallyson/hero-hook-form";
|
|
734
|
+
* import { useForm, Controller } from "react-hook-form";
|
|
735
|
+
*
|
|
736
|
+
* function MyForm() {
|
|
737
|
+
* const { control } = useForm();
|
|
738
|
+
*
|
|
739
|
+
* return (
|
|
740
|
+
* <InputField
|
|
741
|
+
* name="email"
|
|
742
|
+
* label="Email Address"
|
|
743
|
+
* description="Enter your email address"
|
|
744
|
+
* control={control}
|
|
745
|
+
* inputProps={{
|
|
746
|
+
* type: "email",
|
|
747
|
+
* placeholder: "you@example.com",
|
|
748
|
+
* }}
|
|
749
|
+
* />
|
|
750
|
+
* );
|
|
751
|
+
* }
|
|
752
|
+
* ```
|
|
753
|
+
*
|
|
754
|
+
* @see {@link FormFieldHelpers.input} for helper function to create input field config
|
|
755
|
+
* @category Fields
|
|
756
|
+
*/
|
|
473
757
|
declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
|
|
474
758
|
|
|
759
|
+
/**
|
|
760
|
+
* Configuration for a radio option.
|
|
761
|
+
*
|
|
762
|
+
* @template TValue - The value type for the option
|
|
763
|
+
*/
|
|
475
764
|
interface RadioOption<TValue extends string | number> {
|
|
765
|
+
/** Display label for the option */
|
|
476
766
|
label: string;
|
|
767
|
+
/** Value of the option */
|
|
477
768
|
value: TValue;
|
|
769
|
+
/** Optional description text */
|
|
478
770
|
description?: string;
|
|
771
|
+
/** Whether the option is disabled */
|
|
479
772
|
disabled?: boolean;
|
|
480
773
|
}
|
|
774
|
+
/**
|
|
775
|
+
* Props for the RadioGroupField component.
|
|
776
|
+
*
|
|
777
|
+
* @template TFieldValues - The form data type
|
|
778
|
+
* @template TValue - The value type for the radio group (string or number)
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```tsx
|
|
782
|
+
* import { RadioGroupField } from "@rachelallyson/hero-hook-form";
|
|
783
|
+
* import { useForm } from "react-hook-form";
|
|
784
|
+
*
|
|
785
|
+
* const form = useForm({
|
|
786
|
+
* defaultValues: { plan: "" },
|
|
787
|
+
* });
|
|
788
|
+
*
|
|
789
|
+
* const options = [
|
|
790
|
+
* { label: "Basic", value: "basic" },
|
|
791
|
+
* { label: "Pro", value: "pro" },
|
|
792
|
+
* { label: "Enterprise", value: "enterprise" },
|
|
793
|
+
* ];
|
|
794
|
+
*
|
|
795
|
+
* <RadioGroupField
|
|
796
|
+
* control={form.control}
|
|
797
|
+
* name="plan"
|
|
798
|
+
* label="Select Plan"
|
|
799
|
+
* options={options}
|
|
800
|
+
* />
|
|
801
|
+
* ```
|
|
802
|
+
*/
|
|
481
803
|
type RadioGroupFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
804
|
+
/** Array of radio options */
|
|
482
805
|
options: readonly RadioOption<TValue>[];
|
|
806
|
+
/** Additional props to pass to the underlying RadioGroup component */
|
|
483
807
|
radioGroupProps?: Omit<React$1.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">;
|
|
484
808
|
};
|
|
809
|
+
/**
|
|
810
|
+
* A radio group field component that integrates React Hook Form with HeroUI RadioGroup.
|
|
811
|
+
*
|
|
812
|
+
* This component provides a type-safe radio group field with validation support,
|
|
813
|
+
* error handling, and accessibility features. Only one option can be selected at a time.
|
|
814
|
+
*
|
|
815
|
+
* @template TFieldValues - The form data type
|
|
816
|
+
* @template TValue - The value type for the radio group (string or number)
|
|
817
|
+
*
|
|
818
|
+
* @param props - The radio group field props
|
|
819
|
+
* @returns The rendered radio group field component
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```tsx
|
|
823
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
824
|
+
* import { z } from "zod";
|
|
825
|
+
*
|
|
826
|
+
* const schema = z.object({
|
|
827
|
+
* plan: z.enum(["basic", "pro", "enterprise"], {
|
|
828
|
+
* required_error: "Please select a plan",
|
|
829
|
+
* }),
|
|
830
|
+
* });
|
|
831
|
+
*
|
|
832
|
+
* const options = [
|
|
833
|
+
* { label: "Basic - $9/month", value: "basic" },
|
|
834
|
+
* { label: "Pro - $29/month", value: "pro" },
|
|
835
|
+
* { label: "Enterprise - $99/month", value: "enterprise" },
|
|
836
|
+
* ];
|
|
837
|
+
*
|
|
838
|
+
* function MyForm() {
|
|
839
|
+
* return (
|
|
840
|
+
* <ZodForm
|
|
841
|
+
* config={{
|
|
842
|
+
* schema,
|
|
843
|
+
* fields: [
|
|
844
|
+
* FormFieldHelpers.radioGroup("plan", "Select Plan", options),
|
|
845
|
+
* ],
|
|
846
|
+
* }}
|
|
847
|
+
* onSubmit={(data) => console.log(data)}
|
|
848
|
+
* />
|
|
849
|
+
* );
|
|
850
|
+
* }
|
|
851
|
+
* ```
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* ```tsx
|
|
855
|
+
* // With custom styling
|
|
856
|
+
* <RadioGroupField
|
|
857
|
+
* control={form.control}
|
|
858
|
+
* name="plan"
|
|
859
|
+
* label="Select Plan"
|
|
860
|
+
* options={options}
|
|
861
|
+
* radioGroupProps={{
|
|
862
|
+
* orientation: "horizontal",
|
|
863
|
+
* color: "primary",
|
|
864
|
+
* }}
|
|
865
|
+
* />
|
|
866
|
+
* ```
|
|
867
|
+
*/
|
|
485
868
|
declare function RadioGroupField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: RadioGroupFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
486
869
|
|
|
870
|
+
/**
|
|
871
|
+
* Configuration for a select option.
|
|
872
|
+
*
|
|
873
|
+
* @template TValue - The value type for the option
|
|
874
|
+
*/
|
|
487
875
|
interface SelectOption<TValue extends string | number> {
|
|
876
|
+
/** Display label for the option */
|
|
488
877
|
label: string;
|
|
878
|
+
/** Value of the option */
|
|
489
879
|
value: TValue;
|
|
880
|
+
/** Optional description text */
|
|
490
881
|
description?: string;
|
|
882
|
+
/** Whether the option is disabled */
|
|
491
883
|
disabled?: boolean;
|
|
492
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* Props for the SelectField component.
|
|
887
|
+
*
|
|
888
|
+
* @template TFieldValues - The form data type
|
|
889
|
+
* @template TValue - The value type for the select field (string or number)
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```tsx
|
|
893
|
+
* import { SelectField } from "@rachelallyson/hero-hook-form";
|
|
894
|
+
* import { useForm } from "react-hook-form";
|
|
895
|
+
*
|
|
896
|
+
* const form = useForm({
|
|
897
|
+
* defaultValues: { country: "" },
|
|
898
|
+
* });
|
|
899
|
+
*
|
|
900
|
+
* const options = [
|
|
901
|
+
* { label: "United States", value: "us" },
|
|
902
|
+
* { label: "Canada", value: "ca" },
|
|
903
|
+
* { label: "Mexico", value: "mx" },
|
|
904
|
+
* ];
|
|
905
|
+
*
|
|
906
|
+
* <SelectField
|
|
907
|
+
* control={form.control}
|
|
908
|
+
* name="country"
|
|
909
|
+
* label="Country"
|
|
910
|
+
* options={options}
|
|
911
|
+
* placeholder="Select a country"
|
|
912
|
+
* />
|
|
913
|
+
* ```
|
|
914
|
+
*/
|
|
493
915
|
type SelectFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
916
|
+
/** Array of select options */
|
|
494
917
|
options: readonly SelectOption<TValue>[];
|
|
918
|
+
/** Placeholder text when no option is selected */
|
|
495
919
|
placeholder?: string;
|
|
920
|
+
/** Additional props to pass to the underlying Select component */
|
|
496
921
|
selectProps?: Omit<React$1.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
497
922
|
};
|
|
923
|
+
/**
|
|
924
|
+
* A select dropdown field component that integrates React Hook Form with HeroUI Select.
|
|
925
|
+
*
|
|
926
|
+
* This component provides a type-safe select field with validation support,
|
|
927
|
+
* error handling, and accessibility features.
|
|
928
|
+
*
|
|
929
|
+
* @template TFieldValues - The form data type
|
|
930
|
+
* @template TValue - The value type for the select field (string or number)
|
|
931
|
+
*
|
|
932
|
+
* @param props - The select field props
|
|
933
|
+
* @returns The rendered select field component
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```tsx
|
|
937
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
938
|
+
* import { z } from "zod";
|
|
939
|
+
*
|
|
940
|
+
* const schema = z.object({
|
|
941
|
+
* country: z.string().min(1, "Please select a country"),
|
|
942
|
+
* });
|
|
943
|
+
*
|
|
944
|
+
* const options = [
|
|
945
|
+
* { label: "United States", value: "us" },
|
|
946
|
+
* { label: "Canada", value: "ca" },
|
|
947
|
+
* ];
|
|
948
|
+
*
|
|
949
|
+
* function MyForm() {
|
|
950
|
+
* return (
|
|
951
|
+
* <ZodForm
|
|
952
|
+
* config={{
|
|
953
|
+
* schema,
|
|
954
|
+
* fields: [
|
|
955
|
+
* FormFieldHelpers.select("country", "Country", options, "Select a country"),
|
|
956
|
+
* ],
|
|
957
|
+
* }}
|
|
958
|
+
* onSubmit={(data) => console.log(data)}
|
|
959
|
+
* />
|
|
960
|
+
* );
|
|
961
|
+
* }
|
|
962
|
+
* ```
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```tsx
|
|
966
|
+
* // With custom styling
|
|
967
|
+
* <SelectField
|
|
968
|
+
* control={form.control}
|
|
969
|
+
* name="country"
|
|
970
|
+
* label="Country"
|
|
971
|
+
* options={options}
|
|
972
|
+
* selectProps={{
|
|
973
|
+
* variant: "bordered",
|
|
974
|
+
* size: "lg",
|
|
975
|
+
* }}
|
|
976
|
+
* />
|
|
977
|
+
* ```
|
|
978
|
+
*/
|
|
498
979
|
declare function SelectField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: SelectFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
499
980
|
|
|
981
|
+
/**
|
|
982
|
+
* Props for the SliderField component.
|
|
983
|
+
*
|
|
984
|
+
* @template TFieldValues - The form data type
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```tsx
|
|
988
|
+
* import { SliderField } from "@rachelallyson/hero-hook-form";
|
|
989
|
+
* import { useForm } from "react-hook-form";
|
|
990
|
+
*
|
|
991
|
+
* const form = useForm({
|
|
992
|
+
* defaultValues: { volume: 50 },
|
|
993
|
+
* });
|
|
994
|
+
*
|
|
995
|
+
* <SliderField
|
|
996
|
+
* control={form.control}
|
|
997
|
+
* name="volume"
|
|
998
|
+
* label="Volume"
|
|
999
|
+
* description="Adjust the volume level"
|
|
1000
|
+
* />
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
500
1003
|
type SliderFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, number> & WithControl<TFieldValues> & {
|
|
1004
|
+
/** Additional props to pass to the underlying Slider component */
|
|
501
1005
|
sliderProps?: Omit<React$1.ComponentProps<typeof Slider>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
1006
|
+
/** Transform function to modify the slider value before it's set */
|
|
502
1007
|
transform?: (value: number) => number;
|
|
503
1008
|
};
|
|
1009
|
+
/**
|
|
1010
|
+
* A slider field component that integrates React Hook Form with HeroUI Slider.
|
|
1011
|
+
*
|
|
1012
|
+
* This component provides a type-safe slider field with validation support,
|
|
1013
|
+
* error handling, and accessibility features. The field value is a number.
|
|
1014
|
+
*
|
|
1015
|
+
* @template TFieldValues - The form data type
|
|
1016
|
+
*
|
|
1017
|
+
* @param props - The slider field props
|
|
1018
|
+
* @returns The rendered slider field component
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```tsx
|
|
1022
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
1023
|
+
* import { z } from "zod";
|
|
1024
|
+
*
|
|
1025
|
+
* const schema = z.object({
|
|
1026
|
+
* volume: z.number().min(0).max(100),
|
|
1027
|
+
* brightness: z.number().min(0).max(100),
|
|
1028
|
+
* });
|
|
1029
|
+
*
|
|
1030
|
+
* function MyForm() {
|
|
1031
|
+
* return (
|
|
1032
|
+
* <ZodForm
|
|
1033
|
+
* config={{
|
|
1034
|
+
* schema,
|
|
1035
|
+
* fields: [
|
|
1036
|
+
* FormFieldHelpers.slider("volume", "Volume", { min: 0, max: 100 }),
|
|
1037
|
+
* FormFieldHelpers.slider("brightness", "Brightness", { min: 0, max: 100 }),
|
|
1038
|
+
* ],
|
|
1039
|
+
* }}
|
|
1040
|
+
* onSubmit={(data) => console.log(data)}
|
|
1041
|
+
* />
|
|
1042
|
+
* );
|
|
1043
|
+
* }
|
|
1044
|
+
* ```
|
|
1045
|
+
*
|
|
1046
|
+
* @example
|
|
1047
|
+
* ```tsx
|
|
1048
|
+
* // With custom step and marks
|
|
1049
|
+
* <SliderField
|
|
1050
|
+
* control={form.control}
|
|
1051
|
+
* name="volume"
|
|
1052
|
+
* label="Volume"
|
|
1053
|
+
* sliderProps={{
|
|
1054
|
+
* minValue: 0,
|
|
1055
|
+
* maxValue: 100,
|
|
1056
|
+
* step: 10,
|
|
1057
|
+
* marks: [
|
|
1058
|
+
* { value: 0, label: "0" },
|
|
1059
|
+
* { value: 50, label: "50" },
|
|
1060
|
+
* { value: 100, label: "100" },
|
|
1061
|
+
* ],
|
|
1062
|
+
* }}
|
|
1063
|
+
* />
|
|
1064
|
+
* ```
|
|
1065
|
+
*/
|
|
504
1066
|
declare function SliderField<TFieldValues extends FieldValues>(props: SliderFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
505
1067
|
|
|
1068
|
+
/**
|
|
1069
|
+
* Props for the SwitchField component.
|
|
1070
|
+
*
|
|
1071
|
+
* @template TFieldValues - The form data type
|
|
1072
|
+
*
|
|
1073
|
+
* @example
|
|
1074
|
+
* ```tsx
|
|
1075
|
+
* import { SwitchField } from "@rachelallyson/hero-hook-form";
|
|
1076
|
+
* import { useForm } from "react-hook-form";
|
|
1077
|
+
*
|
|
1078
|
+
* const form = useForm({
|
|
1079
|
+
* defaultValues: { notifications: false },
|
|
1080
|
+
* });
|
|
1081
|
+
*
|
|
1082
|
+
* <SwitchField
|
|
1083
|
+
* control={form.control}
|
|
1084
|
+
* name="notifications"
|
|
1085
|
+
* label="Enable notifications"
|
|
1086
|
+
* description="Receive email notifications"
|
|
1087
|
+
* />
|
|
1088
|
+
* ```
|
|
1089
|
+
*/
|
|
506
1090
|
type SwitchFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
1091
|
+
/** Additional props to pass to the underlying Switch component */
|
|
507
1092
|
switchProps?: Omit<React$1.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">;
|
|
508
1093
|
};
|
|
1094
|
+
/**
|
|
1095
|
+
* A switch/toggle field component that integrates React Hook Form with HeroUI Switch.
|
|
1096
|
+
*
|
|
1097
|
+
* This component provides a type-safe switch field with validation support,
|
|
1098
|
+
* error handling, and accessibility features. The field value is a boolean.
|
|
1099
|
+
*
|
|
1100
|
+
* @template TFieldValues - The form data type
|
|
1101
|
+
*
|
|
1102
|
+
* @param props - The switch field props
|
|
1103
|
+
* @returns The rendered switch field component
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```tsx
|
|
1107
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
1108
|
+
* import { z } from "zod";
|
|
1109
|
+
*
|
|
1110
|
+
* const schema = z.object({
|
|
1111
|
+
* notifications: z.boolean(),
|
|
1112
|
+
* darkMode: z.boolean().default(false),
|
|
1113
|
+
* });
|
|
1114
|
+
*
|
|
1115
|
+
* function MyForm() {
|
|
1116
|
+
* return (
|
|
1117
|
+
* <ZodForm
|
|
1118
|
+
* config={{
|
|
1119
|
+
* schema,
|
|
1120
|
+
* fields: [
|
|
1121
|
+
* FormFieldHelpers.switch("notifications", "Enable notifications"),
|
|
1122
|
+
* FormFieldHelpers.switch("darkMode", "Dark mode"),
|
|
1123
|
+
* ],
|
|
1124
|
+
* }}
|
|
1125
|
+
* onSubmit={(data) => console.log(data)}
|
|
1126
|
+
* />
|
|
1127
|
+
* );
|
|
1128
|
+
* }
|
|
1129
|
+
* ```
|
|
1130
|
+
*
|
|
1131
|
+
* @example
|
|
1132
|
+
* ```tsx
|
|
1133
|
+
* // With custom styling
|
|
1134
|
+
* <SwitchField
|
|
1135
|
+
* control={form.control}
|
|
1136
|
+
* name="notifications"
|
|
1137
|
+
* label="Enable notifications"
|
|
1138
|
+
* switchProps={{
|
|
1139
|
+
* color: "success",
|
|
1140
|
+
* size: "lg",
|
|
1141
|
+
* }}
|
|
1142
|
+
* />
|
|
1143
|
+
* ```
|
|
1144
|
+
*/
|
|
509
1145
|
declare function SwitchField<TFieldValues extends FieldValues>(props: SwitchFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
510
1146
|
|
|
1147
|
+
/**
|
|
1148
|
+
* Props for the TextareaField component.
|
|
1149
|
+
*
|
|
1150
|
+
* @template TFieldValues - The form data type
|
|
1151
|
+
*
|
|
1152
|
+
* @example
|
|
1153
|
+
* ```tsx
|
|
1154
|
+
* import { TextareaField } from "@rachelallyson/hero-hook-form";
|
|
1155
|
+
* import { useForm } from "react-hook-form";
|
|
1156
|
+
*
|
|
1157
|
+
* const form = useForm({
|
|
1158
|
+
* defaultValues: { message: "" },
|
|
1159
|
+
* });
|
|
1160
|
+
*
|
|
1161
|
+
* <TextareaField
|
|
1162
|
+
* control={form.control}
|
|
1163
|
+
* name="message"
|
|
1164
|
+
* label="Message"
|
|
1165
|
+
* description="Enter your message here"
|
|
1166
|
+
* placeholder="Type your message..."
|
|
1167
|
+
* />
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
511
1170
|
type TextareaFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
1171
|
+
/** Additional props to pass to the underlying Textarea component */
|
|
512
1172
|
textareaProps?: Omit<React$1.ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
513
1173
|
};
|
|
1174
|
+
/**
|
|
1175
|
+
* A textarea field component that integrates React Hook Form with HeroUI Textarea.
|
|
1176
|
+
*
|
|
1177
|
+
* This component provides a type-safe textarea field with validation support,
|
|
1178
|
+
* error handling, and accessibility features. Use this for multi-line text input.
|
|
1179
|
+
*
|
|
1180
|
+
* @template TFieldValues - The form data type
|
|
1181
|
+
*
|
|
1182
|
+
* @param props - The textarea field props
|
|
1183
|
+
* @returns The rendered textarea field component
|
|
1184
|
+
*
|
|
1185
|
+
* @example
|
|
1186
|
+
* ```tsx
|
|
1187
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
1188
|
+
* import { z } from "zod";
|
|
1189
|
+
*
|
|
1190
|
+
* const schema = z.object({
|
|
1191
|
+
* message: z.string().min(10, "Message must be at least 10 characters"),
|
|
1192
|
+
* feedback: z.string().max(500, "Feedback must be less than 500 characters"),
|
|
1193
|
+
* });
|
|
1194
|
+
*
|
|
1195
|
+
* function MyForm() {
|
|
1196
|
+
* return (
|
|
1197
|
+
* <ZodForm
|
|
1198
|
+
* config={{
|
|
1199
|
+
* schema,
|
|
1200
|
+
* fields: [
|
|
1201
|
+
* FormFieldHelpers.textarea("message", "Message", "Enter your message"),
|
|
1202
|
+
* FormFieldHelpers.textarea("feedback", "Feedback"),
|
|
1203
|
+
* ],
|
|
1204
|
+
* }}
|
|
1205
|
+
* onSubmit={(data) => console.log(data)}
|
|
1206
|
+
* />
|
|
1207
|
+
* );
|
|
1208
|
+
* }
|
|
1209
|
+
* ```
|
|
1210
|
+
*
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```tsx
|
|
1213
|
+
* // With custom styling and min/max rows
|
|
1214
|
+
* <TextareaField
|
|
1215
|
+
* control={form.control}
|
|
1216
|
+
* name="message"
|
|
1217
|
+
* label="Message"
|
|
1218
|
+
* textareaProps={{
|
|
1219
|
+
* minRows: 3,
|
|
1220
|
+
* maxRows: 10,
|
|
1221
|
+
* variant: "bordered",
|
|
1222
|
+
* }}
|
|
1223
|
+
* />
|
|
1224
|
+
* ```
|
|
1225
|
+
*/
|
|
514
1226
|
declare function TextareaField<TFieldValues extends FieldValues>(props: TextareaFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
515
1227
|
|
|
516
1228
|
/**
|
|
@@ -1111,14 +1823,6 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1111
1823
|
submitButtonText?: string;
|
|
1112
1824
|
subtitle?: string;
|
|
1113
1825
|
title?: string;
|
|
1114
|
-
render?: (formState: {
|
|
1115
|
-
form: UseFormReturn<T>;
|
|
1116
|
-
isSubmitting: boolean;
|
|
1117
|
-
isSubmitted: boolean;
|
|
1118
|
-
isSuccess: boolean;
|
|
1119
|
-
errors: FieldErrors<T>;
|
|
1120
|
-
values: T;
|
|
1121
|
-
}) => React$1.ReactNode;
|
|
1122
1826
|
}
|
|
1123
1827
|
/**
|
|
1124
1828
|
* ZodForm component for building type-safe forms with Zod validation.
|
|
@@ -1144,7 +1848,6 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1144
1848
|
* @param {string} [props.resetButtonText="Reset"] - Text for the reset button
|
|
1145
1849
|
* @param {(error: FormValidationError) => void} [props.onError] - Error callback for validation errors
|
|
1146
1850
|
* @param {(data: T) => void} [props.onSuccess] - Success callback called after successful submission
|
|
1147
|
-
* @param {(formState: {...}) => React.ReactNode} [props.render] - Custom render function for advanced use cases
|
|
1148
1851
|
*
|
|
1149
1852
|
* @returns {JSX.Element} The rendered form component with validation and error handling
|
|
1150
1853
|
*
|
|
@@ -1194,28 +1897,12 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1194
1897
|
* />
|
|
1195
1898
|
* ```
|
|
1196
1899
|
*
|
|
1197
|
-
* @example
|
|
1198
|
-
* Custom render function for advanced control:
|
|
1199
|
-
* ```tsx
|
|
1200
|
-
* <ZodForm
|
|
1201
|
-
* config={{ schema, fields }}
|
|
1202
|
-
* onSubmit={handleSubmit}
|
|
1203
|
-
* render={({ form, isSubmitting, errors, values }) => (
|
|
1204
|
-
* <div>
|
|
1205
|
-
* <button disabled={isSubmitting}>
|
|
1206
|
-
* {isSubmitting ? "Submitting..." : "Submit"}
|
|
1207
|
-
* </button>
|
|
1208
|
-
* </div>
|
|
1209
|
-
* )}
|
|
1210
|
-
* />
|
|
1211
|
-
* ```
|
|
1212
|
-
*
|
|
1213
1900
|
* @see {@link Form} for the base form component without Zod
|
|
1214
1901
|
* @see {@link FormFieldHelpers} for field creation helpers
|
|
1215
1902
|
* @see {@link createBasicFormBuilder} for builder pattern alternative
|
|
1216
1903
|
* @category Components
|
|
1217
1904
|
*/
|
|
1218
|
-
declare function ZodForm<T extends FieldValues>({ className, columns, config, layout, onError, onSubmit, onSuccess,
|
|
1905
|
+
declare function ZodForm<T extends FieldValues>({ className, columns, config, layout, onError, onSubmit, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ZodFormProps<T>): React$1.JSX.Element;
|
|
1219
1906
|
|
|
1220
1907
|
/**
|
|
1221
1908
|
* Hook for using Zod validation with React Hook Form
|
|
@@ -1381,14 +2068,14 @@ declare const FormFieldHelpers: {
|
|
|
1381
2068
|
* })
|
|
1382
2069
|
* ```
|
|
1383
2070
|
*/
|
|
1384
|
-
content: <T extends FieldValues>(title?: string | null, description?: string | null, options?: {
|
|
2071
|
+
content: <T extends FieldValues = FieldValues>(title?: string | null, description?: string | null, options?: {
|
|
1385
2072
|
render?: (field: {
|
|
1386
|
-
form:
|
|
1387
|
-
errors:
|
|
2073
|
+
form: UseFormReturn<T>;
|
|
2074
|
+
errors: FieldErrors<T>;
|
|
1388
2075
|
isSubmitting: boolean;
|
|
1389
2076
|
}) => React$1.ReactNode;
|
|
1390
2077
|
className?: string;
|
|
1391
|
-
name?:
|
|
2078
|
+
name?: string;
|
|
1392
2079
|
}) => ZodFormFieldConfig<T>;
|
|
1393
2080
|
/**
|
|
1394
2081
|
* Create a date field
|
|
@@ -2025,11 +2712,68 @@ declare function useTypeInferredForm<T extends FieldValues>(formConfig: {
|
|
|
2025
2712
|
fields: ZodFormFieldConfig<T>[];
|
|
2026
2713
|
}, options?: UseInferredFormOptions<T>): UseFormReturn<T>;
|
|
2027
2714
|
|
|
2715
|
+
/**
|
|
2716
|
+
* Props for the ConditionalField component.
|
|
2717
|
+
*
|
|
2718
|
+
* @template TFieldValues - The form data type
|
|
2719
|
+
*/
|
|
2028
2720
|
interface ConditionalFieldProps<TFieldValues extends FieldValues> {
|
|
2029
2721
|
config: ConditionalFieldConfig<TFieldValues>;
|
|
2030
2722
|
control: Control<TFieldValues>;
|
|
2031
2723
|
className?: string;
|
|
2032
2724
|
}
|
|
2725
|
+
/**
|
|
2726
|
+
* Conditional field component that shows/hides fields based on form values.
|
|
2727
|
+
*
|
|
2728
|
+
* @description
|
|
2729
|
+
* Renders a field only when a condition function returns true based on
|
|
2730
|
+
* current form values. Useful for creating dynamic forms that adapt to
|
|
2731
|
+
* user input. The field is completely removed from the DOM when hidden.
|
|
2732
|
+
*
|
|
2733
|
+
* @template TFieldValues - The form data type
|
|
2734
|
+
*
|
|
2735
|
+
* @param {ConditionalFieldProps<TFieldValues>} props - Component props
|
|
2736
|
+
* @param {ConditionalFieldConfig<TFieldValues>} props.config - Conditional field configuration
|
|
2737
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
2738
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2739
|
+
*
|
|
2740
|
+
* @returns {JSX.Element|null} The rendered field or null if condition is not met
|
|
2741
|
+
*
|
|
2742
|
+
* @example
|
|
2743
|
+
* ```tsx
|
|
2744
|
+
* import { ConditionalField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2745
|
+
*
|
|
2746
|
+
* const fields = [
|
|
2747
|
+
* FormFieldHelpers.checkbox("hasPhone", "I have a phone number"),
|
|
2748
|
+
* ConditionalField({
|
|
2749
|
+
* config: {
|
|
2750
|
+
* name: "phone",
|
|
2751
|
+
* condition: (values) => values.hasPhone === true,
|
|
2752
|
+
* field: FormFieldHelpers.input("phone", "Phone Number", "tel"),
|
|
2753
|
+
* },
|
|
2754
|
+
* control: form.control,
|
|
2755
|
+
* }),
|
|
2756
|
+
* ];
|
|
2757
|
+
* ```
|
|
2758
|
+
*
|
|
2759
|
+
* @example
|
|
2760
|
+
* Multiple conditions:
|
|
2761
|
+
* ```tsx
|
|
2762
|
+
* ConditionalField({
|
|
2763
|
+
* config: {
|
|
2764
|
+
* name: "businessDetails",
|
|
2765
|
+
* condition: (values) =>
|
|
2766
|
+
* values.userType === "business" && values.isRegistered === true,
|
|
2767
|
+
* field: FormFieldHelpers.input("taxId", "Tax ID"),
|
|
2768
|
+
* },
|
|
2769
|
+
* control: form.control,
|
|
2770
|
+
* }),
|
|
2771
|
+
* ```
|
|
2772
|
+
*
|
|
2773
|
+
* @see {@link DynamicSectionField} for grouping multiple conditional fields
|
|
2774
|
+
* @see {@link FieldArrayField} for repeating fields
|
|
2775
|
+
* @category Fields
|
|
2776
|
+
*/
|
|
2033
2777
|
declare function ConditionalField<TFieldValues extends FieldValues>({ className, config, control, }: ConditionalFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2034
2778
|
|
|
2035
2779
|
interface ContentFieldProps<TFieldValues extends FieldValues> {
|
|
@@ -2039,17 +2783,155 @@ interface ContentFieldProps<TFieldValues extends FieldValues> {
|
|
|
2039
2783
|
}
|
|
2040
2784
|
declare function ContentField<TFieldValues extends FieldValues>({ config, form, submissionState, }: ContentFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
2041
2785
|
|
|
2786
|
+
/**
|
|
2787
|
+
* Props for the FieldArrayField component.
|
|
2788
|
+
*
|
|
2789
|
+
* @template TFieldValues - The form data type
|
|
2790
|
+
*/
|
|
2042
2791
|
interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
|
|
2043
2792
|
config: FieldArrayConfig<TFieldValues>;
|
|
2044
2793
|
className?: string;
|
|
2045
2794
|
}
|
|
2795
|
+
/**
|
|
2796
|
+
* Field array component for dynamic repeating field groups.
|
|
2797
|
+
*
|
|
2798
|
+
* @description
|
|
2799
|
+
* Allows users to add and remove multiple instances of a field group.
|
|
2800
|
+
* Useful for forms with repeating data like addresses, items, or contacts.
|
|
2801
|
+
* Automatically manages field array state and provides add/remove buttons.
|
|
2802
|
+
*
|
|
2803
|
+
* @template TFieldValues - The form data type
|
|
2804
|
+
*
|
|
2805
|
+
* @param {FieldArrayFieldProps<TFieldValues>} props - Component props
|
|
2806
|
+
* @param {FieldArrayConfig<TFieldValues>} props.config - Field array configuration
|
|
2807
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2808
|
+
*
|
|
2809
|
+
* @returns {JSX.Element} The rendered field array with add/remove controls
|
|
2810
|
+
*
|
|
2811
|
+
* @example
|
|
2812
|
+
* ```tsx
|
|
2813
|
+
* import { FieldArrayField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2814
|
+
*
|
|
2815
|
+
* const fields = [
|
|
2816
|
+
* FormFieldHelpers.input("name", "Name"),
|
|
2817
|
+
* FieldArrayField({
|
|
2818
|
+
* config: {
|
|
2819
|
+
* name: "addresses",
|
|
2820
|
+
* label: "Address",
|
|
2821
|
+
* fields: [
|
|
2822
|
+
* FormFieldHelpers.input("street", "Street Address"),
|
|
2823
|
+
* FormFieldHelpers.input("city", "City"),
|
|
2824
|
+
* FormFieldHelpers.input("zipCode", "ZIP Code"),
|
|
2825
|
+
* ],
|
|
2826
|
+
* min: 1,
|
|
2827
|
+
* max: 5,
|
|
2828
|
+
* addButtonText: "Add Address",
|
|
2829
|
+
* removeButtonText: "Remove Address",
|
|
2830
|
+
* },
|
|
2831
|
+
* }),
|
|
2832
|
+
* ];
|
|
2833
|
+
* ```
|
|
2834
|
+
*
|
|
2835
|
+
* @example
|
|
2836
|
+
* With validation:
|
|
2837
|
+
* ```tsx
|
|
2838
|
+
* const schema = z.object({
|
|
2839
|
+
* addresses: z.array(z.object({
|
|
2840
|
+
* street: z.string().min(1, "Street is required"),
|
|
2841
|
+
* city: z.string().min(1, "City is required"),
|
|
2842
|
+
* })).min(1, "At least one address is required"),
|
|
2843
|
+
* });
|
|
2844
|
+
* ```
|
|
2845
|
+
*
|
|
2846
|
+
* @see {@link ConditionalField} for conditional single fields
|
|
2847
|
+
* @see {@link DynamicSectionField} for conditional field groups
|
|
2848
|
+
* @category Fields
|
|
2849
|
+
*/
|
|
2046
2850
|
declare function FieldArrayField<TFieldValues extends FieldValues>({ className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2047
2851
|
|
|
2852
|
+
/**
|
|
2853
|
+
* Props for the DynamicSectionField component.
|
|
2854
|
+
*
|
|
2855
|
+
* @template TFieldValues - The form data type
|
|
2856
|
+
*/
|
|
2048
2857
|
interface DynamicSectionFieldProps<TFieldValues extends FieldValues> {
|
|
2049
2858
|
config: DynamicSectionConfig<TFieldValues>;
|
|
2050
2859
|
control: Control<TFieldValues>;
|
|
2051
2860
|
className?: string;
|
|
2052
2861
|
}
|
|
2862
|
+
/**
|
|
2863
|
+
* Dynamic section component that shows/hides groups of fields based on form values.
|
|
2864
|
+
*
|
|
2865
|
+
* @description
|
|
2866
|
+
* Similar to ConditionalField but for groups of fields. Renders a section
|
|
2867
|
+
* with title, description, and multiple fields when a condition is met.
|
|
2868
|
+
* Useful for creating multi-step-like experiences or conditional form sections.
|
|
2869
|
+
*
|
|
2870
|
+
* @template TFieldValues - The form data type
|
|
2871
|
+
*
|
|
2872
|
+
* @param {DynamicSectionFieldProps<TFieldValues>} props - Component props
|
|
2873
|
+
* @param {DynamicSectionConfig<TFieldValues>} props.config - Dynamic section configuration
|
|
2874
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
2875
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2876
|
+
*
|
|
2877
|
+
* @returns {JSX.Element|null} The rendered section or null if condition is not met
|
|
2878
|
+
*
|
|
2879
|
+
* @example
|
|
2880
|
+
* ```tsx
|
|
2881
|
+
* import { DynamicSectionField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2882
|
+
*
|
|
2883
|
+
* const fields = [
|
|
2884
|
+
* FormFieldHelpers.checkbox("hasEmergencyContact", "Has Emergency Contact"),
|
|
2885
|
+
* DynamicSectionField({
|
|
2886
|
+
* config: {
|
|
2887
|
+
* name: "emergencyContact",
|
|
2888
|
+
* title: "Emergency Contact Information",
|
|
2889
|
+
* description: "Please provide emergency contact details",
|
|
2890
|
+
* condition: (values) => values.hasEmergencyContact === true,
|
|
2891
|
+
* fields: [
|
|
2892
|
+
* FormFieldHelpers.input("name", "Contact Name"),
|
|
2893
|
+
* FormFieldHelpers.input("relationship", "Relationship"),
|
|
2894
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel"),
|
|
2895
|
+
* FormFieldHelpers.input("email", "Email", "email"),
|
|
2896
|
+
* ],
|
|
2897
|
+
* },
|
|
2898
|
+
* control: form.control,
|
|
2899
|
+
* }),
|
|
2900
|
+
* ];
|
|
2901
|
+
* ```
|
|
2902
|
+
*
|
|
2903
|
+
* @example
|
|
2904
|
+
* Nested dynamic sections:
|
|
2905
|
+
* ```tsx
|
|
2906
|
+
* DynamicSectionField({
|
|
2907
|
+
* config: {
|
|
2908
|
+
* name: "businessInfo",
|
|
2909
|
+
* title: "Business Information",
|
|
2910
|
+
* condition: (values) => values.accountType === "business",
|
|
2911
|
+
* fields: [
|
|
2912
|
+
* FormFieldHelpers.input("businessName", "Business Name"),
|
|
2913
|
+
* DynamicSectionField({
|
|
2914
|
+
* config: {
|
|
2915
|
+
* name: "billingAddress",
|
|
2916
|
+
* title: "Billing Address",
|
|
2917
|
+
* condition: (values) => values.businessName && values.taxId,
|
|
2918
|
+
* fields: [
|
|
2919
|
+
* FormFieldHelpers.input("street", "Street Address"),
|
|
2920
|
+
* FormFieldHelpers.input("city", "City"),
|
|
2921
|
+
* ],
|
|
2922
|
+
* },
|
|
2923
|
+
* control: form.control,
|
|
2924
|
+
* }),
|
|
2925
|
+
* ],
|
|
2926
|
+
* },
|
|
2927
|
+
* control: form.control,
|
|
2928
|
+
* }),
|
|
2929
|
+
* ```
|
|
2930
|
+
*
|
|
2931
|
+
* @see {@link ConditionalField} for single conditional fields
|
|
2932
|
+
* @see {@link FieldArrayField} for repeating fields
|
|
2933
|
+
* @category Fields
|
|
2934
|
+
*/
|
|
2053
2935
|
declare function DynamicSectionField<TFieldValues extends FieldValues>({ className, config, control, }: DynamicSectionFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2054
2936
|
|
|
2055
2937
|
interface FormStatusProps<T extends Record<string, any>> {
|