@rachelallyson/hero-hook-form 2.2.1 → 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 +25 -0
- package/dist/index.d.ts +675 -41
- package/dist/index.js +10 -19
- package/dist/react/index.d.ts +675 -41
- 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 {
|
|
@@ -517,45 +748,473 @@ type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldVa
|
|
|
517
748
|
*/
|
|
518
749
|
declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
|
|
519
750
|
|
|
751
|
+
/**
|
|
752
|
+
* Configuration for a radio option.
|
|
753
|
+
*
|
|
754
|
+
* @template TValue - The value type for the option
|
|
755
|
+
*/
|
|
520
756
|
interface RadioOption<TValue extends string | number> {
|
|
757
|
+
/** Display label for the option */
|
|
521
758
|
label: string;
|
|
759
|
+
/** Value of the option */
|
|
522
760
|
value: TValue;
|
|
761
|
+
/** Optional description text */
|
|
523
762
|
description?: string;
|
|
763
|
+
/** Whether the option is disabled */
|
|
524
764
|
disabled?: boolean;
|
|
525
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
|
+
*/
|
|
526
795
|
type RadioGroupFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
796
|
+
/** Array of radio options */
|
|
527
797
|
options: readonly RadioOption<TValue>[];
|
|
798
|
+
/** Additional props to pass to the underlying RadioGroup component */
|
|
528
799
|
radioGroupProps?: Omit<React$1.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">;
|
|
529
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
|
+
*/
|
|
530
860
|
declare function RadioGroupField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: RadioGroupFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
531
861
|
|
|
862
|
+
/**
|
|
863
|
+
* Configuration for a select option.
|
|
864
|
+
*
|
|
865
|
+
* @template TValue - The value type for the option
|
|
866
|
+
*/
|
|
532
867
|
interface SelectOption<TValue extends string | number> {
|
|
868
|
+
/** Display label for the option */
|
|
533
869
|
label: string;
|
|
870
|
+
/** Value of the option */
|
|
534
871
|
value: TValue;
|
|
872
|
+
/** Optional description text */
|
|
535
873
|
description?: string;
|
|
874
|
+
/** Whether the option is disabled */
|
|
536
875
|
disabled?: boolean;
|
|
537
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
|
+
*/
|
|
538
907
|
type SelectFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
908
|
+
/** Array of select options */
|
|
539
909
|
options: readonly SelectOption<TValue>[];
|
|
910
|
+
/** Placeholder text when no option is selected */
|
|
540
911
|
placeholder?: string;
|
|
912
|
+
/** Additional props to pass to the underlying Select component */
|
|
541
913
|
selectProps?: Omit<React$1.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
542
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
|
+
*/
|
|
543
971
|
declare function SelectField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: SelectFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
544
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
|
+
*/
|
|
545
995
|
type SliderFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, number> & WithControl<TFieldValues> & {
|
|
996
|
+
/** Additional props to pass to the underlying Slider component */
|
|
546
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 */
|
|
547
999
|
transform?: (value: number) => number;
|
|
548
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
|
+
*/
|
|
549
1058
|
declare function SliderField<TFieldValues extends FieldValues>(props: SliderFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
550
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
|
+
*/
|
|
551
1082
|
type SwitchFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
1083
|
+
/** Additional props to pass to the underlying Switch component */
|
|
552
1084
|
switchProps?: Omit<React$1.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">;
|
|
553
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
|
+
*/
|
|
554
1137
|
declare function SwitchField<TFieldValues extends FieldValues>(props: SwitchFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
555
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
|
+
*/
|
|
556
1162
|
type TextareaFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
1163
|
+
/** Additional props to pass to the underlying Textarea component */
|
|
557
1164
|
textareaProps?: Omit<React$1.ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
558
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
|
+
*/
|
|
559
1218
|
declare function TextareaField<TFieldValues extends FieldValues>(props: TextareaFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
560
1219
|
|
|
561
1220
|
/**
|
|
@@ -1156,14 +1815,6 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1156
1815
|
submitButtonText?: string;
|
|
1157
1816
|
subtitle?: string;
|
|
1158
1817
|
title?: string;
|
|
1159
|
-
render?: (formState: {
|
|
1160
|
-
form: UseFormReturn<T>;
|
|
1161
|
-
isSubmitting: boolean;
|
|
1162
|
-
isSubmitted: boolean;
|
|
1163
|
-
isSuccess: boolean;
|
|
1164
|
-
errors: FieldErrors<T>;
|
|
1165
|
-
values: T;
|
|
1166
|
-
}) => React$1.ReactNode;
|
|
1167
1818
|
}
|
|
1168
1819
|
/**
|
|
1169
1820
|
* ZodForm component for building type-safe forms with Zod validation.
|
|
@@ -1189,7 +1840,6 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1189
1840
|
* @param {string} [props.resetButtonText="Reset"] - Text for the reset button
|
|
1190
1841
|
* @param {(error: FormValidationError) => void} [props.onError] - Error callback for validation errors
|
|
1191
1842
|
* @param {(data: T) => void} [props.onSuccess] - Success callback called after successful submission
|
|
1192
|
-
* @param {(formState: {...}) => React.ReactNode} [props.render] - Custom render function for advanced use cases
|
|
1193
1843
|
*
|
|
1194
1844
|
* @returns {JSX.Element} The rendered form component with validation and error handling
|
|
1195
1845
|
*
|
|
@@ -1239,28 +1889,12 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1239
1889
|
* />
|
|
1240
1890
|
* ```
|
|
1241
1891
|
*
|
|
1242
|
-
* @example
|
|
1243
|
-
* Custom render function for advanced control:
|
|
1244
|
-
* ```tsx
|
|
1245
|
-
* <ZodForm
|
|
1246
|
-
* config={{ schema, fields }}
|
|
1247
|
-
* onSubmit={handleSubmit}
|
|
1248
|
-
* render={({ form, isSubmitting, errors, values }) => (
|
|
1249
|
-
* <div>
|
|
1250
|
-
* <button disabled={isSubmitting}>
|
|
1251
|
-
* {isSubmitting ? "Submitting..." : "Submit"}
|
|
1252
|
-
* </button>
|
|
1253
|
-
* </div>
|
|
1254
|
-
* )}
|
|
1255
|
-
* />
|
|
1256
|
-
* ```
|
|
1257
|
-
*
|
|
1258
1892
|
* @see {@link Form} for the base form component without Zod
|
|
1259
1893
|
* @see {@link FormFieldHelpers} for field creation helpers
|
|
1260
1894
|
* @see {@link createBasicFormBuilder} for builder pattern alternative
|
|
1261
1895
|
* @category Components
|
|
1262
1896
|
*/
|
|
1263
|
-
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;
|
|
1264
1898
|
|
|
1265
1899
|
/**
|
|
1266
1900
|
* Hook for using Zod validation with React Hook Form
|
|
@@ -1426,15 +2060,15 @@ declare const FormFieldHelpers: {
|
|
|
1426
2060
|
* })
|
|
1427
2061
|
* ```
|
|
1428
2062
|
*/
|
|
1429
|
-
content: <T extends FieldValues>(title?: string | null, description?: string | null, options?: {
|
|
2063
|
+
content: <T extends FieldValues = FieldValues>(title?: string | null, description?: string | null, options?: {
|
|
1430
2064
|
render?: (field: {
|
|
1431
|
-
form:
|
|
1432
|
-
errors:
|
|
2065
|
+
form: UseFormReturn<T>;
|
|
2066
|
+
errors: FieldErrors<T>;
|
|
1433
2067
|
isSubmitting: boolean;
|
|
1434
2068
|
}) => React$1.ReactNode;
|
|
1435
2069
|
className?: string;
|
|
1436
|
-
name?:
|
|
1437
|
-
}) =>
|
|
2070
|
+
name?: string;
|
|
2071
|
+
}) => ZodFormFieldConfig<T>;
|
|
1438
2072
|
/**
|
|
1439
2073
|
* Create a date field
|
|
1440
2074
|
*/
|