@rachelallyson/hero-hook-form 2.3.0 → 2.5.1

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.
@@ -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
  * }}
@@ -1952,6 +2074,13 @@ declare class BasicFormBuilder<T extends FieldValues> {
1952
2074
  label: string;
1953
2075
  value: string | number;
1954
2076
  }[]): this;
2077
+ /**
2078
+ * Add an autocomplete field
2079
+ */
2080
+ autocomplete(name: Path<T>, label: string, items: {
2081
+ label: string;
2082
+ value: string | number;
2083
+ }[], placeholder?: string): this;
1955
2084
  /**
1956
2085
  * Add a checkbox field
1957
2086
  */
@@ -1971,7 +2100,7 @@ declare class BasicFormBuilder<T extends FieldValues> {
1971
2100
  /**
1972
2101
  * Add a switch field
1973
2102
  */
1974
- switch(name: Path<T>, label: string): this;
2103
+ switch(name: Path<T>, label: string, description?: string): this;
1975
2104
  /**
1976
2105
  * Build the final field configuration array
1977
2106
  */
@@ -2035,6 +2164,11 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2035
2164
  * { label: "CA", value: "ca" },
2036
2165
  * ]),
2037
2166
  * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter"),
2167
+ * FormFieldHelpers.conditional(
2168
+ * "phone",
2169
+ * (values) => values.hasPhone === true,
2170
+ * FormFieldHelpers.input("phone", "Phone Number", "tel")
2171
+ * ),
2038
2172
  * ];
2039
2173
  * ```
2040
2174
  *
@@ -2042,10 +2176,41 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2042
2176
  * @category Builders
2043
2177
  */
2044
2178
  declare const FormFieldHelpers: {
2179
+ /**
2180
+ * Create an autocomplete field
2181
+ */
2182
+ autocomplete: <T extends FieldValues>(name: Path<T>, label: string, items: {
2183
+ label: string;
2184
+ value: string | number;
2185
+ }[], placeholder?: string) => ZodFormFieldConfig<T>;
2045
2186
  /**
2046
2187
  * Create a checkbox field
2047
2188
  */
2048
2189
  checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2190
+ /**
2191
+ * Create a conditional field that shows/hides based on form data
2192
+ *
2193
+ * @example
2194
+ * ```tsx
2195
+ * FormFieldHelpers.conditional(
2196
+ * "phone",
2197
+ * (values) => values.hasPhone === true,
2198
+ * FormFieldHelpers.input("phone", "Phone Number", "tel")
2199
+ * )
2200
+ * ```
2201
+ *
2202
+ * @example
2203
+ * With explicit type in condition function (similar to content helper pattern):
2204
+ * ```tsx
2205
+ * FormFieldHelpers.conditional(
2206
+ * "options",
2207
+ * (formData: Partial<z.infer<typeof fieldSchema>>) =>
2208
+ * formData.fieldType === 'DROPDOWN',
2209
+ * FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
2210
+ * )
2211
+ * ```
2212
+ */
2213
+ conditional: <T extends FieldValues = FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
2049
2214
  /**
2050
2215
  * Create a content field for headers, questions, or custom content between fields
2051
2216
  *
@@ -2087,7 +2252,7 @@ declare const FormFieldHelpers: {
2087
2252
  /**
2088
2253
  * Create a switch field
2089
2254
  */
2090
- switch: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2255
+ switch: <T extends FieldValues>(name: Path<T>, label: string, description?: string) => ZodFormFieldConfig<T>;
2091
2256
  /**
2092
2257
  * Create a textarea field
2093
2258
  */
@@ -3063,4 +3228,4 @@ declare const validationUtils: {
3063
3228
  }>;
3064
3229
  };
3065
3230
 
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 };
3231
+ 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 };