@rachelallyson/hero-hook-form 1.0.0 → 1.1.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/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- import React, { ComponentProps } from 'react';
1
+ import React$1, { ComponentProps } from 'react';
2
2
  import { Button } from '@heroui/react';
3
3
  import * as react_hook_form from 'react-hook-form';
4
- import { FieldValues, Path, RegisterOptions, Control, UseFormProps, SubmitHandler, UseFormReturn, UseFormSetError } from 'react-hook-form';
4
+ import { FieldValues, Path, RegisterOptions, Control, UseFormReturn, FieldErrors, UseFormProps, SubmitHandler, UseFormSetError } from 'react-hook-form';
5
+ export { UseFormReturn, useFormContext } from 'react-hook-form';
5
6
  import * as zod from 'zod';
7
+ import { z } from 'zod';
6
8
  import * as _internationalized_date from '@internationalized/date';
7
9
  import { CalendarDate } from '@internationalized/date';
8
10
  import { Checkbox } from '@heroui/checkbox';
@@ -37,7 +39,11 @@ interface BaseFormFieldConfig<TFieldValues extends FieldValues> {
37
39
  isDisabled?: boolean;
38
40
  rules?: RegisterOptions<TFieldValues, Path<TFieldValues>>;
39
41
  condition?: (values: Partial<TFieldValues>) => boolean;
42
+ dependsOn?: Path<TFieldValues>;
43
+ dependsOnValue?: unknown;
40
44
  group?: string;
45
+ ariaLabel?: string;
46
+ ariaDescribedBy?: string;
41
47
  }
42
48
  interface StringFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
43
49
  type: "input" | "textarea" | "select";
@@ -82,7 +88,22 @@ interface FileFieldConfig<TFieldValues extends FieldValues> extends BaseFormFiel
82
88
  multiple?: boolean;
83
89
  accept?: string;
84
90
  }
85
- type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues>;
91
+ interface FontPickerFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
92
+ type: "fontPicker";
93
+ defaultValue?: string;
94
+ fontPickerProps?: Record<string, string | number | boolean>;
95
+ }
96
+ interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
97
+ type: "custom";
98
+ render: (field: {
99
+ name: Path<TFieldValues>;
100
+ control: Control<TFieldValues>;
101
+ form: UseFormReturn<TFieldValues>;
102
+ errors: FieldErrors<TFieldValues>;
103
+ isSubmitting: boolean;
104
+ }) => React.ReactNode;
105
+ }
106
+ type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | FontPickerFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues>;
86
107
  interface FormConfig<TFieldValues extends FieldValues> {
87
108
  fields: FormFieldConfig<TFieldValues>[];
88
109
  layout?: "vertical" | "horizontal" | "grid" | "custom";
@@ -96,10 +117,20 @@ interface FormConfig<TFieldValues extends FieldValues> {
96
117
  className?: string;
97
118
  defaultValues?: Partial<TFieldValues>;
98
119
  }
99
- type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules">;
120
+ type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules"> | Omit<FontPickerFieldConfig<TFieldValues>, "rules">;
100
121
  interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
101
- schema?: zod.ZodSchema<TFieldValues>;
122
+ schema: zod.ZodSchema<TFieldValues>;
102
123
  fields: ZodFormFieldConfig<TFieldValues>[];
124
+ onError?: (errors: FieldErrors<TFieldValues>) => void;
125
+ errorDisplay?: "inline" | "toast" | "modal" | "none";
126
+ render?: (formState: {
127
+ form: UseFormReturn<TFieldValues>;
128
+ isSubmitting: boolean;
129
+ isSubmitted: boolean;
130
+ isSuccess: boolean;
131
+ errors: FieldErrors<TFieldValues>;
132
+ values: TFieldValues;
133
+ }) => React.ReactNode;
103
134
  }
104
135
  interface FormValidationError {
105
136
  message: string;
@@ -137,6 +168,33 @@ interface FieldGroup<TFieldValues extends FieldValues> {
137
168
  defaultCollapsed?: boolean;
138
169
  fields: FormFieldConfig<TFieldValues>[];
139
170
  }
171
+ interface ValidationUtils {
172
+ createMinLengthSchema: (min: number, fieldName: string) => zod.ZodString;
173
+ createMaxLengthSchema: (max: number, fieldName: string) => zod.ZodString;
174
+ createEmailSchema: () => zod.ZodString;
175
+ createRequiredSchema: (fieldName: string) => zod.ZodString;
176
+ createUrlSchema: () => zod.ZodString;
177
+ createPhoneSchema: () => zod.ZodString;
178
+ }
179
+ interface FormTestUtils<TFieldValues extends FieldValues> {
180
+ getField: (name: Path<TFieldValues>) => {
181
+ value: unknown;
182
+ error: unknown;
183
+ isDirty: boolean;
184
+ isTouched: boolean;
185
+ };
186
+ submitForm: () => Promise<void>;
187
+ resetForm: () => void;
188
+ getFormState: () => {
189
+ values: TFieldValues;
190
+ errors: FieldErrors<TFieldValues>;
191
+ isSubmitting: boolean;
192
+ isSubmitted: boolean;
193
+ isSuccess: boolean;
194
+ };
195
+ setFieldValue: (name: Path<TFieldValues>, value: unknown) => void;
196
+ triggerValidation: (name?: Path<TFieldValues>) => Promise<boolean>;
197
+ }
140
198
 
141
199
  interface FormProps$1<T extends FieldValues> {
142
200
  className?: string;
@@ -149,45 +207,56 @@ interface FormProps$1<T extends FieldValues> {
149
207
  resetButtonText?: string;
150
208
  showResetButton?: boolean;
151
209
  spacing?: "2" | "4" | "6" | "8" | "lg";
152
- submitButtonProps?: Partial<React.ComponentProps<typeof Button>>;
210
+ submitButtonProps?: Partial<React$1.ComponentProps<typeof Button>>;
153
211
  submitButtonText?: string;
154
212
  subtitle?: string;
155
213
  title?: string;
156
214
  defaultValues?: Partial<T>;
157
215
  }
158
- declare function ConfigurableForm<T extends FieldValues>({ className, columns, defaultValues, fields, layout, onError, onSubmit, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: FormProps$1<T>): React.JSX.Element;
216
+ declare function ConfigurableForm<T extends FieldValues>({ className, columns, defaultValues, fields, layout, onError, onSubmit, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: FormProps$1<T>): React$1.JSX.Element;
159
217
 
160
218
  interface FormFieldProps<TFieldValues extends FieldValues> {
161
219
  config: FormFieldConfig<TFieldValues>;
162
220
  form: UseFormReturn<TFieldValues>;
163
221
  submissionState: FormSubmissionState;
164
222
  }
165
- declare function FormField<TFieldValues extends FieldValues>({ config, form, submissionState, }: FormFieldProps<TFieldValues>): React.JSX.Element | null;
223
+ declare function FormField<TFieldValues extends FieldValues>({ config, form, submissionState, }: FormFieldProps<TFieldValues>): string | number | bigint | boolean | Iterable<React$1.ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<React$1.ReactNode> | null | undefined> | React$1.JSX.Element | null | undefined;
166
224
 
167
225
  type CheckboxFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
168
- checkboxProps?: Omit<React.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
226
+ checkboxProps?: Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
169
227
  };
170
- declare function CheckboxField<TFieldValues extends FieldValues>(props: CheckboxFieldProps<TFieldValues>): React.JSX.Element;
228
+ declare function CheckboxField<TFieldValues extends FieldValues>(props: CheckboxFieldProps<TFieldValues>): React$1.JSX.Element;
171
229
 
172
230
  type DateFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, CalendarDate | null> & WithControl<TFieldValues> & {
173
- dateProps?: Omit<React.ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
231
+ dateProps?: Omit<React$1.ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
174
232
  transform?: (value: CalendarDate | null) => CalendarDate | null;
175
233
  };
176
- declare function DateField<TFieldValues extends FieldValues>(props: DateFieldProps<TFieldValues>): React.JSX.Element;
234
+ declare function DateField<TFieldValues extends FieldValues>(props: DateFieldProps<TFieldValues>): React$1.JSX.Element;
177
235
 
178
236
  type FileFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, FileList | null> & WithControl<TFieldValues> & {
179
- fileProps?: Omit<React.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "type">;
237
+ fileProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled" | "type">;
180
238
  transform?: (value: FileList | null) => FileList | null;
181
239
  multiple?: boolean;
182
240
  accept?: string;
183
241
  };
184
- declare function FileField<TFieldValues extends FieldValues>(props: FileFieldProps<TFieldValues>): React.JSX.Element;
242
+ declare function FileField<TFieldValues extends FieldValues>(props: FileFieldProps<TFieldValues>): React$1.JSX.Element;
243
+
244
+ interface FontPickerProps {
245
+ showFontPreview?: boolean;
246
+ loadAllVariants?: boolean;
247
+ onFontsLoaded?: (loaded: boolean) => void;
248
+ fontsLoadedTimeout?: number;
249
+ }
250
+ type FontPickerFieldProps<TFieldValues extends FieldValues, TValue extends string = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
251
+ fontPickerProps?: FontPickerProps;
252
+ };
253
+ declare function FontPickerField<TFieldValues extends FieldValues, TValue extends string = string>(props: FontPickerFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
185
254
 
186
255
  type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
187
- inputProps?: Omit<React.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
256
+ inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
188
257
  transform?: (value: string) => string;
189
258
  };
190
- declare function InputField<TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>): React.JSX.Element;
259
+ declare function InputField<TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>): React$1.JSX.Element;
191
260
 
192
261
  interface RadioOption<TValue extends string | number> {
193
262
  label: string;
@@ -197,9 +266,9 @@ interface RadioOption<TValue extends string | number> {
197
266
  }
198
267
  type RadioGroupFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
199
268
  options: readonly RadioOption<TValue>[];
200
- radioGroupProps?: Omit<React.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">;
269
+ radioGroupProps?: Omit<React$1.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">;
201
270
  };
202
- declare function RadioGroupField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: RadioGroupFieldProps<TFieldValues, TValue>): React.JSX.Element;
271
+ declare function RadioGroupField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: RadioGroupFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
203
272
 
204
273
  interface SelectOption<TValue extends string | number> {
205
274
  label: string;
@@ -210,25 +279,25 @@ interface SelectOption<TValue extends string | number> {
210
279
  type SelectFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
211
280
  options: readonly SelectOption<TValue>[];
212
281
  placeholder?: string;
213
- selectProps?: Omit<React.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
282
+ selectProps?: Omit<React$1.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
214
283
  };
215
- declare function SelectField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: SelectFieldProps<TFieldValues, TValue>): React.JSX.Element;
284
+ declare function SelectField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: SelectFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
216
285
 
217
286
  type SliderFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, number> & WithControl<TFieldValues> & {
218
- sliderProps?: Omit<React.ComponentProps<typeof Slider>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
287
+ sliderProps?: Omit<React$1.ComponentProps<typeof Slider>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
219
288
  transform?: (value: number) => number;
220
289
  };
221
- declare function SliderField<TFieldValues extends FieldValues>(props: SliderFieldProps<TFieldValues>): React.JSX.Element;
290
+ declare function SliderField<TFieldValues extends FieldValues>(props: SliderFieldProps<TFieldValues>): React$1.JSX.Element;
222
291
 
223
292
  type SwitchFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
224
- switchProps?: Omit<React.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">;
293
+ switchProps?: Omit<React$1.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">;
225
294
  };
226
- declare function SwitchField<TFieldValues extends FieldValues>(props: SwitchFieldProps<TFieldValues>): React.JSX.Element;
295
+ declare function SwitchField<TFieldValues extends FieldValues>(props: SwitchFieldProps<TFieldValues>): React$1.JSX.Element;
227
296
 
228
297
  type TextareaFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
229
- textareaProps?: Omit<React.ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
298
+ textareaProps?: Omit<React$1.ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
230
299
  };
231
- declare function TextareaField<TFieldValues extends FieldValues>(props: TextareaFieldProps<TFieldValues>): React.JSX.Element;
300
+ declare function TextareaField<TFieldValues extends FieldValues>(props: TextareaFieldProps<TFieldValues>): React$1.JSX.Element;
232
301
 
233
302
  interface UseFormHelperOptions<T extends FieldValues> {
234
303
  onError?: (error: FormValidationError) => void;
@@ -248,9 +317,57 @@ declare function useFormHelper<T extends FieldValues>({ defaultValues, methods,
248
317
  submissionState: FormSubmissionState;
249
318
  };
250
319
 
251
- type InputProps = React.ComponentProps<typeof Input>;
252
- type TextareaProps = React.ComponentProps<typeof Textarea>;
253
- type SelectProps = React.ComponentProps<typeof Select>;
320
+ /**
321
+ * Enhanced hook that provides both form methods and styling defaults
322
+ *
323
+ * This hook combines React Hook Form's useFormContext with Hero Hook Form's
324
+ * styling defaults, giving you access to both form functionality and
325
+ * component styling in one convenient hook.
326
+ *
327
+ * @example
328
+ * ```tsx
329
+ * import { useHeroForm } from "@rachelallyson/hero-hook-form";
330
+ *
331
+ * function MyComponent() {
332
+ * const { formState, getValues, setValue, defaults } = useHeroForm();
333
+ *
334
+ * // Access form state
335
+ * const isSubmitting = formState.isSubmitting;
336
+ * const errors = formState.errors;
337
+ *
338
+ * // Access form methods
339
+ * const values = getValues();
340
+ * const handleReset = () => setValue('fieldName', '');
341
+ *
342
+ * // Access styling defaults
343
+ * const inputDefaults = defaults.input;
344
+ * const buttonDefaults = defaults.submitButton;
345
+ * }
346
+ * ```
347
+ */
348
+ declare function useHeroForm<TFieldValues extends FieldValues>(): {
349
+ defaults: Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "select" | "switch" | "radioGroup" | "checkbox" | "slider" | "dateInput" | "submitButton">>;
350
+ watch: react_hook_form.UseFormWatch<TFieldValues>;
351
+ getValues: react_hook_form.UseFormGetValues<TFieldValues>;
352
+ getFieldState: react_hook_form.UseFormGetFieldState<TFieldValues>;
353
+ setError: react_hook_form.UseFormSetError<TFieldValues>;
354
+ clearErrors: react_hook_form.UseFormClearErrors<TFieldValues>;
355
+ setValue: react_hook_form.UseFormSetValue<TFieldValues>;
356
+ trigger: react_hook_form.UseFormTrigger<TFieldValues>;
357
+ formState: react_hook_form.FormState<TFieldValues>;
358
+ resetField: react_hook_form.UseFormResetField<TFieldValues>;
359
+ reset: react_hook_form.UseFormReset<TFieldValues>;
360
+ handleSubmit: react_hook_form.UseFormHandleSubmit<TFieldValues, TFieldValues>;
361
+ unregister: react_hook_form.UseFormUnregister<TFieldValues>;
362
+ control: react_hook_form.Control<TFieldValues, any, TFieldValues>;
363
+ register: react_hook_form.UseFormRegister<TFieldValues>;
364
+ setFocus: react_hook_form.UseFormSetFocus<TFieldValues>;
365
+ subscribe: react_hook_form.UseFormSubscribe<TFieldValues>;
366
+ };
367
+
368
+ type InputProps = React$1.ComponentProps<typeof Input>;
369
+ type TextareaProps = React$1.ComponentProps<typeof Textarea>;
370
+ type SelectProps = React$1.ComponentProps<typeof Select>;
254
371
  type SharedTextLikeColor = Extract<InputProps["color"], Extract<TextareaProps["color"], SelectProps["color"]>>;
255
372
  type SharedTextLikeSize = Extract<InputProps["size"], Extract<TextareaProps["size"], SelectProps["size"]>>;
256
373
  type SharedTextLikeVariant = Extract<InputProps["variant"], Extract<TextareaProps["variant"], SelectProps["variant"]>>;
@@ -265,13 +382,13 @@ type CommonFieldDefaults = Partial<{
265
382
  }>;
266
383
  type InputDefaults = Partial<Omit<InputProps, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
267
384
  type TextareaDefaults = Partial<Omit<TextareaProps, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
268
- type CheckboxDefaults = Partial<Omit<React.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">>;
269
- type RadioGroupDefaults = Partial<Omit<React.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">>;
385
+ type CheckboxDefaults = Partial<Omit<React$1.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">>;
386
+ type RadioGroupDefaults = Partial<Omit<React$1.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">>;
270
387
  type SelectDefaults = Partial<Omit<SelectProps, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
271
- type DateInputDefaults = Partial<Omit<React.ComponentProps<typeof DateInput>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
272
- type SliderDefaults = Partial<Omit<React.ComponentProps<typeof Slider>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
273
- type SwitchDefaults = Partial<Omit<React.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">>;
274
- type ButtonDefaults = Partial<Omit<React.ComponentProps<typeof Button$1>, "type" | "isLoading">>;
388
+ type DateInputDefaults = Partial<Omit<React$1.ComponentProps<typeof DateInput>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
389
+ type SliderDefaults = Partial<Omit<React$1.ComponentProps<typeof Slider>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
390
+ type SwitchDefaults = Partial<Omit<React$1.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">>;
391
+ type ButtonDefaults = Partial<Omit<React$1.ComponentProps<typeof Button$1>, "type" | "isLoading">>;
275
392
  interface HeroHookFormDefaultsConfig {
276
393
  common?: CommonFieldDefaults;
277
394
  input?: InputDefaults;
@@ -285,28 +402,28 @@ interface HeroHookFormDefaultsConfig {
285
402
  submitButton?: ButtonDefaults;
286
403
  }
287
404
  interface HeroHookFormProviderProps {
288
- children: React.ReactNode;
405
+ children: React$1.ReactNode;
289
406
  defaults?: HeroHookFormDefaultsConfig;
290
407
  }
291
- declare function HeroHookFormProvider(props: HeroHookFormProviderProps): React.JSX.Element;
408
+ declare function HeroHookFormProvider(props: HeroHookFormProviderProps): React$1.JSX.Element;
292
409
  declare function useHeroHookFormDefaults(): Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "checkbox" | "radioGroup" | "select" | "dateInput" | "slider" | "switch" | "submitButton">>;
293
410
 
294
411
  interface FormProps<TFieldValues extends FieldValues> {
295
412
  methods: UseFormReturn<TFieldValues>;
296
413
  onSubmit: SubmitHandler<TFieldValues>;
297
414
  className?: string;
298
- children: React.ReactNode;
415
+ children: React$1.ReactNode;
299
416
  id?: string;
300
417
  noValidate?: boolean;
301
418
  }
302
- declare function FormProvider<TFieldValues extends FieldValues>(props: FormProps<TFieldValues>): React.JSX.Element;
419
+ declare function FormProvider<TFieldValues extends FieldValues>(props: FormProps<TFieldValues>): React$1.JSX.Element;
303
420
 
304
421
  interface SubmitButtonProps {
305
- children: React.ReactNode;
422
+ children: React$1.ReactNode;
306
423
  isLoading?: boolean;
307
- buttonProps?: Omit<React.ComponentProps<typeof Button$1>, "type" | "isLoading">;
424
+ buttonProps?: Omit<React$1.ComponentProps<typeof Button$1>, "type" | "isLoading">;
308
425
  }
309
- declare function SubmitButton(props: SubmitButtonProps): React.JSX.Element;
426
+ declare function SubmitButton(props: SubmitButtonProps): React$1.JSX.Element;
310
427
 
311
428
  interface ServerFieldError<TFieldValues extends FieldValues> {
312
429
  path: Path<TFieldValues>;
@@ -319,6 +436,136 @@ interface ServerFormError<TFieldValues extends FieldValues> {
319
436
  }
320
437
  declare function applyServerErrors<TFieldValues extends FieldValues>(setError: UseFormSetError<TFieldValues>, serverError: ServerFormError<TFieldValues>): void;
321
438
 
439
+ /**
440
+ * Testing utilities for forms
441
+ * These utilities help with testing form behavior and state
442
+ */
443
+ /**
444
+ * Creates form test utilities for a given form instance
445
+ */
446
+ declare function createFormTestUtils<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>): FormTestUtils<TFieldValues>;
447
+ /**
448
+ * Mock form data for testing
449
+ */
450
+ declare function createMockFormData<TFieldValues extends FieldValues>(overrides?: Partial<TFieldValues>): TFieldValues;
451
+ /**
452
+ * Mock form errors for testing
453
+ */
454
+ declare function createMockFormErrors<TFieldValues extends FieldValues>(overrides?: Partial<FieldErrors<TFieldValues>>): FieldErrors<TFieldValues>;
455
+ /**
456
+ * Wait for form state to change (useful for async operations)
457
+ */
458
+ declare function waitForFormState<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>, condition: (state: unknown) => boolean, timeout?: number): Promise<void>;
459
+ /**
460
+ * Simulate user input on a field
461
+ */
462
+ declare function simulateFieldInput<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>, name: Path<TFieldValues>, value: unknown): void;
463
+ /**
464
+ * Simulate form submission
465
+ */
466
+ declare function simulateFormSubmission<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>, onSubmit: (data: TFieldValues) => void | Promise<void>): Promise<void>;
467
+ /**
468
+ * Check if form has validation errors
469
+ */
470
+ declare function hasFormErrors<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>): boolean;
471
+ /**
472
+ * Get all form errors as a flat array
473
+ */
474
+ declare function getFormErrors<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>): string[];
475
+ /**
476
+ * Check if a specific field has an error
477
+ */
478
+ declare function hasFieldError<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>, name: Path<TFieldValues>): boolean;
479
+ /**
480
+ * Get error message for a specific field
481
+ */
482
+ declare function getFieldError<TFieldValues extends FieldValues>(form: UseFormReturn<TFieldValues>, name: Path<TFieldValues>): string | undefined;
483
+
484
+ /**
485
+ * Validation utility functions for common form validation patterns
486
+ * These utilities help create consistent validation schemas across forms
487
+ */
488
+ /**
489
+ * Creates a minimum length validation schema
490
+ */
491
+ declare const createMinLengthSchema: (min: number, fieldName: string) => z.ZodString;
492
+ /**
493
+ * Creates a maximum length validation schema
494
+ */
495
+ declare const createMaxLengthSchema: (max: number, fieldName: string) => z.ZodString;
496
+ /**
497
+ * Creates an email validation schema
498
+ */
499
+ declare const createEmailSchema: () => z.ZodEmail;
500
+ /**
501
+ * Creates a required field validation schema
502
+ */
503
+ declare const createRequiredSchema: (fieldName: string) => z.ZodString;
504
+ /**
505
+ * Creates a URL validation schema
506
+ */
507
+ declare const createUrlSchema: () => z.ZodString;
508
+ /**
509
+ * Creates a phone number validation schema
510
+ */
511
+ declare const createPhoneSchema: () => z.ZodString;
512
+ /**
513
+ * Creates a password validation schema with common requirements
514
+ */
515
+ declare const createPasswordSchema: (minLength?: number) => z.ZodString;
516
+ /**
517
+ * Creates a confirm password validation schema
518
+ */
519
+ declare const createConfirmPasswordSchema: (passwordField: string) => z.ZodString;
520
+ /**
521
+ * Creates a number validation schema with range
522
+ */
523
+ declare const createNumberRangeSchema: (min: number, max: number, fieldName: string) => z.ZodNumber;
524
+ /**
525
+ * Creates a date validation schema
526
+ */
527
+ declare const createDateSchema: (fieldName: string) => z.ZodDate;
528
+ /**
529
+ * Creates a future date validation schema
530
+ */
531
+ declare const createFutureDateSchema: (fieldName: string) => z.ZodDate;
532
+ /**
533
+ * Creates a past date validation schema
534
+ */
535
+ declare const createPastDateSchema: (fieldName: string) => z.ZodDate;
536
+ /**
537
+ * Creates a file validation schema
538
+ */
539
+ declare const createFileSchema: (maxSizeInMB?: number, allowedTypes?: string[]) => z.ZodCustom<File, File>;
540
+ /**
541
+ * Creates a checkbox validation schema (must be checked)
542
+ */
543
+ declare const createRequiredCheckboxSchema: (fieldName: string) => z.ZodBoolean;
544
+ /**
545
+ * Creates a conditional validation schema
546
+ */
547
+ declare const createConditionalSchema: <T>(condition: (data: unknown) => boolean, schema: z.ZodSchema<T>, errorMessage?: string) => z.ZodAny;
548
+ /**
549
+ * Common validation patterns for forms
550
+ */
551
+ declare const commonValidations: {
552
+ conditional: <T>(condition: (data: unknown) => boolean, schema: z.ZodSchema<T>, errorMessage?: string) => z.ZodAny;
553
+ confirmPassword: (passwordField: string) => z.ZodString;
554
+ date: (fieldName: string) => z.ZodDate;
555
+ email: z.ZodEmail;
556
+ file: (maxSizeInMB?: number, allowedTypes?: string[]) => z.ZodCustom<File, File>;
557
+ futureDate: (fieldName: string) => z.ZodDate;
558
+ maxLength: (max: number, fieldName: string) => z.ZodString;
559
+ minLength: (min: number, fieldName: string) => z.ZodString;
560
+ numberRange: (min: number, max: number, fieldName: string) => z.ZodNumber;
561
+ password: (minLength?: number) => z.ZodString;
562
+ pastDate: (fieldName: string) => z.ZodDate;
563
+ phone: z.ZodString;
564
+ required: (fieldName: string) => z.ZodString;
565
+ requiredCheckbox: (fieldName: string) => z.ZodBoolean;
566
+ url: z.ZodString;
567
+ };
568
+
322
569
  interface ZodFormProps<T extends FieldValues> {
323
570
  className?: string;
324
571
  columns?: 1 | 2 | 3;
@@ -330,33 +577,29 @@ interface ZodFormProps<T extends FieldValues> {
330
577
  resetButtonText?: string;
331
578
  showResetButton?: boolean;
332
579
  spacing?: "2" | "4" | "6" | "8" | "lg";
333
- submitButtonProps?: Partial<React.ComponentProps<typeof Button>>;
580
+ submitButtonProps?: Partial<React$1.ComponentProps<typeof Button>>;
334
581
  submitButtonText?: string;
335
582
  subtitle?: string;
336
583
  title?: string;
584
+ errorDisplay?: "inline" | "toast" | "modal" | "none";
585
+ render?: (formState: {
586
+ form: UseFormReturn<T>;
587
+ isSubmitting: boolean;
588
+ isSubmitted: boolean;
589
+ isSuccess: boolean;
590
+ errors: FieldErrors<T>;
591
+ values: T;
592
+ }) => React$1.ReactNode;
337
593
  }
338
- declare function ZodForm<T extends FieldValues>({ className, columns, config, layout, onError, onSubmit, onSuccess, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ZodFormProps<T>): React.JSX.Element;
594
+ declare function ZodForm<T extends FieldValues>({ className, columns, config, errorDisplay, layout, onError, onSubmit, onSuccess, render, resetButtonText, showResetButton, spacing, submitButtonProps, submitButtonText, subtitle, title, }: ZodFormProps<T>): string | number | bigint | boolean | Iterable<React$1.ReactNode> | Promise<string | number | bigint | boolean | React$1.ReactPortal | React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>> | Iterable<React$1.ReactNode> | null | undefined> | React$1.JSX.Element | null | undefined;
339
595
 
340
596
  /**
341
597
  * Hook for using Zod validation with React Hook Form
342
- * This hook is only available when zod and @hookform/resolvers are installed
343
- *
344
- * TODO: Remove type assertion when @hookform/resolvers adds official Zod v4 support
345
- *
346
- * Current issue: @hookform/resolvers v5.2.1 is not compatible with Zod v4 due to
347
- * internal type structure changes. The resolver expects Zod3Type<Output, Input> but
348
- * Zod v4 uses a different internal structure (_zod.output vs _output).
349
- *
350
- * Related issues:
351
- * - GitHub Issue: https://github.com/react-hook-form/resolvers/issues/813
352
- * - GitHub PR: https://github.com/react-hook-form/resolvers/pull/803
353
- *
354
- * Workaround: Use type assertion until official support is added
355
598
  */
599
+ declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormConfig<TFieldValues>): react_hook_form.UseFormReturn<TFieldValues, any, TFieldValues>;
356
600
  /**
357
- * Hook for using Zod validation with React Hook Form
358
- * Uses Zod's built-in type inference to avoid type assertion issues
601
+ * Helper function to create Zod form configurations
359
602
  */
360
- declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormConfig<TFieldValues>): react_hook_form.UseFormReturn<TFieldValues, any, TFieldValues>;
603
+ declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: Partial<TFieldValues>): ZodFormConfig<TFieldValues>;
361
604
 
362
- export { type BaseFormFieldConfig, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, type ConditionalValidation, ConfigurableForm, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, type FormConfig, FormField, type FormFieldConfig, type FormProps, FormProvider, type FormStep, type FormSubmissionState, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, 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, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, useFormHelper, useHeroHookFormDefaults, useZodForm };
605
+ export { type BaseFormFieldConfig, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, type ConditionalValidation, ConfigurableForm, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, type FormProps, FormProvider, type FormStep, type FormSubmissionState, type FormTestUtils, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, 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, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, commonValidations, createConditionalSchema, createConfirmPasswordSchema, createDateSchema, createEmailSchema, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNumberRangeSchema, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createUrlSchema, createZodFormConfig, getFieldError, getFormErrors, hasFieldError, hasFormErrors, simulateFieldInput, simulateFormSubmission, useFormHelper, useHeroForm, useHeroHookFormDefaults, useZodForm, waitForFormState };