@rachelallyson/hero-hook-form 2.3.0 → 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 +29 -0
- package/dist/index.d.ts +153 -5
- package/dist/index.js +300 -187
- package/dist/react/index.d.ts +153 -6
- package/dist/react/index.js +306 -192
- 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;
|
|
@@ -420,6 +421,127 @@ interface ServerActionFormProps<T extends FieldValues> {
|
|
|
420
421
|
*/
|
|
421
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;
|
|
422
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
|
+
|
|
423
545
|
/**
|
|
424
546
|
* Props for the CheckboxField component.
|
|
425
547
|
*
|
|
@@ -1110,7 +1232,7 @@ type SwitchFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldV
|
|
|
1110
1232
|
* config={{
|
|
1111
1233
|
* schema,
|
|
1112
1234
|
* fields: [
|
|
1113
|
-
* FormFieldHelpers.switch("notifications", "Enable notifications"),
|
|
1235
|
+
* FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications"),
|
|
1114
1236
|
* FormFieldHelpers.switch("darkMode", "Dark mode"),
|
|
1115
1237
|
* ],
|
|
1116
1238
|
* }}
|
|
@@ -1971,7 +2093,7 @@ declare class BasicFormBuilder<T extends FieldValues> {
|
|
|
1971
2093
|
/**
|
|
1972
2094
|
* Add a switch field
|
|
1973
2095
|
*/
|
|
1974
|
-
switch(name: Path<T>, label: string): this;
|
|
2096
|
+
switch(name: Path<T>, label: string, description?: string): this;
|
|
1975
2097
|
/**
|
|
1976
2098
|
* Build the final field configuration array
|
|
1977
2099
|
*/
|
|
@@ -2035,6 +2157,11 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
|
|
|
2035
2157
|
* { label: "CA", value: "ca" },
|
|
2036
2158
|
* ]),
|
|
2037
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
|
+
* ),
|
|
2038
2165
|
* ];
|
|
2039
2166
|
* ```
|
|
2040
2167
|
*
|
|
@@ -2042,10 +2169,30 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
|
|
|
2042
2169
|
* @category Builders
|
|
2043
2170
|
*/
|
|
2044
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>;
|
|
2045
2179
|
/**
|
|
2046
2180
|
* Create a checkbox field
|
|
2047
2181
|
*/
|
|
2048
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>;
|
|
2049
2196
|
/**
|
|
2050
2197
|
* Create a content field for headers, questions, or custom content between fields
|
|
2051
2198
|
*
|
|
@@ -2087,7 +2234,7 @@ declare const FormFieldHelpers: {
|
|
|
2087
2234
|
/**
|
|
2088
2235
|
* Create a switch field
|
|
2089
2236
|
*/
|
|
2090
|
-
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>;
|
|
2091
2238
|
/**
|
|
2092
2239
|
* Create a textarea field
|
|
2093
2240
|
*/
|
|
@@ -3063,4 +3210,4 @@ declare const validationUtils: {
|
|
|
3063
3210
|
}>;
|
|
3064
3211
|
};
|
|
3065
3212
|
|
|
3066
|
-
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 };
|