@rachelallyson/hero-hook-form 2.5.1 → 2.7.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.
@@ -1,10 +1,10 @@
1
1
  import React$1, { ComponentProps } from 'react';
2
- import { Input, Textarea, Select, Autocomplete, Checkbox, Switch, RadioGroup, Button, DateInput, Slider } from '@heroui/react';
2
+ import { Input, Textarea, Select, Autocomplete, Checkbox, Switch, RadioGroup, Slider, DateInput, Button } from '@heroui/react';
3
3
  import * as react_hook_form from 'react-hook-form';
4
- import { FieldValues, Path, RegisterOptions, Control, UseFormReturn, FieldErrors, UseFormProps, SubmitHandler, UseFormSetError } from 'react-hook-form';
4
+ import { FieldValues, Path, RegisterOptions, Control, UseFormReturn, FieldErrors, UseFormProps, SubmitHandler, UseFormSetError, DefaultValues, ArrayPath, FieldArrayWithId } from 'react-hook-form';
5
5
  export { UseFormReturn, useFormContext } from 'react-hook-form';
6
6
  import * as zod from 'zod';
7
- import { z } from 'zod';
7
+ import { z, ZodSchema } from 'zod';
8
8
  import * as _internationalized_date from '@internationalized/date';
9
9
  import { CalendarDate } from '@internationalized/date';
10
10
 
@@ -67,24 +67,29 @@ interface RadioFieldConfig<TFieldValues extends FieldValues> extends BaseFormFie
67
67
  interface SliderFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
68
68
  type: "slider";
69
69
  defaultValue?: number;
70
- sliderProps?: Record<string, string | number | boolean>;
70
+ sliderProps?: Omit<ComponentProps<typeof Slider>, "value" | "onChange" | "label" | "isDisabled">;
71
71
  }
72
72
  interface DateFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
73
73
  type: "date";
74
74
  defaultValue?: _internationalized_date.CalendarDate | null;
75
- dateProps?: Record<string, string | number | boolean>;
75
+ dateProps?: Omit<ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
76
76
  }
77
77
  interface FileFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
78
78
  type: "file";
79
79
  defaultValue?: FileList | null;
80
- fileProps?: Record<string, string | number | boolean>;
80
+ fileProps?: Omit<ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "type">;
81
81
  multiple?: boolean;
82
82
  accept?: string;
83
83
  }
84
84
  interface FontPickerFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
85
85
  type: "fontPicker";
86
86
  defaultValue?: string;
87
- fontPickerProps?: Record<string, string | number | boolean>;
87
+ fontPickerProps?: {
88
+ showFontPreview?: boolean;
89
+ loadAllVariants?: boolean;
90
+ onFontsLoaded?: (loaded: boolean) => void;
91
+ fontsLoadedTimeout?: number;
92
+ };
88
93
  }
89
94
  interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
90
95
  type: "custom";
@@ -101,13 +106,74 @@ interface ConditionalFieldConfig<TFieldValues extends FieldValues> extends BaseF
101
106
  condition: (formData: Partial<TFieldValues>) => boolean;
102
107
  field: ZodFormFieldConfig<TFieldValues>;
103
108
  }
109
+ /**
110
+ * Field array config for dynamic repeating field groups.
111
+ *
112
+ * @description
113
+ * Configuration for field arrays that support reordering, custom rendering,
114
+ * default values, and conditional fields within array items.
115
+ *
116
+ * @template TFieldValues - The form data type
117
+ */
104
118
  interface FieldArrayConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
105
119
  type: "fieldArray";
120
+ /** Field configurations for each array item */
106
121
  fields: ZodFormFieldConfig<TFieldValues>[];
122
+ /** Minimum number of items (default: 0) */
107
123
  min?: number;
124
+ /** Maximum number of items (default: 10) */
108
125
  max?: number;
126
+ /** Add button text (default: "Add Item") */
109
127
  addButtonText?: string;
128
+ /** Remove button text (default: "Remove") */
110
129
  removeButtonText?: string;
130
+ /** Enable reordering of array items with up/down buttons (default: false) */
131
+ enableReordering?: boolean;
132
+ /** Custom text for reorder buttons */
133
+ reorderButtonText?: {
134
+ /** Text for move up button (default: "↑") */
135
+ up?: string;
136
+ /** Text for move down button (default: "↓") */
137
+ down?: string;
138
+ };
139
+ /** Function to create default item when adding new array item */
140
+ defaultItem?: () => any;
141
+ /** Custom render function for array items */
142
+ renderItem?: (props: {
143
+ /** Item index (0-based) */
144
+ index: number;
145
+ /** Field array item with id */
146
+ field: {
147
+ id: string;
148
+ [key: string]: any;
149
+ };
150
+ /** All fields in the array */
151
+ fields: {
152
+ id: string;
153
+ [key: string]: any;
154
+ }[];
155
+ /** Rendered field elements */
156
+ children: React.ReactNode;
157
+ /** Remove this item */
158
+ onRemove: () => void;
159
+ /** Move item up */
160
+ onMoveUp: () => void;
161
+ /** Move item down */
162
+ onMoveDown: () => void;
163
+ /** Whether item can be removed */
164
+ canRemove: boolean;
165
+ /** Whether item can move up */
166
+ canMoveUp: boolean;
167
+ /** Whether item can move down */
168
+ canMoveDown: boolean;
169
+ }) => React.ReactNode;
170
+ /** Custom render function for add button */
171
+ renderAddButton?: (props: {
172
+ /** Add new item */
173
+ onAdd: () => void;
174
+ /** Whether new item can be added */
175
+ canAdd: boolean;
176
+ }) => React.ReactNode;
111
177
  }
112
178
  interface DynamicSectionConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
113
179
  type: "dynamicSection";
@@ -2018,6 +2084,83 @@ interface ZodFormProps<T extends FieldValues> {
2018
2084
  */
2019
2085
  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;
2020
2086
 
2087
+ /**
2088
+ * Props for the SimpleForm component.
2089
+ *
2090
+ * @template TFieldValues - The form data type
2091
+ */
2092
+ interface SimpleFormProps<TFieldValues extends FieldValues> {
2093
+ /** Zod schema for validation */
2094
+ schema: ZodSchema<TFieldValues>;
2095
+ /** Single field configuration */
2096
+ field: ZodFormFieldConfig<TFieldValues>;
2097
+ /** Submit handler */
2098
+ onSubmit: (data: TFieldValues) => Promise<void> | void;
2099
+ /** Optional custom submit button */
2100
+ submitButton?: React$1.ReactNode;
2101
+ /** Optional form title */
2102
+ title?: string;
2103
+ /** Optional form subtitle */
2104
+ subtitle?: string;
2105
+ /** Optional className */
2106
+ className?: string;
2107
+ /** Optional default values */
2108
+ defaultValues?: DefaultValues<TFieldValues>;
2109
+ /** Optional error callback */
2110
+ onError?: (error: FormValidationError) => void;
2111
+ /** Optional success callback */
2112
+ onSuccess?: (data: TFieldValues) => void;
2113
+ /** Hide default submit button (use custom submitButton instead) */
2114
+ hideSubmitButton?: boolean;
2115
+ }
2116
+ /**
2117
+ * Simple form component for single-field forms.
2118
+ *
2119
+ * @description
2120
+ * A simplified API for forms with a single field. Provides the same validation
2121
+ * and error handling as ZodForm but with a simpler configuration.
2122
+ * Useful for simple inputs like search bars, message inputs, or single-field forms.
2123
+ *
2124
+ * @template TFieldValues - The form data type
2125
+ *
2126
+ * @param {SimpleFormProps<TFieldValues>} props - Component props
2127
+ * @returns {JSX.Element} The rendered form
2128
+ *
2129
+ * @example
2130
+ * ```tsx
2131
+ * import { SimpleForm, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
2132
+ * import { z } from "zod";
2133
+ *
2134
+ * const messageSchema = z.object({
2135
+ * message: z.string().min(1, "Message cannot be empty"),
2136
+ * });
2137
+ *
2138
+ * function MessageInput() {
2139
+ * return (
2140
+ * <SimpleForm
2141
+ * schema={messageSchema}
2142
+ * field={FormFieldHelpers.input("message", "", {
2143
+ * placeholder: "Add a note...",
2144
+ * endContent: (
2145
+ * <Button type="submit" isIconOnly>
2146
+ * <SendIcon />
2147
+ * </Button>
2148
+ * ),
2149
+ * })}
2150
+ * onSubmit={async (data) => {
2151
+ * await sendMessage(data.message);
2152
+ * }}
2153
+ * hideSubmitButton
2154
+ * />
2155
+ * );
2156
+ * }
2157
+ * ```
2158
+ *
2159
+ * @see {@link ZodForm} for multi-field forms
2160
+ * @category Components
2161
+ */
2162
+ declare function SimpleForm<TFieldValues extends FieldValues>({ className, defaultValues, field, hideSubmitButton, onError, onSubmit, onSuccess, schema, submitButton, subtitle, title, }: SimpleFormProps<TFieldValues>): React$1.JSX.Element;
2163
+
2021
2164
  /**
2022
2165
  * Hook for using Zod validation with React Hook Form
2023
2166
  */
@@ -2178,15 +2321,42 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2178
2321
  declare const FormFieldHelpers: {
2179
2322
  /**
2180
2323
  * Create an autocomplete field
2324
+ *
2325
+ * @example
2326
+ * ```tsx
2327
+ * // Simple autocomplete
2328
+ * FormFieldHelpers.autocomplete("country", "Country", options)
2329
+ *
2330
+ * // With placeholder
2331
+ * FormFieldHelpers.autocomplete("country", "Country", options, "Search countries")
2332
+ *
2333
+ * // With full customization
2334
+ * FormFieldHelpers.autocomplete("country", "Country", options, "Search countries", {
2335
+ * classNames: { base: "custom-autocomplete" },
2336
+ * allowsCustomValue: true
2337
+ * })
2338
+ * ```
2181
2339
  */
2182
2340
  autocomplete: <T extends FieldValues>(name: Path<T>, label: string, items: {
2183
2341
  label: string;
2184
2342
  value: string | number;
2185
- }[], placeholder?: string) => ZodFormFieldConfig<T>;
2343
+ }[], placeholder?: string, autocompleteProps?: Omit<React$1.ComponentProps<typeof Autocomplete>, "selectedKey" | "onSelectionChange" | "inputValue" | "onInputChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "children" | "items">) => ZodFormFieldConfig<T>;
2186
2344
  /**
2187
2345
  * Create a checkbox field
2346
+ *
2347
+ * @example
2348
+ * ```tsx
2349
+ * // Simple checkbox
2350
+ * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter")
2351
+ *
2352
+ * // With full customization
2353
+ * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter", {
2354
+ * classNames: { base: "custom-checkbox" },
2355
+ * size: "lg"
2356
+ * })
2357
+ * ```
2188
2358
  */
2189
- checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2359
+ checkbox: <T extends FieldValues>(name: Path<T>, label: string, checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2190
2360
  /**
2191
2361
  * Create a conditional field that shows/hides based on form data
2192
2362
  *
@@ -2236,27 +2406,192 @@ declare const FormFieldHelpers: {
2236
2406
  }) => ZodFormFieldConfig<T>;
2237
2407
  /**
2238
2408
  * Create a date field
2409
+ *
2410
+ * @example
2411
+ * ```tsx
2412
+ * // Simple date field
2413
+ * FormFieldHelpers.date("birthDate", "Birth Date")
2414
+ *
2415
+ * // With full customization
2416
+ * FormFieldHelpers.date("birthDate", "Birth Date", {
2417
+ * label: "Select your birth date",
2418
+ * granularity: "day",
2419
+ * minValue: new CalendarDate(1900, 1, 1)
2420
+ * })
2421
+ * ```
2422
+ */
2423
+ date: <T extends FieldValues>(name: Path<T>, label: string, dateProps?: Omit<React$1.ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2424
+ /**
2425
+ * Create a file upload field
2426
+ *
2427
+ * @example
2428
+ * ```tsx
2429
+ * // Simple file field
2430
+ * FormFieldHelpers.file("avatar", "Profile Picture")
2431
+ *
2432
+ * // With accept and multiple
2433
+ * FormFieldHelpers.file("avatar", "Profile Picture", {
2434
+ * accept: "image/*",
2435
+ * multiple: true
2436
+ * })
2437
+ *
2438
+ * // With full customization
2439
+ * FormFieldHelpers.file("avatar", "Profile Picture", {
2440
+ * accept: "image/*",
2441
+ * multiple: false,
2442
+ * fileProps: { className: "custom-file-input" }
2443
+ * })
2444
+ * ```
2445
+ */
2446
+ file: <T extends FieldValues>(name: Path<T>, label: string, options?: {
2447
+ accept?: string;
2448
+ fileProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "type">;
2449
+ multiple?: boolean;
2450
+ }) => ZodFormFieldConfig<T>;
2451
+ /**
2452
+ * Create a font picker field
2453
+ *
2454
+ * @example
2455
+ * ```tsx
2456
+ * // Simple font picker
2457
+ * FormFieldHelpers.fontPicker("font", "Choose Font")
2458
+ *
2459
+ * // With full customization
2460
+ * FormFieldHelpers.fontPicker("font", "Choose Font", {
2461
+ * showFontPreview: true,
2462
+ * loadAllVariants: false,
2463
+ * fontsLoadedTimeout: 5000
2464
+ * })
2465
+ * ```
2239
2466
  */
2240
- date: <T extends FieldValues>(name: Path<T>, label: string, dateProps?: Record<string, string | number | boolean>) => ZodFormFieldConfig<T>;
2467
+ fontPicker: <T extends FieldValues>(name: Path<T>, label: string, fontPickerProps?: {
2468
+ showFontPreview?: boolean;
2469
+ loadAllVariants?: boolean;
2470
+ onFontsLoaded?: (loaded: boolean) => void;
2471
+ fontsLoadedTimeout?: number;
2472
+ }) => ZodFormFieldConfig<T>;
2241
2473
  /**
2242
2474
  * Create an input field
2475
+ *
2476
+ * @example
2477
+ * ```tsx
2478
+ * // Simple input
2479
+ * FormFieldHelpers.input("name", "Name")
2480
+ *
2481
+ * // With type
2482
+ * FormFieldHelpers.input("email", "Email", "email")
2483
+ *
2484
+ * // With full customization
2485
+ * FormFieldHelpers.input("email", "Email", "email", {
2486
+ * placeholder: "Enter your email",
2487
+ * classNames: { input: "custom-input" },
2488
+ * startContent: <MailIcon />,
2489
+ * description: "We'll never share your email"
2490
+ * })
2491
+ * ```
2243
2492
  */
2244
- input: <T extends FieldValues>(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password") => ZodFormFieldConfig<T>;
2493
+ input: <T extends FieldValues>(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password", inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2494
+ /**
2495
+ * Create a radio group field
2496
+ *
2497
+ * @example
2498
+ * ```tsx
2499
+ * // Simple radio group
2500
+ * FormFieldHelpers.radio("gender", "Gender", [
2501
+ * { label: "Male", value: "male" },
2502
+ * { label: "Female", value: "female" }
2503
+ * ])
2504
+ *
2505
+ * // With full customization
2506
+ * FormFieldHelpers.radio("gender", "Gender", options, {
2507
+ * orientation: "horizontal",
2508
+ * classNames: { base: "custom-radio" }
2509
+ * })
2510
+ * ```
2511
+ */
2512
+ radio: <T extends FieldValues>(name: Path<T>, label: string, options: {
2513
+ label: string;
2514
+ value: string | number;
2515
+ }[], radioProps?: Omit<React$1.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">) => ZodFormFieldConfig<T>;
2245
2516
  /**
2246
2517
  * Create a select field
2518
+ *
2519
+ * @example
2520
+ * ```tsx
2521
+ * // Simple select
2522
+ * FormFieldHelpers.select("country", "Country", options)
2523
+ *
2524
+ * // With full customization
2525
+ * FormFieldHelpers.select("country", "Country", options, {
2526
+ * placeholder: "Select a country",
2527
+ * classNames: { trigger: "custom-select" },
2528
+ * selectionMode: "multiple"
2529
+ * })
2530
+ * ```
2247
2531
  */
2248
2532
  select: <T extends FieldValues>(name: Path<T>, label: string, options: {
2249
2533
  label: string;
2250
2534
  value: string | number;
2251
- }[]) => ZodFormFieldConfig<T>;
2535
+ }[], selectProps?: Omit<React$1.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2536
+ /**
2537
+ * Create a slider field
2538
+ *
2539
+ * @example
2540
+ * ```tsx
2541
+ * // Simple slider
2542
+ * FormFieldHelpers.slider("rating", "Rating")
2543
+ *
2544
+ * // With full customization
2545
+ * FormFieldHelpers.slider("rating", "Rating", {
2546
+ * minValue: 1,
2547
+ * maxValue: 5,
2548
+ * step: 1,
2549
+ * showSteps: true,
2550
+ * classNames: { base: "custom-slider" }
2551
+ * })
2552
+ * ```
2553
+ */
2554
+ slider: <T extends FieldValues>(name: Path<T>, label: string, sliderProps?: Omit<React$1.ComponentProps<typeof Slider>, "value" | "onChange" | "label" | "isDisabled">) => ZodFormFieldConfig<T>;
2252
2555
  /**
2253
2556
  * Create a switch field
2557
+ *
2558
+ * @example
2559
+ * ```tsx
2560
+ * // Simple switch
2561
+ * FormFieldHelpers.switch("notifications", "Enable notifications")
2562
+ *
2563
+ * // With description
2564
+ * FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications")
2565
+ *
2566
+ * // With full customization
2567
+ * FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications", {
2568
+ * classNames: { base: "custom-switch" },
2569
+ * size: "lg",
2570
+ * color: "primary"
2571
+ * })
2572
+ * ```
2254
2573
  */
2255
- switch: <T extends FieldValues>(name: Path<T>, label: string, description?: string) => ZodFormFieldConfig<T>;
2574
+ switch: <T extends FieldValues>(name: Path<T>, label: string, description?: string, switchProps?: Omit<React$1.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2256
2575
  /**
2257
2576
  * Create a textarea field
2577
+ *
2578
+ * @example
2579
+ * ```tsx
2580
+ * // Simple textarea
2581
+ * FormFieldHelpers.textarea("message", "Message")
2582
+ *
2583
+ * // With placeholder
2584
+ * FormFieldHelpers.textarea("message", "Message", "Enter your message")
2585
+ *
2586
+ * // With full customization
2587
+ * FormFieldHelpers.textarea("message", "Message", "Enter your message", {
2588
+ * classNames: { input: "custom-textarea" },
2589
+ * minRows: 3,
2590
+ * maxRows: 10
2591
+ * })
2592
+ * ```
2258
2593
  */
2259
- textarea: <T extends FieldValues>(name: Path<T>, label: string, placeholder?: string) => ZodFormFieldConfig<T>;
2594
+ textarea: <T extends FieldValues>(name: Path<T>, label: string, placeholder?: string, textareaProps?: Omit<React$1.ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2260
2595
  };
2261
2596
  /**
2262
2597
  * Common field collections
@@ -2956,6 +3291,7 @@ interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
2956
3291
  * Allows users to add and remove multiple instances of a field group.
2957
3292
  * Useful for forms with repeating data like addresses, items, or contacts.
2958
3293
  * Automatically manages field array state and provides add/remove buttons.
3294
+ * Supports reordering, custom item rendering, default values, and conditional fields within items.
2959
3295
  *
2960
3296
  * @template TFieldValues - The form data type
2961
3297
  *
@@ -2966,42 +3302,101 @@ interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
2966
3302
  * @returns {JSX.Element} The rendered field array with add/remove controls
2967
3303
  *
2968
3304
  * @example
3305
+ * Basic usage:
2969
3306
  * ```tsx
2970
3307
  * import { FieldArrayField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
2971
3308
  *
2972
3309
  * const fields = [
2973
3310
  * FormFieldHelpers.input("name", "Name"),
2974
- * FieldArrayField({
2975
- * config: {
2976
- * name: "addresses",
2977
- * label: "Address",
2978
- * fields: [
2979
- * FormFieldHelpers.input("street", "Street Address"),
2980
- * FormFieldHelpers.input("city", "City"),
2981
- * FormFieldHelpers.input("zipCode", "ZIP Code"),
2982
- * ],
2983
- * min: 1,
2984
- * max: 5,
2985
- * addButtonText: "Add Address",
2986
- * removeButtonText: "Remove Address",
2987
- * },
2988
- * }),
3311
+ * {
3312
+ * type: "fieldArray",
3313
+ * name: "addresses",
3314
+ * label: "Address",
3315
+ * fields: [
3316
+ * FormFieldHelpers.input("street", "Street Address"),
3317
+ * FormFieldHelpers.input("city", "City"),
3318
+ * FormFieldHelpers.input("zipCode", "ZIP Code"),
3319
+ * ],
3320
+ * min: 1,
3321
+ * max: 5,
3322
+ * addButtonText: "Add Address",
3323
+ * removeButtonText: "Remove Address",
3324
+ * },
2989
3325
  * ];
2990
3326
  * ```
2991
3327
  *
2992
3328
  * @example
2993
- * With validation:
3329
+ * With reordering:
2994
3330
  * ```tsx
2995
- * const schema = z.object({
2996
- * addresses: z.array(z.object({
2997
- * street: z.string().min(1, "Street is required"),
2998
- * city: z.string().min(1, "City is required"),
2999
- * })).min(1, "At least one address is required"),
3000
- * });
3331
+ * {
3332
+ * type: "fieldArray",
3333
+ * name: "slots",
3334
+ * label: "Question Slots",
3335
+ * enableReordering: true,
3336
+ * reorderButtonText: { up: "↑", down: "↓" },
3337
+ * fields: [
3338
+ * FormFieldHelpers.select("slotType", "Slot Type", options),
3339
+ * ],
3340
+ * }
3341
+ * ```
3342
+ *
3343
+ * @example
3344
+ * With custom item rendering:
3345
+ * ```tsx
3346
+ * {
3347
+ * type: "fieldArray",
3348
+ * name: "items",
3349
+ * renderItem: ({ index, children, onMoveUp, onMoveDown, onRemove }) => (
3350
+ * <Card className="p-4">
3351
+ * <div className="flex justify-between">
3352
+ * <span>Item {index + 1}</span>
3353
+ * <Button onPress={onRemove}>Remove</Button>
3354
+ * </div>
3355
+ * {children}
3356
+ * </Card>
3357
+ * ),
3358
+ * fields: [...],
3359
+ * }
3360
+ * ```
3361
+ *
3362
+ * @example
3363
+ * With default item:
3364
+ * ```tsx
3365
+ * {
3366
+ * type: "fieldArray",
3367
+ * name: "slots",
3368
+ * defaultItem: () => ({
3369
+ * order: 0,
3370
+ * slotType: "STATIC",
3371
+ * staticQuestionId: "",
3372
+ * }),
3373
+ * fields: [...],
3374
+ * }
3375
+ * ```
3376
+ *
3377
+ * @example
3378
+ * With conditional fields within items:
3379
+ * ```tsx
3380
+ * {
3381
+ * type: "fieldArray",
3382
+ * name: "slots",
3383
+ * fields: [
3384
+ * FormFieldHelpers.select("slotType", "Slot Type", [
3385
+ * { label: "Static", value: "STATIC" },
3386
+ * { label: "Dynamic", value: "DYNAMIC" },
3387
+ * ]),
3388
+ * {
3389
+ * ...FormFieldHelpers.select("staticQuestionId", "Question", questions),
3390
+ * dependsOn: "slotType",
3391
+ * dependsOnValue: "STATIC",
3392
+ * },
3393
+ * ],
3394
+ * }
3001
3395
  * ```
3002
3396
  *
3003
3397
  * @see {@link ConditionalField} for conditional single fields
3004
3398
  * @see {@link DynamicSectionField} for conditional field groups
3399
+ * @see {@link createFieldArrayCustomConfig} for advanced custom rendering
3005
3400
  * @category Fields
3006
3401
  */
3007
3402
  declare function FieldArrayField<TFieldValues extends FieldValues>({ className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
@@ -3145,6 +3540,157 @@ declare function createOptimizedFieldHandler<T>(onChange: (value: T) => void, op
3145
3540
  */
3146
3541
  declare function useMemoizedFieldProps<T extends Record<string, any>>(props: T, deps: React.DependencyList): T;
3147
3542
 
3543
+ /**
3544
+ * Options for syncing arrays
3545
+ *
3546
+ * @template TItem - The item type in the arrays
3547
+ */
3548
+ interface ArraySyncOptions<TItem> {
3549
+ /** Existing items (from database/API) */
3550
+ existing: TItem[];
3551
+ /** Current items (from form) */
3552
+ current: TItem[];
3553
+ /** Function to extract ID from an item */
3554
+ getId: (item: TItem) => string | number | undefined;
3555
+ }
3556
+ /**
3557
+ * Result of array sync operation
3558
+ *
3559
+ * @template TItem - The item type in the arrays
3560
+ */
3561
+ interface ArraySyncResult<TItem> {
3562
+ /** Items that should be deleted (exist in existing but not in current) */
3563
+ toDelete: TItem[];
3564
+ /** Items that should be updated (exist in both, may have changed) */
3565
+ toUpdate: {
3566
+ existing: TItem;
3567
+ current: TItem;
3568
+ }[];
3569
+ /** Items that should be created (exist in current but not in existing) */
3570
+ toCreate: TItem[];
3571
+ }
3572
+ /**
3573
+ * Sync arrays to determine what items to delete, update, and create.
3574
+ *
3575
+ * @description
3576
+ * Compares existing items (from database) with current items (from form)
3577
+ * to determine which items need to be deleted, updated, or created.
3578
+ * Useful for edit forms where you need to sync array changes.
3579
+ *
3580
+ * @template TItem - The item type in the arrays
3581
+ *
3582
+ * @param {ArraySyncOptions<TItem>} options - Sync options
3583
+ * @returns {ArraySyncResult<TItem>} Result with items to delete, update, and create
3584
+ *
3585
+ * @example
3586
+ * ```tsx
3587
+ * const { toDelete, toUpdate, toCreate } = syncArrays({
3588
+ * existing: slots,
3589
+ * current: data.slots,
3590
+ * getId: (slot) => slot.id,
3591
+ * });
3592
+ *
3593
+ * // Delete removed slots
3594
+ * await Promise.all(toDelete.map(slot => deleteSlot(slot.id)));
3595
+ *
3596
+ * // Update existing slots
3597
+ * await Promise.all(
3598
+ * toUpdate.map(({ existing, current }) =>
3599
+ * updateSlot(existing.id, current)
3600
+ * )
3601
+ * );
3602
+ *
3603
+ * // Create new slots
3604
+ * await Promise.all(toCreate.map(slot => createSlot(slot)));
3605
+ * ```
3606
+ *
3607
+ * @category Utilities
3608
+ */
3609
+ declare function syncArrays<TItem>(options: ArraySyncOptions<TItem>): ArraySyncResult<TItem>;
3610
+
3611
+ /**
3612
+ * Options for creating a custom field array config
3613
+ *
3614
+ * @template TFieldValues - The form data type
3615
+ */
3616
+ interface CreateFieldArrayCustomConfigOptions<TFieldValues extends FieldValues> {
3617
+ /** Field array name */
3618
+ name: ArrayPath<TFieldValues>;
3619
+ /** Optional label for the field array */
3620
+ label?: string;
3621
+ /** Render function for each array item */
3622
+ renderItem: (props: {
3623
+ index: number;
3624
+ field: FieldArrayWithId<TFieldValues, ArrayPath<TFieldValues>>;
3625
+ fields: FieldArrayWithId<TFieldValues, ArrayPath<TFieldValues>>[];
3626
+ form: UseFormReturn<TFieldValues>;
3627
+ control: Control<TFieldValues>;
3628
+ errors: FieldErrors<TFieldValues>;
3629
+ canMoveUp: boolean;
3630
+ canMoveDown: boolean;
3631
+ onMoveUp: () => void;
3632
+ onMoveDown: () => void;
3633
+ onRemove: () => void;
3634
+ }) => React$1.ReactNode;
3635
+ /** Optional render function for add button */
3636
+ renderAddButton?: (props: {
3637
+ onAdd: () => void;
3638
+ canAdd: boolean;
3639
+ }) => React$1.ReactNode;
3640
+ /** Function to create default item when adding new array item */
3641
+ defaultItem?: () => any;
3642
+ /** Minimum number of items */
3643
+ min?: number;
3644
+ /** Maximum number of items */
3645
+ max?: number;
3646
+ /** Enable reordering of array items */
3647
+ enableReordering?: boolean;
3648
+ /** Optional className */
3649
+ className?: string;
3650
+ }
3651
+ /**
3652
+ * Create a CustomFieldConfig for field arrays with full control over rendering.
3653
+ *
3654
+ * @description
3655
+ * This helper creates a CustomFieldConfig that uses useFieldArray internally,
3656
+ * giving you full control over the UI while still being integrated with the form.
3657
+ * Useful when you need custom layouts, reordering, or complex item rendering
3658
+ * that FieldArrayConfig doesn't support.
3659
+ *
3660
+ * @template TFieldValues - The form data type
3661
+ *
3662
+ * @param {CreateFieldArrayCustomConfigOptions<TFieldValues>} options - Configuration options
3663
+ * @returns {CustomFieldConfig<TFieldValues>} Custom field config for field arrays
3664
+ *
3665
+ * @example
3666
+ * ```tsx
3667
+ * const slotsConfig = createFieldArrayCustomConfig("slots", {
3668
+ * label: "Question Slots",
3669
+ * enableReordering: true,
3670
+ * renderItem: ({ index, field, form, control, onMoveUp, onMoveDown, onRemove }) => (
3671
+ * <div className="border rounded-lg p-4">
3672
+ * <div className="flex justify-between">
3673
+ * <span>Slot {index + 1}</span>
3674
+ * <div className="flex gap-2">
3675
+ * <Button onPress={onMoveUp}>↑</Button>
3676
+ * <Button onPress={onMoveDown}>↓</Button>
3677
+ * <Button onPress={onRemove}>Remove</Button>
3678
+ * </div>
3679
+ * </div>
3680
+ * <SelectField
3681
+ * name={`slots.${index}.slotType`}
3682
+ * control={control}
3683
+ * // ...
3684
+ * />
3685
+ * </div>
3686
+ * ),
3687
+ * });
3688
+ * ```
3689
+ *
3690
+ * @category Utilities
3691
+ */
3692
+ declare function createFieldArrayCustomConfig<TFieldValues extends FieldValues>(options: CreateFieldArrayCustomConfigOptions<TFieldValues>): CustomFieldConfig<TFieldValues>;
3693
+
3148
3694
  /**
3149
3695
  * Common validation patterns for forms
3150
3696
  */
@@ -3228,4 +3774,4 @@ declare const validationUtils: {
3228
3774
  }>;
3229
3775
  };
3230
3776
 
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 };
3777
+ export { AdvancedFieldBuilder, type ArraySyncOptions, type ArraySyncResult, 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 CreateFieldArrayCustomConfigOptions, 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, SimpleForm, type SimpleFormProps, 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, createFieldArrayCustomConfig, 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, syncArrays, throttle, useDebouncedFieldValidation, useDebouncedValidation, useEnhancedFormState, useFormHelper, useHeroForm, useHeroHookFormDefaults, useInferredForm, useMemoizedCallback, useMemoizedFieldProps, usePerformanceMonitor, useTypeInferredForm, useZodForm, validationPatterns, validationUtils, waitForFormState };