@rachelallyson/hero-hook-form 2.4.0 → 2.6.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,5 +1,5 @@
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
4
  import { FieldValues, Path, RegisterOptions, Control, UseFormReturn, FieldErrors, UseFormProps, SubmitHandler, UseFormSetError } from 'react-hook-form';
5
5
  export { UseFormReturn, useFormContext } from 'react-hook-form';
@@ -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";
@@ -2074,6 +2079,13 @@ declare class BasicFormBuilder<T extends FieldValues> {
2074
2079
  label: string;
2075
2080
  value: string | number;
2076
2081
  }[]): this;
2082
+ /**
2083
+ * Add an autocomplete field
2084
+ */
2085
+ autocomplete(name: Path<T>, label: string, items: {
2086
+ label: string;
2087
+ value: string | number;
2088
+ }[], placeholder?: string): this;
2077
2089
  /**
2078
2090
  * Add a checkbox field
2079
2091
  */
@@ -2171,15 +2183,42 @@ declare function createBasicFormBuilder<T extends FieldValues>(): BasicFormBuild
2171
2183
  declare const FormFieldHelpers: {
2172
2184
  /**
2173
2185
  * Create an autocomplete field
2186
+ *
2187
+ * @example
2188
+ * ```tsx
2189
+ * // Simple autocomplete
2190
+ * FormFieldHelpers.autocomplete("country", "Country", options)
2191
+ *
2192
+ * // With placeholder
2193
+ * FormFieldHelpers.autocomplete("country", "Country", options, "Search countries")
2194
+ *
2195
+ * // With full customization
2196
+ * FormFieldHelpers.autocomplete("country", "Country", options, "Search countries", {
2197
+ * classNames: { base: "custom-autocomplete" },
2198
+ * allowsCustomValue: true
2199
+ * })
2200
+ * ```
2174
2201
  */
2175
2202
  autocomplete: <T extends FieldValues>(name: Path<T>, label: string, items: {
2176
2203
  label: string;
2177
2204
  value: string | number;
2178
- }[], placeholder?: string) => ZodFormFieldConfig<T>;
2205
+ }[], placeholder?: string, autocompleteProps?: Omit<React$1.ComponentProps<typeof Autocomplete>, "selectedKey" | "onSelectionChange" | "inputValue" | "onInputChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "children" | "items">) => ZodFormFieldConfig<T>;
2179
2206
  /**
2180
2207
  * Create a checkbox field
2208
+ *
2209
+ * @example
2210
+ * ```tsx
2211
+ * // Simple checkbox
2212
+ * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter")
2213
+ *
2214
+ * // With full customization
2215
+ * FormFieldHelpers.checkbox("newsletter", "Subscribe to newsletter", {
2216
+ * classNames: { base: "custom-checkbox" },
2217
+ * size: "lg"
2218
+ * })
2219
+ * ```
2181
2220
  */
2182
- checkbox: <T extends FieldValues>(name: Path<T>, label: string) => ZodFormFieldConfig<T>;
2221
+ checkbox: <T extends FieldValues>(name: Path<T>, label: string, checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2183
2222
  /**
2184
2223
  * Create a conditional field that shows/hides based on form data
2185
2224
  *
@@ -2191,8 +2230,19 @@ declare const FormFieldHelpers: {
2191
2230
  * FormFieldHelpers.input("phone", "Phone Number", "tel")
2192
2231
  * )
2193
2232
  * ```
2233
+ *
2234
+ * @example
2235
+ * With explicit type in condition function (similar to content helper pattern):
2236
+ * ```tsx
2237
+ * FormFieldHelpers.conditional(
2238
+ * "options",
2239
+ * (formData: Partial<z.infer<typeof fieldSchema>>) =>
2240
+ * formData.fieldType === 'DROPDOWN',
2241
+ * FormFieldHelpers.textarea("options", "Dropdown Options", "One per line")
2242
+ * )
2243
+ * ```
2194
2244
  */
2195
- conditional: <T extends FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
2245
+ conditional: <T extends FieldValues = FieldValues>(name: Path<T>, condition: (formData: Partial<T>) => boolean, field: ZodFormFieldConfig<T>) => ZodFormFieldConfig<T>;
2196
2246
  /**
2197
2247
  * Create a content field for headers, questions, or custom content between fields
2198
2248
  *
@@ -2218,27 +2268,192 @@ declare const FormFieldHelpers: {
2218
2268
  }) => ZodFormFieldConfig<T>;
2219
2269
  /**
2220
2270
  * Create a date field
2271
+ *
2272
+ * @example
2273
+ * ```tsx
2274
+ * // Simple date field
2275
+ * FormFieldHelpers.date("birthDate", "Birth Date")
2276
+ *
2277
+ * // With full customization
2278
+ * FormFieldHelpers.date("birthDate", "Birth Date", {
2279
+ * label: "Select your birth date",
2280
+ * granularity: "day",
2281
+ * minValue: new CalendarDate(1900, 1, 1)
2282
+ * })
2283
+ * ```
2284
+ */
2285
+ date: <T extends FieldValues>(name: Path<T>, label: string, dateProps?: Omit<React$1.ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2286
+ /**
2287
+ * Create a file upload field
2288
+ *
2289
+ * @example
2290
+ * ```tsx
2291
+ * // Simple file field
2292
+ * FormFieldHelpers.file("avatar", "Profile Picture")
2293
+ *
2294
+ * // With accept and multiple
2295
+ * FormFieldHelpers.file("avatar", "Profile Picture", {
2296
+ * accept: "image/*",
2297
+ * multiple: true
2298
+ * })
2299
+ *
2300
+ * // With full customization
2301
+ * FormFieldHelpers.file("avatar", "Profile Picture", {
2302
+ * accept: "image/*",
2303
+ * multiple: false,
2304
+ * fileProps: { className: "custom-file-input" }
2305
+ * })
2306
+ * ```
2307
+ */
2308
+ file: <T extends FieldValues>(name: Path<T>, label: string, options?: {
2309
+ accept?: string;
2310
+ fileProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "type">;
2311
+ multiple?: boolean;
2312
+ }) => ZodFormFieldConfig<T>;
2313
+ /**
2314
+ * Create a font picker field
2315
+ *
2316
+ * @example
2317
+ * ```tsx
2318
+ * // Simple font picker
2319
+ * FormFieldHelpers.fontPicker("font", "Choose Font")
2320
+ *
2321
+ * // With full customization
2322
+ * FormFieldHelpers.fontPicker("font", "Choose Font", {
2323
+ * showFontPreview: true,
2324
+ * loadAllVariants: false,
2325
+ * fontsLoadedTimeout: 5000
2326
+ * })
2327
+ * ```
2221
2328
  */
2222
- date: <T extends FieldValues>(name: Path<T>, label: string, dateProps?: Record<string, string | number | boolean>) => ZodFormFieldConfig<T>;
2329
+ fontPicker: <T extends FieldValues>(name: Path<T>, label: string, fontPickerProps?: {
2330
+ showFontPreview?: boolean;
2331
+ loadAllVariants?: boolean;
2332
+ onFontsLoaded?: (loaded: boolean) => void;
2333
+ fontsLoadedTimeout?: number;
2334
+ }) => ZodFormFieldConfig<T>;
2223
2335
  /**
2224
2336
  * Create an input field
2337
+ *
2338
+ * @example
2339
+ * ```tsx
2340
+ * // Simple input
2341
+ * FormFieldHelpers.input("name", "Name")
2342
+ *
2343
+ * // With type
2344
+ * FormFieldHelpers.input("email", "Email", "email")
2345
+ *
2346
+ * // With full customization
2347
+ * FormFieldHelpers.input("email", "Email", "email", {
2348
+ * placeholder: "Enter your email",
2349
+ * classNames: { input: "custom-input" },
2350
+ * startContent: <MailIcon />,
2351
+ * description: "We'll never share your email"
2352
+ * })
2353
+ * ```
2225
2354
  */
2226
- input: <T extends FieldValues>(name: Path<T>, label: string, type?: "text" | "email" | "tel" | "password") => ZodFormFieldConfig<T>;
2355
+ 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>;
2356
+ /**
2357
+ * Create a radio group field
2358
+ *
2359
+ * @example
2360
+ * ```tsx
2361
+ * // Simple radio group
2362
+ * FormFieldHelpers.radio("gender", "Gender", [
2363
+ * { label: "Male", value: "male" },
2364
+ * { label: "Female", value: "female" }
2365
+ * ])
2366
+ *
2367
+ * // With full customization
2368
+ * FormFieldHelpers.radio("gender", "Gender", options, {
2369
+ * orientation: "horizontal",
2370
+ * classNames: { base: "custom-radio" }
2371
+ * })
2372
+ * ```
2373
+ */
2374
+ radio: <T extends FieldValues>(name: Path<T>, label: string, options: {
2375
+ label: string;
2376
+ value: string | number;
2377
+ }[], radioProps?: Omit<React$1.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">) => ZodFormFieldConfig<T>;
2227
2378
  /**
2228
2379
  * Create a select field
2380
+ *
2381
+ * @example
2382
+ * ```tsx
2383
+ * // Simple select
2384
+ * FormFieldHelpers.select("country", "Country", options)
2385
+ *
2386
+ * // With full customization
2387
+ * FormFieldHelpers.select("country", "Country", options, {
2388
+ * placeholder: "Select a country",
2389
+ * classNames: { trigger: "custom-select" },
2390
+ * selectionMode: "multiple"
2391
+ * })
2392
+ * ```
2229
2393
  */
2230
2394
  select: <T extends FieldValues>(name: Path<T>, label: string, options: {
2231
2395
  label: string;
2232
2396
  value: string | number;
2233
- }[]) => ZodFormFieldConfig<T>;
2397
+ }[], selectProps?: Omit<React$1.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">) => ZodFormFieldConfig<T>;
2398
+ /**
2399
+ * Create a slider field
2400
+ *
2401
+ * @example
2402
+ * ```tsx
2403
+ * // Simple slider
2404
+ * FormFieldHelpers.slider("rating", "Rating")
2405
+ *
2406
+ * // With full customization
2407
+ * FormFieldHelpers.slider("rating", "Rating", {
2408
+ * minValue: 1,
2409
+ * maxValue: 5,
2410
+ * step: 1,
2411
+ * showSteps: true,
2412
+ * classNames: { base: "custom-slider" }
2413
+ * })
2414
+ * ```
2415
+ */
2416
+ slider: <T extends FieldValues>(name: Path<T>, label: string, sliderProps?: Omit<React$1.ComponentProps<typeof Slider>, "value" | "onChange" | "label" | "isDisabled">) => ZodFormFieldConfig<T>;
2234
2417
  /**
2235
2418
  * Create a switch field
2419
+ *
2420
+ * @example
2421
+ * ```tsx
2422
+ * // Simple switch
2423
+ * FormFieldHelpers.switch("notifications", "Enable notifications")
2424
+ *
2425
+ * // With description
2426
+ * FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications")
2427
+ *
2428
+ * // With full customization
2429
+ * FormFieldHelpers.switch("notifications", "Enable notifications", "Receive email notifications", {
2430
+ * classNames: { base: "custom-switch" },
2431
+ * size: "lg",
2432
+ * color: "primary"
2433
+ * })
2434
+ * ```
2236
2435
  */
2237
- switch: <T extends FieldValues>(name: Path<T>, label: string, description?: string) => ZodFormFieldConfig<T>;
2436
+ 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>;
2238
2437
  /**
2239
2438
  * Create a textarea field
2439
+ *
2440
+ * @example
2441
+ * ```tsx
2442
+ * // Simple textarea
2443
+ * FormFieldHelpers.textarea("message", "Message")
2444
+ *
2445
+ * // With placeholder
2446
+ * FormFieldHelpers.textarea("message", "Message", "Enter your message")
2447
+ *
2448
+ * // With full customization
2449
+ * FormFieldHelpers.textarea("message", "Message", "Enter your message", {
2450
+ * classNames: { input: "custom-textarea" },
2451
+ * minRows: 3,
2452
+ * maxRows: 10
2453
+ * })
2454
+ * ```
2240
2455
  */
2241
- textarea: <T extends FieldValues>(name: Path<T>, label: string, placeholder?: string) => ZodFormFieldConfig<T>;
2456
+ 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>;
2242
2457
  };
2243
2458
  /**
2244
2459
  * Common field collections