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