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