@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 CHANGED
@@ -2,6 +2,35 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.4.0] - 2026-01-13
6
+
7
+ ### Added
8
+
9
+ - **Switch Field Description Support**: Added optional `description` parameter to `FormFieldHelpers.switch()` and `BasicFormBuilder.switch()`
10
+ - Allows adding help text to switch fields for better UX
11
+ - Description is rendered below the switch component
12
+ - Backward compatible - existing code without description continues to work
13
+ - Example: `FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications")`
14
+
15
+ - **Conditional Field Helper**: Added `FormFieldHelpers.conditional()` helper function for creating conditional fields
16
+ - Simplifies creating fields that show/hide based on form data
17
+ - Works seamlessly with all form types
18
+ - Example: `FormFieldHelpers.conditional("phone", (values) => values.hasPhone === true, FormFieldHelpers.input("phone", "Phone Number", "tel"))`
19
+
20
+ ### Fixed
21
+
22
+ - **AdvancedFormBuilder Switch Field**: Fixed bug in `AdvancedFormBuilder.switchField()` where:
23
+ - `description` parameter was accepted but not included in the returned config
24
+ - `isDisabled` was incorrectly placed in `switchProps.disabled` instead of at the top level
25
+ - Both properties are now correctly placed at the top level of the field config
26
+
27
+ ### Testing
28
+
29
+ - Added comprehensive test coverage for switch field description functionality
30
+ - Added tests for `FormFieldHelpers.switch()` with and without description
31
+ - Added tests for `BasicFormBuilder.switch()` with description
32
+ - All tests passing (8/8 tests in SwitchField.cy.tsx)
33
+
5
34
  ## [2.3.0] - 2026-01-13
6
35
 
7
36
  ### 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
  * }}
@@ -1979,7 +2102,7 @@ declare class BasicFormBuilder<T extends FieldValues> {
1979
2102
  /**
1980
2103
  * Add a switch field
1981
2104
  */
1982
- switch(name: Path<T>, label: string): this;
2105
+ switch(name: Path<T>, label: string, description?: string): this;
1983
2106
  /**
1984
2107
  * Build the final field configuration array
1985
2108
  */
@@ -2043,6 +2166,11 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2043
2166
  * { label: "CA", value: "ca" },
2044
2167
  * ]),
2045
2168
  * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter"),
2169
+ * FormFieldHelpers.conditional(
2170
+ * "phone",
2171
+ * (values) => values.hasPhone === true,
2172
+ * FormFieldHelpers.input("phone", "Phone Number", "tel")
2173
+ * ),
2046
2174
  * ];
2047
2175
  * ```
2048
2176
  *
@@ -2050,10 +2178,30 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2050
2178
  * @category Builders
2051
2179
  */
2052
2180
  declare const FormFieldHelpers: {
2181
+ /**
2182
+ * Create an autocomplete field
2183
+ */
2184
+ autocomplete: <T extends FieldValues>(name: Path<T>, label: string, items: {
2185
+ label: string;
2186
+ value: string | number;
2187
+ }[], placeholder?: string) => ZodFormFieldConfig<T>;
2053
2188
  /**
2054
2189
  * Create a checkbox field
2055
2190
  */
2056
2191
  checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2192
+ /**
2193
+ * Create a conditional field that shows/hides based on form data
2194
+ *
2195
+ * @example
2196
+ * ```tsx
2197
+ * FormFieldHelpers.conditional(
2198
+ * "phone",
2199
+ * (values) => values.hasPhone === true,
2200
+ * FormFieldHelpers.input("phone", "Phone Number", "tel")
2201
+ * )
2202
+ * ```
2203
+ */
2204
+ conditional: <T extends FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
2057
2205
  /**
2058
2206
  * Create a content field for headers, questions, or custom content between fields
2059
2207
  *
@@ -2095,7 +2243,7 @@ declare const FormFieldHelpers: {
2095
2243
  /**
2096
2244
  * Create a switch field
2097
2245
  */
2098
- switch: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2246
+ switch: <T extends FieldValues>(name: Path<T>, label: string, description?: string) => ZodFormFieldConfig<T>;
2099
2247
  /**
2100
2248
  * Create a textarea field
2101
2249
  */
@@ -3071,4 +3219,4 @@ declare const validationUtils: {
3071
3219
  }>;
3072
3220
  };
3073
3221
 
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 };
3222
+ export { AdvancedFieldBuilder, AutocompleteField, type AutocompleteFieldProps, type AutocompleteOption, type BaseFormFieldConfig, BasicFormBuilder, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, CommonFields, ConditionalField, type ConditionalFieldConfig, type ConditionalFieldProps, type ConditionalValidation, ConfigurableForm, ContentField, type ContentFieldConfig, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type DynamicSectionConfig, DynamicSectionField, type DynamicSectionFieldProps, type EnhancedFormState, FieldArrayBuilder, type FieldArrayConfig, FieldArrayField, type FieldArrayFieldProps, FieldArrayItemBuilder, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, FormFieldHelpers, type FormProps, FormProvider, FormStatus, type FormStatusProps, type FormStep, type FormSubmissionState, type FormTestUtils, FormToast, type FormToastProps, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, ServerActionForm, type ServerFieldError, type ServerFormError, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, TypeInferredBuilder, type UseDebouncedValidationOptions, type UseEnhancedFormStateOptions, type UseInferredFormOptions, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, asyncValidation, commonValidations, createAdvancedBuilder, createBasicFormBuilder, createDateSchema, createEmailSchema, createField, createFieldArrayBuilder, createFieldArrayItemBuilder, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNestedPathBuilder, createNumberRangeSchema, createOptimizedFieldHandler, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createTypeInferredBuilder, createUrlSchema, createZodFormConfig, crossFieldValidation, debounce, deepEqual, defineInferredForm, errorMessages, field, getFieldError, getFormErrors, hasFieldError, hasFormErrors, serverValidation, shallowEqual, simulateFieldInput, simulateFormSubmission, throttle, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };