@rachelallyson/hero-hook-form 1.0.1 → 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/CHANGELOG.md +54 -42
- package/README.md +131 -178
- package/dist/index.d.ts +73 -4
- package/dist/index.js +170 -80
- package/dist/react/index.d.ts +73 -4
- package/dist/react/index.js +170 -80
- package/package.json +41 -32
package/dist/react/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import React$1, { ComponentProps } from 'react';
|
|
|
2
2
|
import { Input, Textarea, Select, Checkbox, Switch, RadioGroup, Button, DateInput, Slider } 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
|
+
export { UseFormReturn, useFormContext } from 'react-hook-form';
|
|
5
6
|
import * as zod from 'zod';
|
|
6
7
|
import { z } from 'zod';
|
|
7
8
|
import * as _internationalized_date from '@internationalized/date';
|
|
@@ -79,6 +80,11 @@ interface FileFieldConfig<TFieldValues extends FieldValues> extends BaseFormFiel
|
|
|
79
80
|
multiple?: boolean;
|
|
80
81
|
accept?: string;
|
|
81
82
|
}
|
|
83
|
+
interface FontPickerFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
84
|
+
type: "fontPicker";
|
|
85
|
+
defaultValue?: string;
|
|
86
|
+
fontPickerProps?: Record<string, string | number | boolean>;
|
|
87
|
+
}
|
|
82
88
|
interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
83
89
|
type: "custom";
|
|
84
90
|
render: (field: {
|
|
@@ -89,7 +95,7 @@ interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFi
|
|
|
89
95
|
isSubmitting: boolean;
|
|
90
96
|
}) => React.ReactNode;
|
|
91
97
|
}
|
|
92
|
-
type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues>;
|
|
98
|
+
type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | FontPickerFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues>;
|
|
93
99
|
interface FormConfig<TFieldValues extends FieldValues> {
|
|
94
100
|
fields: FormFieldConfig<TFieldValues>[];
|
|
95
101
|
layout?: "vertical" | "horizontal" | "grid" | "custom";
|
|
@@ -103,9 +109,9 @@ interface FormConfig<TFieldValues extends FieldValues> {
|
|
|
103
109
|
className?: string;
|
|
104
110
|
defaultValues?: Partial<TFieldValues>;
|
|
105
111
|
}
|
|
106
|
-
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">;
|
|
112
|
+
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">;
|
|
107
113
|
interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
|
|
108
|
-
schema
|
|
114
|
+
schema: zod.ZodSchema<TFieldValues>;
|
|
109
115
|
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
110
116
|
onError?: (errors: FieldErrors<TFieldValues>) => void;
|
|
111
117
|
errorDisplay?: "inline" | "toast" | "modal" | "none";
|
|
@@ -227,6 +233,17 @@ type FileFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldVal
|
|
|
227
233
|
};
|
|
228
234
|
declare function FileField<TFieldValues extends FieldValues>(props: FileFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
229
235
|
|
|
236
|
+
interface FontPickerProps {
|
|
237
|
+
showFontPreview?: boolean;
|
|
238
|
+
loadAllVariants?: boolean;
|
|
239
|
+
onFontsLoaded?: (loaded: boolean) => void;
|
|
240
|
+
fontsLoadedTimeout?: number;
|
|
241
|
+
}
|
|
242
|
+
type FontPickerFieldProps<TFieldValues extends FieldValues, TValue extends string = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
243
|
+
fontPickerProps?: FontPickerProps;
|
|
244
|
+
};
|
|
245
|
+
declare function FontPickerField<TFieldValues extends FieldValues, TValue extends string = string>(props: FontPickerFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
246
|
+
|
|
230
247
|
type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
231
248
|
inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
232
249
|
transform?: (value: string) => string;
|
|
@@ -292,6 +309,54 @@ declare function useFormHelper<T extends FieldValues>({ defaultValues, methods,
|
|
|
292
309
|
submissionState: FormSubmissionState;
|
|
293
310
|
};
|
|
294
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Enhanced hook that provides both form methods and styling defaults
|
|
314
|
+
*
|
|
315
|
+
* This hook combines React Hook Form's useFormContext with Hero Hook Form's
|
|
316
|
+
* styling defaults, giving you access to both form functionality and
|
|
317
|
+
* component styling in one convenient hook.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```tsx
|
|
321
|
+
* import { useHeroForm } from "@rachelallyson/hero-hook-form";
|
|
322
|
+
*
|
|
323
|
+
* function MyComponent() {
|
|
324
|
+
* const { formState, getValues, setValue, defaults } = useHeroForm();
|
|
325
|
+
*
|
|
326
|
+
* // Access form state
|
|
327
|
+
* const isSubmitting = formState.isSubmitting;
|
|
328
|
+
* const errors = formState.errors;
|
|
329
|
+
*
|
|
330
|
+
* // Access form methods
|
|
331
|
+
* const values = getValues();
|
|
332
|
+
* const handleReset = () => setValue('fieldName', '');
|
|
333
|
+
*
|
|
334
|
+
* // Access styling defaults
|
|
335
|
+
* const inputDefaults = defaults.input;
|
|
336
|
+
* const buttonDefaults = defaults.submitButton;
|
|
337
|
+
* }
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
declare function useHeroForm<TFieldValues extends FieldValues>(): {
|
|
341
|
+
defaults: Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "select" | "switch" | "radioGroup" | "checkbox" | "slider" | "dateInput" | "submitButton">>;
|
|
342
|
+
watch: react_hook_form.UseFormWatch<TFieldValues>;
|
|
343
|
+
getValues: react_hook_form.UseFormGetValues<TFieldValues>;
|
|
344
|
+
getFieldState: react_hook_form.UseFormGetFieldState<TFieldValues>;
|
|
345
|
+
setError: react_hook_form.UseFormSetError<TFieldValues>;
|
|
346
|
+
clearErrors: react_hook_form.UseFormClearErrors<TFieldValues>;
|
|
347
|
+
setValue: react_hook_form.UseFormSetValue<TFieldValues>;
|
|
348
|
+
trigger: react_hook_form.UseFormTrigger<TFieldValues>;
|
|
349
|
+
formState: react_hook_form.FormState<TFieldValues>;
|
|
350
|
+
resetField: react_hook_form.UseFormResetField<TFieldValues>;
|
|
351
|
+
reset: react_hook_form.UseFormReset<TFieldValues>;
|
|
352
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<TFieldValues, TFieldValues>;
|
|
353
|
+
unregister: react_hook_form.UseFormUnregister<TFieldValues>;
|
|
354
|
+
control: react_hook_form.Control<TFieldValues, any, TFieldValues>;
|
|
355
|
+
register: react_hook_form.UseFormRegister<TFieldValues>;
|
|
356
|
+
setFocus: react_hook_form.UseFormSetFocus<TFieldValues>;
|
|
357
|
+
subscribe: react_hook_form.UseFormSubscribe<TFieldValues>;
|
|
358
|
+
};
|
|
359
|
+
|
|
295
360
|
type InputProps = React$1.ComponentProps<typeof Input>;
|
|
296
361
|
type TextareaProps = React$1.ComponentProps<typeof Textarea>;
|
|
297
362
|
type SelectProps = React$1.ComponentProps<typeof Select>;
|
|
@@ -524,5 +589,9 @@ declare function ZodForm<T extends FieldValues>({ className, columns, config, er
|
|
|
524
589
|
* Hook for using Zod validation with React Hook Form
|
|
525
590
|
*/
|
|
526
591
|
declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormConfig<TFieldValues>): react_hook_form.UseFormReturn<TFieldValues, any, TFieldValues>;
|
|
592
|
+
/**
|
|
593
|
+
* Helper function to create Zod form configurations
|
|
594
|
+
*/
|
|
595
|
+
declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: Partial<TFieldValues>): ZodFormConfig<TFieldValues>;
|
|
527
596
|
|
|
528
|
-
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, 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, getFieldError, getFormErrors, hasFieldError, hasFormErrors, simulateFieldInput, simulateFormSubmission, useFormHelper, useHeroHookFormDefaults, useZodForm, waitForFormState };
|
|
597
|
+
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 };
|