@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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,65 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.5.1] - 2026-01-13
6
+
7
+ ### Fixed
8
+
9
+ - **Conditional Field Helper TypeScript Types**: Fixed type inference issues in `FormFieldHelpers.conditional()`
10
+ - Added default generic type parameter `= FieldValues` for better type compatibility
11
+ - Updated to use type assertion pattern similar to `FormFieldHelpers.content()` for consistency
12
+ - Improved type safety and compatibility with explicit type annotations in condition functions
13
+ - When TypeScript can't infer the type from `Partial<T>`, explicitly specify: `FormFieldHelpers.conditional<YourType>(...)`
14
+ - Removed unused `ConditionalFieldConfig` import
15
+
16
+ ## [2.5.0] - 2026-01-13
17
+
18
+ ### Added
19
+
20
+ - **AutocompleteField Component**: New autocomplete field component with full React Hook Form integration
21
+ - Supports static option lists via `items` prop
22
+ - Supports async loading via custom `children` render function
23
+ - Handles custom values with `allowsCustomValue` prop
24
+ - Full validation and error handling support
25
+ - Integrated with `FormFieldHelpers.autocomplete()` helper
26
+ - Integrated with `BasicFormBuilder.autocomplete()` method
27
+ - Comprehensive test coverage (10/10 tests passing)
28
+ - Example: `FormFieldHelpers.autocomplete("country", "Country", options, "Search for a country")`
29
+
30
+ ### Dependencies
31
+
32
+ - Added `@heroui/autocomplete` as optional peer dependency and dev dependency
33
+ - Updated UI exports to include Autocomplete and AutocompleteItem components
34
+
35
+ ## [2.4.0] - 2026-01-13
36
+
37
+ ### Added
38
+
39
+ - **Switch Field Description Support**: Added optional `description` parameter to `FormFieldHelpers.switch()` and `BasicFormBuilder.switch()`
40
+ - Allows adding help text to switch fields for better UX
41
+ - Description is rendered below the switch component
42
+ - Backward compatible - existing code without description continues to work
43
+ - Example: `FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications")`
44
+
45
+ - **Conditional Field Helper**: Added `FormFieldHelpers.conditional()` helper function for creating conditional fields
46
+ - Simplifies creating fields that show/hide based on form data
47
+ - Works seamlessly with all form types
48
+ - Example: `FormFieldHelpers.conditional("phone", (values) => values.hasPhone === true, FormFieldHelpers.input("phone", "Phone Number", "tel"))`
49
+
50
+ ### Fixed
51
+
52
+ - **AdvancedFormBuilder Switch Field**: Fixed bug in `AdvancedFormBuilder.switchField()` where:
53
+ - `description` parameter was accepted but not included in the returned config
54
+ - `isDisabled` was incorrectly placed in `switchProps.disabled` instead of at the top level
55
+ - Both properties are now correctly placed at the top level of the field config
56
+
57
+ ### Testing
58
+
59
+ - Added comprehensive test coverage for switch field description functionality
60
+ - Added tests for `FormFieldHelpers.switch()` with and without description
61
+ - Added tests for `BasicFormBuilder.switch()` with description
62
+ - All tests passing (8/8 tests in SwitchField.cy.tsx)
63
+
5
64
  ## [2.3.0] - 2026-01-13
6
65
 
7
66
  ### Removed
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;
@@ -428,6 +430,127 @@ interface ServerActionFormProps<T extends FieldValues> {
428
430
  */
429
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;
430
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
+
431
554
  /**
432
555
  * Props for the CheckboxField component.
433
556
  *
@@ -1118,7 +1241,7 @@ type SwitchFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldV
1118
1241
  * config={{
1119
1242
  * schema,
1120
1243
  * fields: [
1121
- * FormFieldHelpers.switch("notifications", "Enable notifications"),
1244
+ * FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications"),
1122
1245
  * FormFieldHelpers.switch("darkMode", "Dark mode"),
1123
1246
  * ],
1124
1247
  * }}
@@ -1960,6 +2083,13 @@ declare class BasicFormBuilder<T extends FieldValues> {
1960
2083
  label: string;
1961
2084
  value: string | number;
1962
2085
  }[]): this;
2086
+ /**
2087
+ * Add an autocomplete field
2088
+ */
2089
+ autocomplete(name: Path<T>, label: string, items: {
2090
+ label: string;
2091
+ value: string | number;
2092
+ }[], placeholder?: string): this;
1963
2093
  /**
1964
2094
  * Add a checkbox field
1965
2095
  */
@@ -1979,7 +2109,7 @@ declare class BasicFormBuilder<T extends FieldValues> {
1979
2109
  /**
1980
2110
  * Add a switch field
1981
2111
  */
1982
- switch(name: Path<T>, label: string): this;
2112
+ switch(name: Path<T>, label: string, description?: string): this;
1983
2113
  /**
1984
2114
  * Build the final field configuration array
1985
2115
  */
@@ -2043,6 +2173,11 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2043
2173
  * { label: "CA", value: "ca" },
2044
2174
  * ]),
2045
2175
  * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter"),
2176
+ * FormFieldHelpers.conditional(
2177
+ * "phone",
2178
+ * (values) => values.hasPhone === true,
2179
+ * FormFieldHelpers.input("phone", "Phone Number", "tel")
2180
+ * ),
2046
2181
  * ];
2047
2182
  * ```
2048
2183
  *
@@ -2050,10 +2185,41 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2050
2185
  * @category Builders
2051
2186
  */
2052
2187
  declare const FormFieldHelpers: {
2188
+ /**
2189
+ * Create an autocomplete field
2190
+ */
2191
+ autocomplete: <T extends FieldValues>(name: Path<T>, label: string, items: {
2192
+ label: string;
2193
+ value: string | number;
2194
+ }[], placeholder?: string) => ZodFormFieldConfig<T>;
2053
2195
  /**
2054
2196
  * Create a checkbox field
2055
2197
  */
2056
2198
  checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2199
+ /**
2200
+ * Create a conditional field that shows/hides based on form data
2201
+ *
2202
+ * @example
2203
+ * ```tsx
2204
+ * FormFieldHelpers.conditional(
2205
+ * "phone",
2206
+ * (values) => values.hasPhone === true,
2207
+ * FormFieldHelpers.input("phone", "Phone Number", "tel")
2208
+ * )
2209
+ * ```
2210
+ *
2211
+ * @example
2212
+ * With explicit type in condition function (similar to content helper pattern):
2213
+ * ```tsx
2214
+ * FormFieldHelpers.conditional(
2215
+ * "options",
2216
+ * (formData: Partial<z.infer<typeof fieldSchema>>) =>
2217
+ * formData.fieldType === 'DROPDOWN',
2218
+ * FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
2219
+ * )
2220
+ * ```
2221
+ */
2222
+ conditional: <T extends FieldValues = FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
2057
2223
  /**
2058
2224
  * Create a content field for headers, questions, or custom content between fields
2059
2225
  *
@@ -2095,7 +2261,7 @@ declare const FormFieldHelpers: {
2095
2261
  /**
2096
2262
  * Create a switch field
2097
2263
  */
2098
- switch: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2264
+ switch: <T extends FieldValues>(name: Path<T>, label: string, description?: string) => ZodFormFieldConfig<T>;
2099
2265
  /**
2100
2266
  * Create a textarea field
2101
2267
  */
@@ -3071,4 +3237,4 @@ declare const validationUtils: {
3071
3237
  }>;
3072
3238
  };
3073
3239
 
3074
- 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 };
3240
+ 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 };