@rachelallyson/hero-hook-form 1.0.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 +50 -0
- package/LICENSE +15 -0
- package/README.md +440 -0
- package/dist/dist-ICUU7SXF.js +8 -0
- package/dist/index.cjs +17915 -0
- package/dist/index.d.cts +362 -0
- package/dist/index.d.ts +362 -0
- package/dist/index.js +17842 -0
- package/dist/react/index.cjs +1297 -0
- package/dist/react/index.d.cts +354 -0
- package/dist/react/index.d.ts +354 -0
- package/dist/react/index.js +1256 -0
- package/package.json +148 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
|
+
import { Button } from '@heroui/react';
|
|
3
|
+
import * as react_hook_form from 'react-hook-form';
|
|
4
|
+
import { FieldValues, Path, RegisterOptions, Control, UseFormProps, SubmitHandler, UseFormReturn, UseFormSetError } from 'react-hook-form';
|
|
5
|
+
import * as zod from 'zod';
|
|
6
|
+
import * as _internationalized_date from '@internationalized/date';
|
|
7
|
+
import { CalendarDate } from '@internationalized/date';
|
|
8
|
+
import { Checkbox } from '@heroui/checkbox';
|
|
9
|
+
import { Input, Textarea } from '@heroui/input';
|
|
10
|
+
import { RadioGroup } from '@heroui/radio';
|
|
11
|
+
import { Select } from '@heroui/select';
|
|
12
|
+
import { Switch } from '@heroui/switch';
|
|
13
|
+
import { DateInput } from '@heroui/date-input';
|
|
14
|
+
import { Slider } from '@heroui/slider';
|
|
15
|
+
import { Button as Button$1 } from '@heroui/button';
|
|
16
|
+
|
|
17
|
+
interface FieldBaseProps<TFieldValues extends FieldValues, TValue> {
|
|
18
|
+
name: Path<TFieldValues>;
|
|
19
|
+
label?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
className?: string;
|
|
22
|
+
/** Additional validation rules */
|
|
23
|
+
rules?: RegisterOptions<TFieldValues, Path<TFieldValues>>;
|
|
24
|
+
/** Provide a default value when the form hasn't set one yet. */
|
|
25
|
+
defaultValue?: TValue;
|
|
26
|
+
/** Disable the input */
|
|
27
|
+
isDisabled?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface WithControl<TFieldValues extends FieldValues> {
|
|
30
|
+
control: Control<TFieldValues>;
|
|
31
|
+
}
|
|
32
|
+
interface BaseFormFieldConfig<TFieldValues extends FieldValues> {
|
|
33
|
+
name: Path<TFieldValues>;
|
|
34
|
+
label?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
className?: string;
|
|
37
|
+
isDisabled?: boolean;
|
|
38
|
+
rules?: RegisterOptions<TFieldValues, Path<TFieldValues>>;
|
|
39
|
+
condition?: (values: Partial<TFieldValues>) => boolean;
|
|
40
|
+
group?: string;
|
|
41
|
+
}
|
|
42
|
+
interface StringFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
43
|
+
type: "input" | "textarea" | "select";
|
|
44
|
+
defaultValue?: string;
|
|
45
|
+
inputProps?: Omit<ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
46
|
+
textareaProps?: Omit<ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
47
|
+
selectProps?: Omit<ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
48
|
+
options?: {
|
|
49
|
+
label: string;
|
|
50
|
+
value: string | number;
|
|
51
|
+
}[];
|
|
52
|
+
}
|
|
53
|
+
interface BooleanFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
54
|
+
type: "checkbox" | "switch";
|
|
55
|
+
defaultValue?: boolean;
|
|
56
|
+
checkboxProps?: Omit<ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
57
|
+
switchProps?: Omit<ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
58
|
+
}
|
|
59
|
+
interface RadioFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
60
|
+
type: "radio";
|
|
61
|
+
defaultValue?: string;
|
|
62
|
+
radioProps?: Omit<ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">;
|
|
63
|
+
radioOptions?: {
|
|
64
|
+
label: string;
|
|
65
|
+
value: string | number;
|
|
66
|
+
}[];
|
|
67
|
+
}
|
|
68
|
+
interface SliderFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
69
|
+
type: "slider";
|
|
70
|
+
defaultValue?: number;
|
|
71
|
+
sliderProps?: Record<string, string | number | boolean>;
|
|
72
|
+
}
|
|
73
|
+
interface DateFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
74
|
+
type: "date";
|
|
75
|
+
defaultValue?: _internationalized_date.CalendarDate | null;
|
|
76
|
+
dateProps?: Record<string, string | number | boolean>;
|
|
77
|
+
}
|
|
78
|
+
interface FileFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
79
|
+
type: "file";
|
|
80
|
+
defaultValue?: FileList | null;
|
|
81
|
+
fileProps?: Record<string, string | number | boolean>;
|
|
82
|
+
multiple?: boolean;
|
|
83
|
+
accept?: string;
|
|
84
|
+
}
|
|
85
|
+
type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues>;
|
|
86
|
+
interface FormConfig<TFieldValues extends FieldValues> {
|
|
87
|
+
fields: FormFieldConfig<TFieldValues>[];
|
|
88
|
+
layout?: "vertical" | "horizontal" | "grid" | "custom";
|
|
89
|
+
columns?: 1 | 2 | 3 | 4;
|
|
90
|
+
spacing?: "sm" | "md" | "lg" | "xl";
|
|
91
|
+
title?: string;
|
|
92
|
+
subtitle?: string;
|
|
93
|
+
showResetButton?: boolean;
|
|
94
|
+
resetButtonText?: string;
|
|
95
|
+
submitButtonText?: string;
|
|
96
|
+
className?: string;
|
|
97
|
+
defaultValues?: Partial<TFieldValues>;
|
|
98
|
+
}
|
|
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">;
|
|
100
|
+
interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
|
|
101
|
+
schema?: zod.ZodSchema<TFieldValues>;
|
|
102
|
+
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
103
|
+
}
|
|
104
|
+
interface FormValidationError {
|
|
105
|
+
message: string;
|
|
106
|
+
field?: string;
|
|
107
|
+
}
|
|
108
|
+
interface FormSubmissionState {
|
|
109
|
+
isSubmitting: boolean;
|
|
110
|
+
isSubmitted: boolean;
|
|
111
|
+
isSuccess: boolean;
|
|
112
|
+
error?: string;
|
|
113
|
+
}
|
|
114
|
+
interface FormStep<TFieldValues extends FieldValues> {
|
|
115
|
+
id: string;
|
|
116
|
+
title: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
fields: FormFieldConfig<TFieldValues>[];
|
|
119
|
+
validation?: (values: Partial<TFieldValues>) => boolean;
|
|
120
|
+
}
|
|
121
|
+
interface WizardFormConfig<TFieldValues extends FieldValues> {
|
|
122
|
+
steps: FormStep<TFieldValues>[];
|
|
123
|
+
allowStepNavigation?: boolean;
|
|
124
|
+
showStepProgress?: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface ConditionalValidation<TFieldValues extends FieldValues> {
|
|
127
|
+
when: Path<TFieldValues>;
|
|
128
|
+
is: string | number | boolean | null | undefined;
|
|
129
|
+
then: RegisterOptions<TFieldValues, Path<TFieldValues>>;
|
|
130
|
+
otherwise?: RegisterOptions<TFieldValues, Path<TFieldValues>>;
|
|
131
|
+
}
|
|
132
|
+
interface FieldGroup<TFieldValues extends FieldValues> {
|
|
133
|
+
id: string;
|
|
134
|
+
title?: string;
|
|
135
|
+
description?: string;
|
|
136
|
+
collapsible?: boolean;
|
|
137
|
+
defaultCollapsed?: boolean;
|
|
138
|
+
fields: FormFieldConfig<TFieldValues>[];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface FormProps$1<T extends FieldValues> {
|
|
142
|
+
className?: string;
|
|
143
|
+
columns?: 1 | 2 | 3;
|
|
144
|
+
fields: FormFieldConfig<T>[];
|
|
145
|
+
layout?: "vertical" | "horizontal" | "grid";
|
|
146
|
+
onError?: (error: FormValidationError) => void;
|
|
147
|
+
onSubmit: SubmitHandler<T>;
|
|
148
|
+
onSuccess?: (data: T) => void;
|
|
149
|
+
resetButtonText?: string;
|
|
150
|
+
showResetButton?: boolean;
|
|
151
|
+
spacing?: "2" | "4" | "6" | "8" | "lg";
|
|
152
|
+
submitButtonProps?: Partial<React.ComponentProps<typeof Button>>;
|
|
153
|
+
submitButtonText?: string;
|
|
154
|
+
subtitle?: string;
|
|
155
|
+
title?: string;
|
|
156
|
+
defaultValues?: Partial<T>;
|
|
157
|
+
}
|
|
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;
|
|
159
|
+
|
|
160
|
+
interface FormFieldProps<TFieldValues extends FieldValues> {
|
|
161
|
+
config: FormFieldConfig<TFieldValues>;
|
|
162
|
+
form: UseFormReturn<TFieldValues>;
|
|
163
|
+
submissionState: FormSubmissionState;
|
|
164
|
+
}
|
|
165
|
+
declare function FormField<TFieldValues extends FieldValues>({ config, form, submissionState, }: FormFieldProps<TFieldValues>): React.JSX.Element | null;
|
|
166
|
+
|
|
167
|
+
type CheckboxFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
168
|
+
checkboxProps?: Omit<React.ComponentProps<typeof Checkbox>, "isSelected" | "onValueChange" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
169
|
+
};
|
|
170
|
+
declare function CheckboxField<TFieldValues extends FieldValues>(props: CheckboxFieldProps<TFieldValues>): React.JSX.Element;
|
|
171
|
+
|
|
172
|
+
type DateFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, CalendarDate | null> & WithControl<TFieldValues> & {
|
|
173
|
+
dateProps?: Omit<React.ComponentProps<typeof DateInput>, "value" | "onChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
174
|
+
transform?: (value: CalendarDate | null) => CalendarDate | null;
|
|
175
|
+
};
|
|
176
|
+
declare function DateField<TFieldValues extends FieldValues>(props: DateFieldProps<TFieldValues>): React.JSX.Element;
|
|
177
|
+
|
|
178
|
+
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">;
|
|
180
|
+
transform?: (value: FileList | null) => FileList | null;
|
|
181
|
+
multiple?: boolean;
|
|
182
|
+
accept?: string;
|
|
183
|
+
};
|
|
184
|
+
declare function FileField<TFieldValues extends FieldValues>(props: FileFieldProps<TFieldValues>): React.JSX.Element;
|
|
185
|
+
|
|
186
|
+
type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
187
|
+
inputProps?: Omit<React.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
188
|
+
transform?: (value: string) => string;
|
|
189
|
+
};
|
|
190
|
+
declare function InputField<TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>): React.JSX.Element;
|
|
191
|
+
|
|
192
|
+
interface RadioOption<TValue extends string | number> {
|
|
193
|
+
label: string;
|
|
194
|
+
value: TValue;
|
|
195
|
+
description?: string;
|
|
196
|
+
disabled?: boolean;
|
|
197
|
+
}
|
|
198
|
+
type RadioGroupFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
199
|
+
options: readonly RadioOption<TValue>[];
|
|
200
|
+
radioGroupProps?: Omit<React.ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">;
|
|
201
|
+
};
|
|
202
|
+
declare function RadioGroupField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: RadioGroupFieldProps<TFieldValues, TValue>): React.JSX.Element;
|
|
203
|
+
|
|
204
|
+
interface SelectOption<TValue extends string | number> {
|
|
205
|
+
label: string;
|
|
206
|
+
value: TValue;
|
|
207
|
+
description?: string;
|
|
208
|
+
disabled?: boolean;
|
|
209
|
+
}
|
|
210
|
+
type SelectFieldProps<TFieldValues extends FieldValues, TValue extends string | number = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
211
|
+
options: readonly SelectOption<TValue>[];
|
|
212
|
+
placeholder?: string;
|
|
213
|
+
selectProps?: Omit<React.ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
214
|
+
};
|
|
215
|
+
declare function SelectField<TFieldValues extends FieldValues, TValue extends string | number = string>(props: SelectFieldProps<TFieldValues, TValue>): React.JSX.Element;
|
|
216
|
+
|
|
217
|
+
type SliderFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, number> & WithControl<TFieldValues> & {
|
|
218
|
+
sliderProps?: Omit<React.ComponentProps<typeof Slider>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
219
|
+
transform?: (value: number) => number;
|
|
220
|
+
};
|
|
221
|
+
declare function SliderField<TFieldValues extends FieldValues>(props: SliderFieldProps<TFieldValues>): React.JSX.Element;
|
|
222
|
+
|
|
223
|
+
type SwitchFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, boolean> & WithControl<TFieldValues> & {
|
|
224
|
+
switchProps?: Omit<React.ComponentProps<typeof Switch>, "isSelected" | "onValueChange" | "isInvalid" | "isDisabled">;
|
|
225
|
+
};
|
|
226
|
+
declare function SwitchField<TFieldValues extends FieldValues>(props: SwitchFieldProps<TFieldValues>): React.JSX.Element;
|
|
227
|
+
|
|
228
|
+
type TextareaFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
229
|
+
textareaProps?: Omit<React.ComponentProps<typeof Textarea>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
230
|
+
};
|
|
231
|
+
declare function TextareaField<TFieldValues extends FieldValues>(props: TextareaFieldProps<TFieldValues>): React.JSX.Element;
|
|
232
|
+
|
|
233
|
+
interface UseFormHelperOptions<T extends FieldValues> {
|
|
234
|
+
onError?: (error: FormValidationError) => void;
|
|
235
|
+
onSubmit: SubmitHandler<T>;
|
|
236
|
+
onSuccess?: (data: T) => void;
|
|
237
|
+
defaultValues?: Partial<T>;
|
|
238
|
+
methods?: UseFormReturn<T>;
|
|
239
|
+
}
|
|
240
|
+
declare function useFormHelper<T extends FieldValues>({ defaultValues, methods, onError, onSubmit, onSuccess, }: UseFormHelperOptions<T>): {
|
|
241
|
+
error: string | undefined;
|
|
242
|
+
form: UseFormReturn<T>;
|
|
243
|
+
handleSubmit: () => Promise<void>;
|
|
244
|
+
isSubmitted: boolean;
|
|
245
|
+
isSubmitting: boolean;
|
|
246
|
+
isSuccess: boolean;
|
|
247
|
+
resetForm: () => void;
|
|
248
|
+
submissionState: FormSubmissionState;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
type InputProps = React.ComponentProps<typeof Input>;
|
|
252
|
+
type TextareaProps = React.ComponentProps<typeof Textarea>;
|
|
253
|
+
type SelectProps = React.ComponentProps<typeof Select>;
|
|
254
|
+
type SharedTextLikeColor = Extract<InputProps["color"], Extract<TextareaProps["color"], SelectProps["color"]>>;
|
|
255
|
+
type SharedTextLikeSize = Extract<InputProps["size"], Extract<TextareaProps["size"], SelectProps["size"]>>;
|
|
256
|
+
type SharedTextLikeVariant = Extract<InputProps["variant"], Extract<TextareaProps["variant"], SelectProps["variant"]>>;
|
|
257
|
+
type SharedTextLikeRadius = Extract<InputProps["radius"], Extract<TextareaProps["radius"], SelectProps["radius"]>>;
|
|
258
|
+
type SharedTextLikeLabelPlacement = Extract<InputProps["labelPlacement"], Extract<TextareaProps["labelPlacement"], SelectProps["labelPlacement"]>>;
|
|
259
|
+
type CommonFieldDefaults = Partial<{
|
|
260
|
+
color: SharedTextLikeColor;
|
|
261
|
+
size: SharedTextLikeSize;
|
|
262
|
+
variant: SharedTextLikeVariant;
|
|
263
|
+
radius: SharedTextLikeRadius;
|
|
264
|
+
labelPlacement: SharedTextLikeLabelPlacement;
|
|
265
|
+
}>;
|
|
266
|
+
type InputDefaults = Partial<Omit<InputProps, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">>;
|
|
267
|
+
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">>;
|
|
270
|
+
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">>;
|
|
275
|
+
interface HeroHookFormDefaultsConfig {
|
|
276
|
+
common?: CommonFieldDefaults;
|
|
277
|
+
input?: InputDefaults;
|
|
278
|
+
textarea?: TextareaDefaults;
|
|
279
|
+
checkbox?: CheckboxDefaults;
|
|
280
|
+
radioGroup?: RadioGroupDefaults;
|
|
281
|
+
select?: SelectDefaults;
|
|
282
|
+
dateInput?: DateInputDefaults;
|
|
283
|
+
slider?: SliderDefaults;
|
|
284
|
+
switch?: SwitchDefaults;
|
|
285
|
+
submitButton?: ButtonDefaults;
|
|
286
|
+
}
|
|
287
|
+
interface HeroHookFormProviderProps {
|
|
288
|
+
children: React.ReactNode;
|
|
289
|
+
defaults?: HeroHookFormDefaultsConfig;
|
|
290
|
+
}
|
|
291
|
+
declare function HeroHookFormProvider(props: HeroHookFormProviderProps): React.JSX.Element;
|
|
292
|
+
declare function useHeroHookFormDefaults(): Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "checkbox" | "radioGroup" | "select" | "dateInput" | "slider" | "switch" | "submitButton">>;
|
|
293
|
+
|
|
294
|
+
interface FormProps<TFieldValues extends FieldValues> {
|
|
295
|
+
methods: UseFormReturn<TFieldValues>;
|
|
296
|
+
onSubmit: SubmitHandler<TFieldValues>;
|
|
297
|
+
className?: string;
|
|
298
|
+
children: React.ReactNode;
|
|
299
|
+
id?: string;
|
|
300
|
+
noValidate?: boolean;
|
|
301
|
+
}
|
|
302
|
+
declare function FormProvider<TFieldValues extends FieldValues>(props: FormProps<TFieldValues>): React.JSX.Element;
|
|
303
|
+
|
|
304
|
+
interface SubmitButtonProps {
|
|
305
|
+
children: React.ReactNode;
|
|
306
|
+
isLoading?: boolean;
|
|
307
|
+
buttonProps?: Omit<React.ComponentProps<typeof Button$1>, "type" | "isLoading">;
|
|
308
|
+
}
|
|
309
|
+
declare function SubmitButton(props: SubmitButtonProps): React.JSX.Element;
|
|
310
|
+
|
|
311
|
+
interface ServerFieldError<TFieldValues extends FieldValues> {
|
|
312
|
+
path: Path<TFieldValues>;
|
|
313
|
+
message: string;
|
|
314
|
+
type?: string;
|
|
315
|
+
}
|
|
316
|
+
interface ServerFormError<TFieldValues extends FieldValues> {
|
|
317
|
+
message?: string;
|
|
318
|
+
fieldErrors?: readonly ServerFieldError<TFieldValues>[];
|
|
319
|
+
}
|
|
320
|
+
declare function applyServerErrors<TFieldValues extends FieldValues>(setError: UseFormSetError<TFieldValues>, serverError: ServerFormError<TFieldValues>): void;
|
|
321
|
+
|
|
322
|
+
interface ZodFormProps<T extends FieldValues> {
|
|
323
|
+
className?: string;
|
|
324
|
+
columns?: 1 | 2 | 3;
|
|
325
|
+
config: ZodFormConfig<T>;
|
|
326
|
+
layout?: "vertical" | "horizontal" | "grid";
|
|
327
|
+
onError?: (error: FormValidationError) => void;
|
|
328
|
+
onSubmit: SubmitHandler<T>;
|
|
329
|
+
onSuccess?: (data: T) => void;
|
|
330
|
+
resetButtonText?: string;
|
|
331
|
+
showResetButton?: boolean;
|
|
332
|
+
spacing?: "2" | "4" | "6" | "8" | "lg";
|
|
333
|
+
submitButtonProps?: Partial<React.ComponentProps<typeof Button>>;
|
|
334
|
+
submitButtonText?: string;
|
|
335
|
+
subtitle?: string;
|
|
336
|
+
title?: string;
|
|
337
|
+
}
|
|
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;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 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
|
+
*/
|
|
356
|
+
/**
|
|
357
|
+
* Hook for using Zod validation with React Hook Form
|
|
358
|
+
* Uses Zod's built-in type inference to avoid type assertion issues
|
|
359
|
+
*/
|
|
360
|
+
declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormConfig<TFieldValues>): react_hook_form.UseFormReturn<TFieldValues, any, TFieldValues>;
|
|
361
|
+
|
|
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 };
|