@rachelallyson/hero-hook-form 2.2.1 → 2.4.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 +54 -0
- package/dist/index.d.ts +827 -45
- package/dist/index.js +310 -206
- package/dist/react/index.d.ts +827 -46
- package/dist/react/index.js +316 -211
- package/package.json +7 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as zod from 'zod';
|
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
import * as _internationalized_date from '@internationalized/date';
|
|
9
9
|
import { CalendarDate } from '@internationalized/date';
|
|
10
|
+
import { Autocomplete } from '@heroui/autocomplete';
|
|
10
11
|
import { Checkbox } from '@heroui/checkbox';
|
|
11
12
|
import { Input, Textarea } from '@heroui/input';
|
|
12
13
|
import { RadioGroup } from '@heroui/radio';
|
|
@@ -46,11 +47,12 @@ interface BaseFormFieldConfig<TFieldValues extends FieldValues> {
|
|
|
46
47
|
ariaDescribedBy?: string;
|
|
47
48
|
}
|
|
48
49
|
interface StringFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
49
|
-
type: "input" | "textarea" | "select";
|
|
50
|
+
type: "input" | "textarea" | "select" | "autocomplete";
|
|
50
51
|
defaultValue?: string;
|
|
51
52
|
inputProps?: Omit<ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
52
53
|
textareaProps?: Omit<ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
53
54
|
selectProps?: Omit<ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
55
|
+
autocompleteProps?: Omit<ComponentProps<typeof Autocomplete>, "selectedKey" | "onSelectionChange" | "inputValue" | "onInputChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "children" | "items">;
|
|
54
56
|
options?: {
|
|
55
57
|
label: string;
|
|
56
58
|
value: string | number;
|
|
@@ -123,9 +125,9 @@ interface DynamicSectionConfig<TFieldValues extends FieldValues> extends BaseFor
|
|
|
123
125
|
condition: (formData: Partial<TFieldValues>) => boolean;
|
|
124
126
|
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
125
127
|
}
|
|
126
|
-
interface ContentFieldConfig<TFieldValues extends FieldValues> {
|
|
128
|
+
interface ContentFieldConfig<TFieldValues extends FieldValues = FieldValues> {
|
|
127
129
|
type: "content";
|
|
128
|
-
name?:
|
|
130
|
+
name?: string;
|
|
129
131
|
title?: string;
|
|
130
132
|
description?: string;
|
|
131
133
|
render?: (field: {
|
|
@@ -155,14 +157,6 @@ interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<T
|
|
|
155
157
|
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
156
158
|
onError?: (errors: FieldErrors<TFieldValues>) => void;
|
|
157
159
|
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
160
|
}
|
|
167
161
|
interface FormValidationError {
|
|
168
162
|
message: string;
|
|
@@ -436,23 +430,383 @@ interface ServerActionFormProps<T extends FieldValues> {
|
|
|
436
430
|
*/
|
|
437
431
|
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
432
|
|
|
433
|
+
/**
|
|
434
|
+
* Configuration for an autocomplete option.
|
|
435
|
+
*
|
|
436
|
+
* @template TValue - The value type for the option
|
|
437
|
+
*/
|
|
438
|
+
interface AutocompleteOption<TValue extends string | number> {
|
|
439
|
+
/** Display label for the option */
|
|
440
|
+
label: string;
|
|
441
|
+
/** Value of the option */
|
|
442
|
+
value: TValue;
|
|
443
|
+
/** Optional description text */
|
|
444
|
+
description?: string;
|
|
445
|
+
/** Whether the option is disabled */
|
|
446
|
+
disabled?: boolean;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Props for the AutocompleteField component.
|
|
450
|
+
*
|
|
451
|
+
* @template TFieldValues - The form data type
|
|
452
|
+
* @template TValue - The value type for the autocomplete field (string or number)
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```tsx
|
|
456
|
+
* import { AutocompleteField } from "@rachelallyson/hero-hook-form";
|
|
457
|
+
* import { useForm } from "react-hook-form";
|
|
458
|
+
*
|
|
459
|
+
* const form = useForm({
|
|
460
|
+
* defaultValues: { country: "" },
|
|
461
|
+
* });
|
|
462
|
+
*
|
|
463
|
+
* const options = [
|
|
464
|
+
* { label: "United States", value: "us" },
|
|
465
|
+
* { label: "Canada", value: "ca" },
|
|
466
|
+
* { label: "Mexico", value: "mx" },
|
|
467
|
+
* ];
|
|
468
|
+
*
|
|
469
|
+
* <AutocompleteField
|
|
470
|
+
* control={form.control}
|
|
471
|
+
* name="country"
|
|
472
|
+
* label="Country"
|
|
473
|
+
* items={options}
|
|
474
|
+
* placeholder="Search for a country"
|
|
475
|
+
* />
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
type AutocompleteFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
479
|
+
/** Array of autocomplete options (for static lists) */
|
|
480
|
+
items?: readonly AutocompleteOption<TValue>[];
|
|
481
|
+
/** Placeholder text when no option is selected */
|
|
482
|
+
placeholder?: string;
|
|
483
|
+
/** Additional props to pass to the underlying Autocomplete component */
|
|
484
|
+
autocompleteProps?: Omit<React$1.ComponentProps<typeof Autocomplete>, "selectedKey" | "onSelectionChange" | "inputValue" | "onInputChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "children" | "items" | "defaultItems">;
|
|
485
|
+
/** Custom render function for items (for async loading) */
|
|
486
|
+
children?: (item: AutocompleteOption<TValue>) => React$1.JSX.Element;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* An autocomplete field component that integrates React Hook Form with HeroUI Autocomplete.
|
|
490
|
+
*
|
|
491
|
+
* This component provides a type-safe autocomplete field with validation support,
|
|
492
|
+
* error handling, and accessibility features. It supports both static option lists
|
|
493
|
+
* and async loading via the items prop or children render function.
|
|
494
|
+
*
|
|
495
|
+
* @template TFieldValues - The form data type
|
|
496
|
+
* @template TValue - The value type for the autocomplete field (string or number)
|
|
497
|
+
*
|
|
498
|
+
* @param props - The autocomplete field props
|
|
499
|
+
* @returns The rendered autocomplete field component
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```tsx
|
|
503
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
504
|
+
* import { z } from "zod";
|
|
505
|
+
*
|
|
506
|
+
* const schema = z.object({
|
|
507
|
+
* country: z.string().min(1, "Please select a country"),
|
|
508
|
+
* });
|
|
509
|
+
*
|
|
510
|
+
* const options = [
|
|
511
|
+
* { label: "United States", value: "us" },
|
|
512
|
+
* { label: "Canada", value: "ca" },
|
|
513
|
+
* ];
|
|
514
|
+
*
|
|
515
|
+
* function MyForm() {
|
|
516
|
+
* return (
|
|
517
|
+
* <ZodForm
|
|
518
|
+
* config={{
|
|
519
|
+
* schema,
|
|
520
|
+
* fields: [
|
|
521
|
+
* FormFieldHelpers.autocomplete("country", "Country", options, "Search for a country"),
|
|
522
|
+
* ],
|
|
523
|
+
* }}
|
|
524
|
+
* onSubmit={(data) => console.log(data)}
|
|
525
|
+
* />
|
|
526
|
+
* );
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```tsx
|
|
532
|
+
* // With async loading
|
|
533
|
+
* <AutocompleteField
|
|
534
|
+
* control={form.control}
|
|
535
|
+
* name="country"
|
|
536
|
+
* label="Country"
|
|
537
|
+
* placeholder="Search for a country"
|
|
538
|
+
* autocompleteProps={{
|
|
539
|
+
* allowsCustomValue: true,
|
|
540
|
+
* onInputChange={(value) => {
|
|
541
|
+
* // Load options asynchronously based on input
|
|
542
|
+
* loadOptions(value);
|
|
543
|
+
* }},
|
|
544
|
+
* }}
|
|
545
|
+
* >
|
|
546
|
+
* {(item) => (
|
|
547
|
+
* <AutocompleteItem key={item.value}>{item.label}</AutocompleteItem>
|
|
548
|
+
* )}
|
|
549
|
+
* </AutocompleteField>
|
|
550
|
+
* ```
|
|
551
|
+
*/
|
|
552
|
+
declare function AutocompleteField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: AutocompleteFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Props for the CheckboxField component.
|
|
556
|
+
*
|
|
557
|
+
* @template TFieldValues - The form data type
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```tsx
|
|
561
|
+
* import { CheckboxField } from "@rachelallyson/hero-hook-form";
|
|
562
|
+
* import { useForm } from "react-hook-form";
|
|
563
|
+
*
|
|
564
|
+
* const form = useForm({
|
|
565
|
+
* defaultValues: { newsletter: false },
|
|
566
|
+
* });
|
|
567
|
+
*
|
|
568
|
+
* <CheckboxField
|
|
569
|
+
* control={form.control}
|
|
570
|
+
* name="newsletter"
|
|
571
|
+
* label="Subscribe to newsletter"
|
|
572
|
+
* description="Receive weekly updates"
|
|
573
|
+
* />
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
439
576
|
type CheckboxFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
577
|
+
/** Additional props to pass to the underlying Checkbox component */
|
|
440
578
|
checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
441
579
|
};
|
|
580
|
+
/**
|
|
581
|
+
* A checkbox field component that integrates React Hook Form with HeroUI Checkbox.
|
|
582
|
+
*
|
|
583
|
+
* This component provides a type-safe checkbox field with validation support,
|
|
584
|
+
* error handling, and accessibility features. The field value is a boolean.
|
|
585
|
+
*
|
|
586
|
+
* @template TFieldValues - The form data type
|
|
587
|
+
*
|
|
588
|
+
* @param props - The checkbox field props
|
|
589
|
+
* @returns The rendered checkbox field component
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```tsx
|
|
593
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
594
|
+
* import { z } from "zod";
|
|
595
|
+
*
|
|
596
|
+
* const schema = z.object({
|
|
597
|
+
* terms: z.boolean().refine((val) => val === true, {
|
|
598
|
+
* message: "You must accept the terms",
|
|
599
|
+
* }),
|
|
600
|
+
* newsletter: z.boolean().optional(),
|
|
601
|
+
* });
|
|
602
|
+
*
|
|
603
|
+
* function MyForm() {
|
|
604
|
+
* return (
|
|
605
|
+
* <ZodForm
|
|
606
|
+
* config={{
|
|
607
|
+
* schema,
|
|
608
|
+
* fields: [
|
|
609
|
+
* FormFieldHelpers.checkbox("terms", "I accept the terms and conditions"),
|
|
610
|
+
* FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter"),
|
|
611
|
+
* ],
|
|
612
|
+
* }}
|
|
613
|
+
* onSubmit={(data) => console.log(data)}
|
|
614
|
+
* />
|
|
615
|
+
* );
|
|
616
|
+
* }
|
|
617
|
+
* ```
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```tsx
|
|
621
|
+
* // With custom styling
|
|
622
|
+
* <CheckboxField
|
|
623
|
+
* control={form.control}
|
|
624
|
+
* name="newsletter"
|
|
625
|
+
* label="Subscribe"
|
|
626
|
+
* checkboxProps={{
|
|
627
|
+
* color: "primary",
|
|
628
|
+
* size: "lg",
|
|
629
|
+
* }}
|
|
630
|
+
* />
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
442
633
|
declare function CheckboxField<TFieldValues extends FieldValues>(props: CheckboxFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
443
634
|
|
|
635
|
+
/**
|
|
636
|
+
* Props for the DateField component.
|
|
637
|
+
*
|
|
638
|
+
* @template TFieldValues - The form data type
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```tsx
|
|
642
|
+
* import { DateField } from "@rachelallyson/hero-hook-form";
|
|
643
|
+
* import { useForm } from "react-hook-form";
|
|
644
|
+
* import { CalendarDate } from "@internationalized/date";
|
|
645
|
+
*
|
|
646
|
+
* const form = useForm({
|
|
647
|
+
* defaultValues: { birthDate: null as CalendarDate | null },
|
|
648
|
+
* });
|
|
649
|
+
*
|
|
650
|
+
* <DateField
|
|
651
|
+
* control={form.control}
|
|
652
|
+
* name="birthDate"
|
|
653
|
+
* label="Birth Date"
|
|
654
|
+
* description="Select your date of birth"
|
|
655
|
+
* />
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
444
658
|
type DateFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, CalendarDate | null> & WithControl<TFieldValues> & {
|
|
659
|
+
/** Additional props to pass to the underlying DateInput component */
|
|
445
660
|
dateProps?: Omit<React$1.ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
661
|
+
/** Transform function to modify the date value before it's set */
|
|
446
662
|
transform?: (value: CalendarDate | null) => CalendarDate | null;
|
|
447
663
|
};
|
|
664
|
+
/**
|
|
665
|
+
* A date input field component that integrates React Hook Form with HeroUI DateInput.
|
|
666
|
+
*
|
|
667
|
+
* This component provides a type-safe date field with validation support,
|
|
668
|
+
* error handling, and accessibility features. Uses `@internationalized/date`
|
|
669
|
+
* for date handling.
|
|
670
|
+
*
|
|
671
|
+
* @template TFieldValues - The form data type
|
|
672
|
+
*
|
|
673
|
+
* @param props - The date field props
|
|
674
|
+
* @returns The rendered date field component
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```tsx
|
|
678
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
679
|
+
* import { z } from "zod";
|
|
680
|
+
* import { CalendarDate } from "@internationalized/date";
|
|
681
|
+
*
|
|
682
|
+
* const schema = z.object({
|
|
683
|
+
* birthDate: z.instanceof(CalendarDate).nullable(),
|
|
684
|
+
* eventDate: z.instanceof(CalendarDate),
|
|
685
|
+
* });
|
|
686
|
+
*
|
|
687
|
+
* function MyForm() {
|
|
688
|
+
* return (
|
|
689
|
+
* <ZodForm
|
|
690
|
+
* config={{
|
|
691
|
+
* schema,
|
|
692
|
+
* fields: [
|
|
693
|
+
* FormFieldHelpers.date("birthDate", "Birth Date"),
|
|
694
|
+
* FormFieldHelpers.date("eventDate", "Event Date"),
|
|
695
|
+
* ],
|
|
696
|
+
* }}
|
|
697
|
+
* onSubmit={(data) => console.log(data)}
|
|
698
|
+
* />
|
|
699
|
+
* );
|
|
700
|
+
* }
|
|
701
|
+
* ```
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```tsx
|
|
705
|
+
* // With custom date format and min/max dates
|
|
706
|
+
* <DateField
|
|
707
|
+
* control={form.control}
|
|
708
|
+
* name="eventDate"
|
|
709
|
+
* label="Event Date"
|
|
710
|
+
* dateProps={{
|
|
711
|
+
* minValue: new CalendarDate(2024, 1, 1),
|
|
712
|
+
* maxValue: new CalendarDate(2024, 12, 31),
|
|
713
|
+
* }}
|
|
714
|
+
* />
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
448
717
|
declare function DateField<TFieldValues extends FieldValues>(props: DateFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
449
718
|
|
|
719
|
+
/**
|
|
720
|
+
* Props for the FileField component.
|
|
721
|
+
*
|
|
722
|
+
* @template TFieldValues - The form data type
|
|
723
|
+
*
|
|
724
|
+
* @example
|
|
725
|
+
* ```tsx
|
|
726
|
+
* import { FileField } from "@rachelallyson/hero-hook-form";
|
|
727
|
+
* import { useForm } from "react-hook-form";
|
|
728
|
+
*
|
|
729
|
+
* const form = useForm({
|
|
730
|
+
* defaultValues: { avatar: null as FileList | null },
|
|
731
|
+
* });
|
|
732
|
+
*
|
|
733
|
+
* <FileField
|
|
734
|
+
* control={form.control}
|
|
735
|
+
* name="avatar"
|
|
736
|
+
* label="Upload Avatar"
|
|
737
|
+
* accept="image/*"
|
|
738
|
+
* description="Select an image file"
|
|
739
|
+
* />
|
|
740
|
+
* ```
|
|
741
|
+
*/
|
|
450
742
|
type FileFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, FileList | null> & WithControl<TFieldValues> & {
|
|
743
|
+
/** Additional props to pass to the underlying Input component */
|
|
451
744
|
fileProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "type">;
|
|
745
|
+
/** Transform function to modify the file list before it's set */
|
|
452
746
|
transform?: (value: FileList | null) => FileList | null;
|
|
747
|
+
/** Whether multiple files can be selected */
|
|
453
748
|
multiple?: boolean;
|
|
749
|
+
/** Accepted file types (e.g., "image/*", ".pdf,.doc") */
|
|
454
750
|
accept?: string;
|
|
455
751
|
};
|
|
752
|
+
/**
|
|
753
|
+
* A file input field component that integrates React Hook Form with HeroUI Input.
|
|
754
|
+
*
|
|
755
|
+
* This component provides a type-safe file upload field with validation support,
|
|
756
|
+
* error handling, and accessibility features. The field value is a `FileList` or `null`.
|
|
757
|
+
*
|
|
758
|
+
* @template TFieldValues - The form data type
|
|
759
|
+
*
|
|
760
|
+
* @param props - The file field props
|
|
761
|
+
* @returns The rendered file field component
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```tsx
|
|
765
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
766
|
+
* import { z } from "zod";
|
|
767
|
+
*
|
|
768
|
+
* const schema = z.object({
|
|
769
|
+
* avatar: z.instanceof(FileList).nullable(),
|
|
770
|
+
* documents: z.instanceof(FileList).optional(),
|
|
771
|
+
* });
|
|
772
|
+
*
|
|
773
|
+
* function MyForm() {
|
|
774
|
+
* return (
|
|
775
|
+
* <ZodForm
|
|
776
|
+
* config={{
|
|
777
|
+
* schema,
|
|
778
|
+
* fields: [
|
|
779
|
+
* FormFieldHelpers.file("avatar", "Upload Avatar", { accept: "image/*" }),
|
|
780
|
+
* FormFieldHelpers.file("documents", "Upload Documents", {
|
|
781
|
+
* multiple: true,
|
|
782
|
+
* accept: ".pdf,.doc,.docx",
|
|
783
|
+
* }),
|
|
784
|
+
* ],
|
|
785
|
+
* }}
|
|
786
|
+
* onSubmit={(data) => console.log(data)}
|
|
787
|
+
* />
|
|
788
|
+
* );
|
|
789
|
+
* }
|
|
790
|
+
* ```
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* ```tsx
|
|
794
|
+
* // With file size validation
|
|
795
|
+
* <FileField
|
|
796
|
+
* control={form.control}
|
|
797
|
+
* name="avatar"
|
|
798
|
+
* label="Upload Avatar"
|
|
799
|
+
* accept="image/*"
|
|
800
|
+
* transform={(files) => {
|
|
801
|
+
* if (files && files[0] && files[0].size > 5 * 1024 * 1024) {
|
|
802
|
+
* // File too large
|
|
803
|
+
* return null;
|
|
804
|
+
* }
|
|
805
|
+
* return files;
|
|
806
|
+
* }}
|
|
807
|
+
* />
|
|
808
|
+
* ```
|
|
809
|
+
*/
|
|
456
810
|
declare function FileField<TFieldValues extends FieldValues>(props: FileFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
457
811
|
|
|
458
812
|
interface FontPickerProps {
|
|
@@ -525,45 +879,473 @@ type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldVa
|
|
|
525
879
|
*/
|
|
526
880
|
declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
|
|
527
881
|
|
|
882
|
+
/**
|
|
883
|
+
* Configuration for a radio option.
|
|
884
|
+
*
|
|
885
|
+
* @template TValue - The value type for the option
|
|
886
|
+
*/
|
|
528
887
|
interface RadioOption<TValue extends string | number> {
|
|
888
|
+
/** Display label for the option */
|
|
529
889
|
label: string;
|
|
890
|
+
/** Value of the option */
|
|
530
891
|
value: TValue;
|
|
892
|
+
/** Optional description text */
|
|
531
893
|
description?: string;
|
|
894
|
+
/** Whether the option is disabled */
|
|
532
895
|
disabled?: boolean;
|
|
533
896
|
}
|
|
897
|
+
/**
|
|
898
|
+
* Props for the RadioGroupField component.
|
|
899
|
+
*
|
|
900
|
+
* @template TFieldValues - The form data type
|
|
901
|
+
* @template TValue - The value type for the radio group (string or number)
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```tsx
|
|
905
|
+
* import { RadioGroupField } from "@rachelallyson/hero-hook-form";
|
|
906
|
+
* import { useForm } from "react-hook-form";
|
|
907
|
+
*
|
|
908
|
+
* const form = useForm({
|
|
909
|
+
* defaultValues: { plan: "" },
|
|
910
|
+
* });
|
|
911
|
+
*
|
|
912
|
+
* const options = [
|
|
913
|
+
* { label: "Basic", value: "basic" },
|
|
914
|
+
* { label: "Pro", value: "pro" },
|
|
915
|
+
* { label: "Enterprise", value: "enterprise" },
|
|
916
|
+
* ];
|
|
917
|
+
*
|
|
918
|
+
* <RadioGroupField
|
|
919
|
+
* control={form.control}
|
|
920
|
+
* name="plan"
|
|
921
|
+
* label="Select Plan"
|
|
922
|
+
* options={options}
|
|
923
|
+
* />
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
534
926
|
type RadioGroupFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
927
|
+
/** Array of radio options */
|
|
535
928
|
options: readonly RadioOption<TValue>[];
|
|
929
|
+
/** Additional props to pass to the underlying RadioGroup component */
|
|
536
930
|
radioGroupProps?: Omit<React$1.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">;
|
|
537
931
|
};
|
|
932
|
+
/**
|
|
933
|
+
* A radio group field component that integrates React Hook Form with HeroUI RadioGroup.
|
|
934
|
+
*
|
|
935
|
+
* This component provides a type-safe radio group field with validation support,
|
|
936
|
+
* error handling, and accessibility features. Only one option can be selected at a time.
|
|
937
|
+
*
|
|
938
|
+
* @template TFieldValues - The form data type
|
|
939
|
+
* @template TValue - The value type for the radio group (string or number)
|
|
940
|
+
*
|
|
941
|
+
* @param props - The radio group field props
|
|
942
|
+
* @returns The rendered radio group field component
|
|
943
|
+
*
|
|
944
|
+
* @example
|
|
945
|
+
* ```tsx
|
|
946
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
947
|
+
* import { z } from "zod";
|
|
948
|
+
*
|
|
949
|
+
* const schema = z.object({
|
|
950
|
+
* plan: z.enum(["basic", "pro", "enterprise"], {
|
|
951
|
+
* required_error: "Please select a plan",
|
|
952
|
+
* }),
|
|
953
|
+
* });
|
|
954
|
+
*
|
|
955
|
+
* const options = [
|
|
956
|
+
* { label: "Basic - $9/month", value: "basic" },
|
|
957
|
+
* { label: "Pro - $29/month", value: "pro" },
|
|
958
|
+
* { label: "Enterprise - $99/month", value: "enterprise" },
|
|
959
|
+
* ];
|
|
960
|
+
*
|
|
961
|
+
* function MyForm() {
|
|
962
|
+
* return (
|
|
963
|
+
* <ZodForm
|
|
964
|
+
* config={{
|
|
965
|
+
* schema,
|
|
966
|
+
* fields: [
|
|
967
|
+
* FormFieldHelpers.radioGroup("plan", "Select Plan", options),
|
|
968
|
+
* ],
|
|
969
|
+
* }}
|
|
970
|
+
* onSubmit={(data) => console.log(data)}
|
|
971
|
+
* />
|
|
972
|
+
* );
|
|
973
|
+
* }
|
|
974
|
+
* ```
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* ```tsx
|
|
978
|
+
* // With custom styling
|
|
979
|
+
* <RadioGroupField
|
|
980
|
+
* control={form.control}
|
|
981
|
+
* name="plan"
|
|
982
|
+
* label="Select Plan"
|
|
983
|
+
* options={options}
|
|
984
|
+
* radioGroupProps={{
|
|
985
|
+
* orientation: "horizontal",
|
|
986
|
+
* color: "primary",
|
|
987
|
+
* }}
|
|
988
|
+
* />
|
|
989
|
+
* ```
|
|
990
|
+
*/
|
|
538
991
|
declare function RadioGroupField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: RadioGroupFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
539
992
|
|
|
993
|
+
/**
|
|
994
|
+
* Configuration for a select option.
|
|
995
|
+
*
|
|
996
|
+
* @template TValue - The value type for the option
|
|
997
|
+
*/
|
|
540
998
|
interface SelectOption<TValue extends string | number> {
|
|
999
|
+
/** Display label for the option */
|
|
541
1000
|
label: string;
|
|
1001
|
+
/** Value of the option */
|
|
542
1002
|
value: TValue;
|
|
1003
|
+
/** Optional description text */
|
|
543
1004
|
description?: string;
|
|
1005
|
+
/** Whether the option is disabled */
|
|
544
1006
|
disabled?: boolean;
|
|
545
1007
|
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Props for the SelectField component.
|
|
1010
|
+
*
|
|
1011
|
+
* @template TFieldValues - The form data type
|
|
1012
|
+
* @template TValue - The value type for the select field (string or number)
|
|
1013
|
+
*
|
|
1014
|
+
* @example
|
|
1015
|
+
* ```tsx
|
|
1016
|
+
* import { SelectField } from "@rachelallyson/hero-hook-form";
|
|
1017
|
+
* import { useForm } from "react-hook-form";
|
|
1018
|
+
*
|
|
1019
|
+
* const form = useForm({
|
|
1020
|
+
* defaultValues: { country: "" },
|
|
1021
|
+
* });
|
|
1022
|
+
*
|
|
1023
|
+
* const options = [
|
|
1024
|
+
* { label: "United States", value: "us" },
|
|
1025
|
+
* { label: "Canada", value: "ca" },
|
|
1026
|
+
* { label: "Mexico", value: "mx" },
|
|
1027
|
+
* ];
|
|
1028
|
+
*
|
|
1029
|
+
* <SelectField
|
|
1030
|
+
* control={form.control}
|
|
1031
|
+
* name="country"
|
|
1032
|
+
* label="Country"
|
|
1033
|
+
* options={options}
|
|
1034
|
+
* placeholder="Select a country"
|
|
1035
|
+
* />
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
546
1038
|
type SelectFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
1039
|
+
/** Array of select options */
|
|
547
1040
|
options: readonly SelectOption<TValue>[];
|
|
1041
|
+
/** Placeholder text when no option is selected */
|
|
548
1042
|
placeholder?: string;
|
|
1043
|
+
/** Additional props to pass to the underlying Select component */
|
|
549
1044
|
selectProps?: Omit<React$1.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
550
1045
|
};
|
|
1046
|
+
/**
|
|
1047
|
+
* A select dropdown field component that integrates React Hook Form with HeroUI Select.
|
|
1048
|
+
*
|
|
1049
|
+
* This component provides a type-safe select field with validation support,
|
|
1050
|
+
* error handling, and accessibility features.
|
|
1051
|
+
*
|
|
1052
|
+
* @template TFieldValues - The form data type
|
|
1053
|
+
* @template TValue - The value type for the select field (string or number)
|
|
1054
|
+
*
|
|
1055
|
+
* @param props - The select field props
|
|
1056
|
+
* @returns The rendered select field component
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* ```tsx
|
|
1060
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
1061
|
+
* import { z } from "zod";
|
|
1062
|
+
*
|
|
1063
|
+
* const schema = z.object({
|
|
1064
|
+
* country: z.string().min(1, "Please select a country"),
|
|
1065
|
+
* });
|
|
1066
|
+
*
|
|
1067
|
+
* const options = [
|
|
1068
|
+
* { label: "United States", value: "us" },
|
|
1069
|
+
* { label: "Canada", value: "ca" },
|
|
1070
|
+
* ];
|
|
1071
|
+
*
|
|
1072
|
+
* function MyForm() {
|
|
1073
|
+
* return (
|
|
1074
|
+
* <ZodForm
|
|
1075
|
+
* config={{
|
|
1076
|
+
* schema,
|
|
1077
|
+
* fields: [
|
|
1078
|
+
* FormFieldHelpers.select("country", "Country", options, "Select a country"),
|
|
1079
|
+
* ],
|
|
1080
|
+
* }}
|
|
1081
|
+
* onSubmit={(data) => console.log(data)}
|
|
1082
|
+
* />
|
|
1083
|
+
* );
|
|
1084
|
+
* }
|
|
1085
|
+
* ```
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
* ```tsx
|
|
1089
|
+
* // With custom styling
|
|
1090
|
+
* <SelectField
|
|
1091
|
+
* control={form.control}
|
|
1092
|
+
* name="country"
|
|
1093
|
+
* label="Country"
|
|
1094
|
+
* options={options}
|
|
1095
|
+
* selectProps={{
|
|
1096
|
+
* variant: "bordered",
|
|
1097
|
+
* size: "lg",
|
|
1098
|
+
* }}
|
|
1099
|
+
* />
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
551
1102
|
declare function SelectField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: SelectFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
552
1103
|
|
|
1104
|
+
/**
|
|
1105
|
+
* Props for the SliderField component.
|
|
1106
|
+
*
|
|
1107
|
+
* @template TFieldValues - The form data type
|
|
1108
|
+
*
|
|
1109
|
+
* @example
|
|
1110
|
+
* ```tsx
|
|
1111
|
+
* import { SliderField } from "@rachelallyson/hero-hook-form";
|
|
1112
|
+
* import { useForm } from "react-hook-form";
|
|
1113
|
+
*
|
|
1114
|
+
* const form = useForm({
|
|
1115
|
+
* defaultValues: { volume: 50 },
|
|
1116
|
+
* });
|
|
1117
|
+
*
|
|
1118
|
+
* <SliderField
|
|
1119
|
+
* control={form.control}
|
|
1120
|
+
* name="volume"
|
|
1121
|
+
* label="Volume"
|
|
1122
|
+
* description="Adjust the volume level"
|
|
1123
|
+
* />
|
|
1124
|
+
* ```
|
|
1125
|
+
*/
|
|
553
1126
|
type SliderFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, number> & WithControl<TFieldValues> & {
|
|
1127
|
+
/** Additional props to pass to the underlying Slider component */
|
|
554
1128
|
sliderProps?: Omit<React$1.ComponentProps<typeof Slider>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
1129
|
+
/** Transform function to modify the slider value before it's set */
|
|
555
1130
|
transform?: (value: number) => number;
|
|
556
1131
|
};
|
|
1132
|
+
/**
|
|
1133
|
+
* A slider field component that integrates React Hook Form with HeroUI Slider.
|
|
1134
|
+
*
|
|
1135
|
+
* This component provides a type-safe slider field with validation support,
|
|
1136
|
+
* error handling, and accessibility features. The field value is a number.
|
|
1137
|
+
*
|
|
1138
|
+
* @template TFieldValues - The form data type
|
|
1139
|
+
*
|
|
1140
|
+
* @param props - The slider field props
|
|
1141
|
+
* @returns The rendered slider field component
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```tsx
|
|
1145
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
1146
|
+
* import { z } from "zod";
|
|
1147
|
+
*
|
|
1148
|
+
* const schema = z.object({
|
|
1149
|
+
* volume: z.number().min(0).max(100),
|
|
1150
|
+
* brightness: z.number().min(0).max(100),
|
|
1151
|
+
* });
|
|
1152
|
+
*
|
|
1153
|
+
* function MyForm() {
|
|
1154
|
+
* return (
|
|
1155
|
+
* <ZodForm
|
|
1156
|
+
* config={{
|
|
1157
|
+
* schema,
|
|
1158
|
+
* fields: [
|
|
1159
|
+
* FormFieldHelpers.slider("volume", "Volume", { min: 0, max: 100 }),
|
|
1160
|
+
* FormFieldHelpers.slider("brightness", "Brightness", { min: 0, max: 100 }),
|
|
1161
|
+
* ],
|
|
1162
|
+
* }}
|
|
1163
|
+
* onSubmit={(data) => console.log(data)}
|
|
1164
|
+
* />
|
|
1165
|
+
* );
|
|
1166
|
+
* }
|
|
1167
|
+
* ```
|
|
1168
|
+
*
|
|
1169
|
+
* @example
|
|
1170
|
+
* ```tsx
|
|
1171
|
+
* // With custom step and marks
|
|
1172
|
+
* <SliderField
|
|
1173
|
+
* control={form.control}
|
|
1174
|
+
* name="volume"
|
|
1175
|
+
* label="Volume"
|
|
1176
|
+
* sliderProps={{
|
|
1177
|
+
* minValue: 0,
|
|
1178
|
+
* maxValue: 100,
|
|
1179
|
+
* step: 10,
|
|
1180
|
+
* marks: [
|
|
1181
|
+
* { value: 0, label: "0" },
|
|
1182
|
+
* { value: 50, label: "50" },
|
|
1183
|
+
* { value: 100, label: "100" },
|
|
1184
|
+
* ],
|
|
1185
|
+
* }}
|
|
1186
|
+
* />
|
|
1187
|
+
* ```
|
|
1188
|
+
*/
|
|
557
1189
|
declare function SliderField<TFieldValues extends FieldValues>(props: SliderFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
558
1190
|
|
|
1191
|
+
/**
|
|
1192
|
+
* Props for the SwitchField component.
|
|
1193
|
+
*
|
|
1194
|
+
* @template TFieldValues - The form data type
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* ```tsx
|
|
1198
|
+
* import { SwitchField } from "@rachelallyson/hero-hook-form";
|
|
1199
|
+
* import { useForm } from "react-hook-form";
|
|
1200
|
+
*
|
|
1201
|
+
* const form = useForm({
|
|
1202
|
+
* defaultValues: { notifications: false },
|
|
1203
|
+
* });
|
|
1204
|
+
*
|
|
1205
|
+
* <SwitchField
|
|
1206
|
+
* control={form.control}
|
|
1207
|
+
* name="notifications"
|
|
1208
|
+
* label="Enable notifications"
|
|
1209
|
+
* description="Receive email notifications"
|
|
1210
|
+
* />
|
|
1211
|
+
* ```
|
|
1212
|
+
*/
|
|
559
1213
|
type SwitchFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
1214
|
+
/** Additional props to pass to the underlying Switch component */
|
|
560
1215
|
switchProps?: Omit<React$1.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">;
|
|
561
1216
|
};
|
|
1217
|
+
/**
|
|
1218
|
+
* A switch/toggle field component that integrates React Hook Form with HeroUI Switch.
|
|
1219
|
+
*
|
|
1220
|
+
* This component provides a type-safe switch field with validation support,
|
|
1221
|
+
* error handling, and accessibility features. The field value is a boolean.
|
|
1222
|
+
*
|
|
1223
|
+
* @template TFieldValues - The form data type
|
|
1224
|
+
*
|
|
1225
|
+
* @param props - The switch field props
|
|
1226
|
+
* @returns The rendered switch field component
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* ```tsx
|
|
1230
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
1231
|
+
* import { z } from "zod";
|
|
1232
|
+
*
|
|
1233
|
+
* const schema = z.object({
|
|
1234
|
+
* notifications: z.boolean(),
|
|
1235
|
+
* darkMode: z.boolean().default(false),
|
|
1236
|
+
* });
|
|
1237
|
+
*
|
|
1238
|
+
* function MyForm() {
|
|
1239
|
+
* return (
|
|
1240
|
+
* <ZodForm
|
|
1241
|
+
* config={{
|
|
1242
|
+
* schema,
|
|
1243
|
+
* fields: [
|
|
1244
|
+
* FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications"),
|
|
1245
|
+
* FormFieldHelpers.switch("darkMode", "Dark mode"),
|
|
1246
|
+
* ],
|
|
1247
|
+
* }}
|
|
1248
|
+
* onSubmit={(data) => console.log(data)}
|
|
1249
|
+
* />
|
|
1250
|
+
* );
|
|
1251
|
+
* }
|
|
1252
|
+
* ```
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* ```tsx
|
|
1256
|
+
* // With custom styling
|
|
1257
|
+
* <SwitchField
|
|
1258
|
+
* control={form.control}
|
|
1259
|
+
* name="notifications"
|
|
1260
|
+
* label="Enable notifications"
|
|
1261
|
+
* switchProps={{
|
|
1262
|
+
* color: "success",
|
|
1263
|
+
* size: "lg",
|
|
1264
|
+
* }}
|
|
1265
|
+
* />
|
|
1266
|
+
* ```
|
|
1267
|
+
*/
|
|
562
1268
|
declare function SwitchField<TFieldValues extends FieldValues>(props: SwitchFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
563
1269
|
|
|
1270
|
+
/**
|
|
1271
|
+
* Props for the TextareaField component.
|
|
1272
|
+
*
|
|
1273
|
+
* @template TFieldValues - The form data type
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```tsx
|
|
1277
|
+
* import { TextareaField } from "@rachelallyson/hero-hook-form";
|
|
1278
|
+
* import { useForm } from "react-hook-form";
|
|
1279
|
+
*
|
|
1280
|
+
* const form = useForm({
|
|
1281
|
+
* defaultValues: { message: "" },
|
|
1282
|
+
* });
|
|
1283
|
+
*
|
|
1284
|
+
* <TextareaField
|
|
1285
|
+
* control={form.control}
|
|
1286
|
+
* name="message"
|
|
1287
|
+
* label="Message"
|
|
1288
|
+
* description="Enter your message here"
|
|
1289
|
+
* placeholder="Type your message..."
|
|
1290
|
+
* />
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
564
1293
|
type TextareaFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
1294
|
+
/** Additional props to pass to the underlying Textarea component */
|
|
565
1295
|
textareaProps?: Omit<React$1.ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
566
1296
|
};
|
|
1297
|
+
/**
|
|
1298
|
+
* A textarea field component that integrates React Hook Form with HeroUI Textarea.
|
|
1299
|
+
*
|
|
1300
|
+
* This component provides a type-safe textarea field with validation support,
|
|
1301
|
+
* error handling, and accessibility features. Use this for multi-line text input.
|
|
1302
|
+
*
|
|
1303
|
+
* @template TFieldValues - The form data type
|
|
1304
|
+
*
|
|
1305
|
+
* @param props - The textarea field props
|
|
1306
|
+
* @returns The rendered textarea field component
|
|
1307
|
+
*
|
|
1308
|
+
* @example
|
|
1309
|
+
* ```tsx
|
|
1310
|
+
* import { ZodForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
1311
|
+
* import { z } from "zod";
|
|
1312
|
+
*
|
|
1313
|
+
* const schema = z.object({
|
|
1314
|
+
* message: z.string().min(10, "Message must be at least 10 characters"),
|
|
1315
|
+
* feedback: z.string().max(500, "Feedback must be less than 500 characters"),
|
|
1316
|
+
* });
|
|
1317
|
+
*
|
|
1318
|
+
* function MyForm() {
|
|
1319
|
+
* return (
|
|
1320
|
+
* <ZodForm
|
|
1321
|
+
* config={{
|
|
1322
|
+
* schema,
|
|
1323
|
+
* fields: [
|
|
1324
|
+
* FormFieldHelpers.textarea("message", "Message", "Enter your message"),
|
|
1325
|
+
* FormFieldHelpers.textarea("feedback", "Feedback"),
|
|
1326
|
+
* ],
|
|
1327
|
+
* }}
|
|
1328
|
+
* onSubmit={(data) => console.log(data)}
|
|
1329
|
+
* />
|
|
1330
|
+
* );
|
|
1331
|
+
* }
|
|
1332
|
+
* ```
|
|
1333
|
+
*
|
|
1334
|
+
* @example
|
|
1335
|
+
* ```tsx
|
|
1336
|
+
* // With custom styling and min/max rows
|
|
1337
|
+
* <TextareaField
|
|
1338
|
+
* control={form.control}
|
|
1339
|
+
* name="message"
|
|
1340
|
+
* label="Message"
|
|
1341
|
+
* textareaProps={{
|
|
1342
|
+
* minRows: 3,
|
|
1343
|
+
* maxRows: 10,
|
|
1344
|
+
* variant: "bordered",
|
|
1345
|
+
* }}
|
|
1346
|
+
* />
|
|
1347
|
+
* ```
|
|
1348
|
+
*/
|
|
567
1349
|
declare function TextareaField<TFieldValues extends FieldValues>(props: TextareaFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
568
1350
|
|
|
569
1351
|
/**
|
|
@@ -1164,14 +1946,6 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1164
1946
|
submitButtonText?: string;
|
|
1165
1947
|
subtitle?: string;
|
|
1166
1948
|
title?: string;
|
|
1167
|
-
render?: (formState: {
|
|
1168
|
-
form: UseFormReturn<T>;
|
|
1169
|
-
isSubmitting: boolean;
|
|
1170
|
-
isSubmitted: boolean;
|
|
1171
|
-
isSuccess: boolean;
|
|
1172
|
-
errors: FieldErrors<T>;
|
|
1173
|
-
values: T;
|
|
1174
|
-
}) => React$1.ReactNode;
|
|
1175
1949
|
}
|
|
1176
1950
|
/**
|
|
1177
1951
|
* ZodForm component for building type-safe forms with Zod validation.
|
|
@@ -1197,7 +1971,6 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1197
1971
|
* @param {string} [props.resetButtonText="Reset"] - Text for the reset button
|
|
1198
1972
|
* @param {(error: FormValidationError) => void} [props.onError] - Error callback for validation errors
|
|
1199
1973
|
* @param {(data: T) => void} [props.onSuccess] - Success callback called after successful submission
|
|
1200
|
-
* @param {(formState: {...}) => React.ReactNode} [props.render] - Custom render function for advanced use cases
|
|
1201
1974
|
*
|
|
1202
1975
|
* @returns {JSX.Element} The rendered form component with validation and error handling
|
|
1203
1976
|
*
|
|
@@ -1247,28 +2020,12 @@ interface ZodFormProps<T extends FieldValues> {
|
|
|
1247
2020
|
* />
|
|
1248
2021
|
* ```
|
|
1249
2022
|
*
|
|
1250
|
-
* @example
|
|
1251
|
-
* Custom render function for advanced control:
|
|
1252
|
-
* ```tsx
|
|
1253
|
-
* <ZodForm
|
|
1254
|
-
* config={{ schema, fields }}
|
|
1255
|
-
* onSubmit={handleSubmit}
|
|
1256
|
-
* render={({ form, isSubmitting, errors, values }) => (
|
|
1257
|
-
* <div>
|
|
1258
|
-
* <button disabled={isSubmitting}>
|
|
1259
|
-
* {isSubmitting ? "Submitting..." : "Submit"}
|
|
1260
|
-
* </button>
|
|
1261
|
-
* </div>
|
|
1262
|
-
* )}
|
|
1263
|
-
* />
|
|
1264
|
-
* ```
|
|
1265
|
-
*
|
|
1266
2023
|
* @see {@link Form} for the base form component without Zod
|
|
1267
2024
|
* @see {@link FormFieldHelpers} for field creation helpers
|
|
1268
2025
|
* @see {@link createBasicFormBuilder} for builder pattern alternative
|
|
1269
2026
|
* @category Components
|
|
1270
2027
|
*/
|
|
1271
|
-
declare function ZodForm<T extends FieldValues>({ className, columns, config, layout, onError, onSubmit, onSuccess,
|
|
2028
|
+
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;
|
|
1272
2029
|
|
|
1273
2030
|
/**
|
|
1274
2031
|
* Hook for using Zod validation with React Hook Form
|
|
@@ -1345,7 +2102,7 @@ declare class BasicFormBuilder<T extends FieldValues> {
|
|
|
1345
2102
|
/**
|
|
1346
2103
|
* Add a switch field
|
|
1347
2104
|
*/
|
|
1348
|
-
switch(name: Path<T>, label: string): this;
|
|
2105
|
+
switch(name: Path<T>, label: string, description?: string): this;
|
|
1349
2106
|
/**
|
|
1350
2107
|
* Build the final field configuration array
|
|
1351
2108
|
*/
|
|
@@ -1409,6 +2166,11 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
|
|
|
1409
2166
|
* { label: "CA", value: "ca" },
|
|
1410
2167
|
* ]),
|
|
1411
2168
|
* FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter"),
|
|
2169
|
+
* FormFieldHelpers.conditional(
|
|
2170
|
+
* "phone",
|
|
2171
|
+
* (values) => values.hasPhone === true,
|
|
2172
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2173
|
+
* ),
|
|
1412
2174
|
* ];
|
|
1413
2175
|
* ```
|
|
1414
2176
|
*
|
|
@@ -1416,10 +2178,30 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
|
|
|
1416
2178
|
* @category Builders
|
|
1417
2179
|
*/
|
|
1418
2180
|
declare const FormFieldHelpers: {
|
|
2181
|
+
/**
|
|
2182
|
+
* Create an autocomplete field
|
|
2183
|
+
*/
|
|
2184
|
+
autocomplete: <T extends FieldValues>(name: Path<T>, label: string, items: {
|
|
2185
|
+
label: string;
|
|
2186
|
+
value: string | number;
|
|
2187
|
+
}[], placeholder?: string) => ZodFormFieldConfig<T>;
|
|
1419
2188
|
/**
|
|
1420
2189
|
* Create a checkbox field
|
|
1421
2190
|
*/
|
|
1422
2191
|
checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
|
|
2192
|
+
/**
|
|
2193
|
+
* Create a conditional field that shows/hides based on form data
|
|
2194
|
+
*
|
|
2195
|
+
* @example
|
|
2196
|
+
* ```tsx
|
|
2197
|
+
* FormFieldHelpers.conditional(
|
|
2198
|
+
* "phone",
|
|
2199
|
+
* (values) => values.hasPhone === true,
|
|
2200
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel")
|
|
2201
|
+
* )
|
|
2202
|
+
* ```
|
|
2203
|
+
*/
|
|
2204
|
+
conditional: <T extends FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
|
|
1423
2205
|
/**
|
|
1424
2206
|
* Create a content field for headers, questions, or custom content between fields
|
|
1425
2207
|
*
|
|
@@ -1434,15 +2216,15 @@ declare const FormFieldHelpers: {
|
|
|
1434
2216
|
* })
|
|
1435
2217
|
* ```
|
|
1436
2218
|
*/
|
|
1437
|
-
content: <T extends FieldValues>(title?: string | null, description?: string | null, options?: {
|
|
2219
|
+
content: <T extends FieldValues = FieldValues>(title?: string | null, description?: string | null, options?: {
|
|
1438
2220
|
render?: (field: {
|
|
1439
|
-
form:
|
|
1440
|
-
errors:
|
|
2221
|
+
form: UseFormReturn<T>;
|
|
2222
|
+
errors: FieldErrors<T>;
|
|
1441
2223
|
isSubmitting: boolean;
|
|
1442
2224
|
}) => React$1.ReactNode;
|
|
1443
2225
|
className?: string;
|
|
1444
|
-
name?:
|
|
1445
|
-
}) =>
|
|
2226
|
+
name?: string;
|
|
2227
|
+
}) => ZodFormFieldConfig<T>;
|
|
1446
2228
|
/**
|
|
1447
2229
|
* Create a date field
|
|
1448
2230
|
*/
|
|
@@ -1461,7 +2243,7 @@ declare const FormFieldHelpers: {
|
|
|
1461
2243
|
/**
|
|
1462
2244
|
* Create a switch field
|
|
1463
2245
|
*/
|
|
1464
|
-
switch: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
|
|
2246
|
+
switch: <T extends FieldValues>(name: Path<T>, label: string, description?: string) => ZodFormFieldConfig<T>;
|
|
1465
2247
|
/**
|
|
1466
2248
|
* Create a textarea field
|
|
1467
2249
|
*/
|
|
@@ -2437,4 +3219,4 @@ declare const validationUtils: {
|
|
|
2437
3219
|
}>;
|
|
2438
3220
|
};
|
|
2439
3221
|
|
|
2440
|
-
export { AdvancedFieldBuilder, type BaseFormFieldConfig, BasicFormBuilder, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, CommonFields, ConditionalField, type ConditionalFieldConfig, type ConditionalFieldProps, type ConditionalValidation, ConfigurableForm, ContentField, type ContentFieldConfig, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type DynamicSectionConfig, DynamicSectionField, type DynamicSectionFieldProps, type EnhancedFormState, FieldArrayBuilder, type FieldArrayConfig, FieldArrayField, type FieldArrayFieldProps, FieldArrayItemBuilder, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, FormFieldHelpers, type FormProps, FormProvider, FormStatus, type FormStatusProps, type FormStep, type FormSubmissionState, type FormTestUtils, FormToast, type FormToastProps, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, ServerActionForm, type ServerFieldError, type ServerFormError, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, TypeInferredBuilder, type UseDebouncedValidationOptions, type UseEnhancedFormStateOptions, type UseInferredFormOptions, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, asyncValidation, commonValidations, createAdvancedBuilder, createBasicFormBuilder, createDateSchema, createEmailSchema, createField, createFieldArrayBuilder, createFieldArrayItemBuilder, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNestedPathBuilder, createNumberRangeSchema, createOptimizedFieldHandler, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createTypeInferredBuilder, createUrlSchema, createZodFormConfig, crossFieldValidation, debounce, deepEqual, defineInferredForm, errorMessages, field, getFieldError, getFormErrors, hasFieldError, hasFormErrors, serverValidation, shallowEqual, simulateFieldInput, simulateFormSubmission, throttle, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };
|
|
3222
|
+
export { AdvancedFieldBuilder, AutocompleteField, type AutocompleteFieldProps, type AutocompleteOption, type BaseFormFieldConfig, BasicFormBuilder, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, CommonFields, ConditionalField, type ConditionalFieldConfig, type ConditionalFieldProps, type ConditionalValidation, ConfigurableForm, ContentField, type ContentFieldConfig, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type DynamicSectionConfig, DynamicSectionField, type DynamicSectionFieldProps, type EnhancedFormState, FieldArrayBuilder, type FieldArrayConfig, FieldArrayField, type FieldArrayFieldProps, FieldArrayItemBuilder, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, FormFieldHelpers, type FormProps, FormProvider, FormStatus, type FormStatusProps, type FormStep, type FormSubmissionState, type FormTestUtils, FormToast, type FormToastProps, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, ServerActionForm, type ServerFieldError, type ServerFormError, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, TypeInferredBuilder, type UseDebouncedValidationOptions, type UseEnhancedFormStateOptions, type UseInferredFormOptions, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, asyncValidation, commonValidations, createAdvancedBuilder, createBasicFormBuilder, createDateSchema, createEmailSchema, createField, createFieldArrayBuilder, createFieldArrayItemBuilder, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNestedPathBuilder, createNumberRangeSchema, createOptimizedFieldHandler, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createTypeInferredBuilder, createUrlSchema, createZodFormConfig, crossFieldValidation, debounce, deepEqual, defineInferredForm, errorMessages, field, getFieldError, getFormErrors, hasFieldError, hasFormErrors, serverValidation, shallowEqual, simulateFieldInput, simulateFormSubmission, throttle, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };
|