@nwon/react-mui-hook-form 3.0.4 → 3.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/package.json +50 -16
- package/dist/LoadingButton/LoadingButton.d.ts +0 -6
- package/dist/LoadingButton/LoadingButtonInterfaces.d.ts +0 -33
- package/dist/LoadingButton/getLoadingButtonState.d.ts +0 -20
- package/dist/LoadingButton/index.d.ts +0 -4
- package/dist/formFields/HookFormProvider.d.ts +0 -7
- package/dist/formFields/InputEmail/InputEmail.d.ts +0 -10
- package/dist/formFields/InputPasswordSet/InputPasswordSet.d.ts +0 -8
- package/dist/formFields/InputPasswordSet/InputPasswordSetInterfaces.d.ts +0 -18
- package/dist/formFields/TranslatedString.d.ts +0 -13
- package/dist/formFields/baseTypes/BaseInputProps.d.ts +0 -33
- package/dist/formFields/baseTypes/InputAutocomplete/InputAutocomplete.d.ts +0 -9
- package/dist/formFields/baseTypes/InputAutocomplete/InputAutocompleteInterfaces.d.ts +0 -24
- package/dist/formFields/baseTypes/InputAutocomplete/useSortedOptionsWithGroup.d.ts +0 -9
- package/dist/formFields/baseTypes/InputCheckbox/InputCheckbox.d.ts +0 -18
- package/dist/formFields/baseTypes/InputDatePicker/InputDatePicker.d.ts +0 -16
- package/dist/formFields/baseTypes/InputDateTimePicker/InputDateTimePicker.d.ts +0 -16
- package/dist/formFields/baseTypes/InputNumber/InputNumber.d.ts +0 -15
- package/dist/formFields/baseTypes/InputOutlinedInput/InputOutlinedInput.d.ts +0 -13
- package/dist/formFields/baseTypes/InputRadio/InputRadio.d.ts +0 -13
- package/dist/formFields/baseTypes/InputSelect/InputSelect.d.ts +0 -26
- package/dist/formFields/baseTypes/InputSelectFromEnum/InputSelectFromEnum.d.ts +0 -7
- package/dist/formFields/baseTypes/InputSelectFromEnum/InputSelectFromEnumInterfaces.d.ts +0 -10
- package/dist/formFields/baseTypes/InputSlider/InputSlider.d.ts +0 -13
- package/dist/formFields/baseTypes/InputSwitch/InputSwitch.d.ts +0 -11
- package/dist/formFields/baseTypes/InputTextField/InputTextField.d.ts +0 -13
- package/dist/formFields/baseTypes/InputTimePicker/InputTimePicker.d.ts +0 -16
- package/dist/formFields/baseTypes/InputToggleButton/InputToggleButton.d.ts +0 -12
- package/dist/formFields/baseTypes/InputToggleButtonGroup/InputToggleButtonGroup.d.ts +0 -34
- package/dist/formFields/baseTypes/useEffectFieldUnregisterOnUnmount.d.ts +0 -12
- package/dist/formFields/errorMessages.d.ts +0 -1
- package/dist/formFields/errors/FormFieldError.d.ts +0 -11
- package/dist/formFields/errors/FormFieldErrorDisplay.d.ts +0 -11
- package/dist/formFields/errors/getFormErrorForNestedKeys.d.ts +0 -14
- package/dist/formFields/errors/useFormFieldError.d.ts +0 -7
- package/dist/formFields/errors/useFormFieldHasError.d.ts +0 -6
- package/dist/formFields/formHelper/syncSubmit.d.ts +0 -15
- package/dist/formFields/formHelper/useHookForm.d.ts +0 -56
- package/dist/formFields/formHelper/useHookFormContext.d.ts +0 -9
- package/dist/formFields/formHelper/useMergedFormField.d.ts +0 -6
- package/dist/formFields/formHelper/useSortedOptionsWithGroup.d.ts +0 -5
- package/dist/formFields/formHelper/useTranslateString.d.ts +0 -8
- package/dist/formFields/index.d.ts +0 -49
- package/dist/formFields/inputTypes.d.ts +0 -76
- package/dist/packageExports.d.ts +0 -9
- package/dist/packageExports.js +0 -1761
- package/dist/packageExports.js.map +0 -1
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AnyObject } from "@nvon/baseline";
|
|
2
|
-
import type { FieldError, FormState } from "react-hook-form";
|
|
3
|
-
/**
|
|
4
|
-
* Get the field errors for a (possibly nested) field name.
|
|
5
|
-
*
|
|
6
|
-
* Checking `formState.errors[fieldName]` only works if fieldName is not a path
|
|
7
|
-
* (e.g. Does not include dots).
|
|
8
|
-
*
|
|
9
|
-
* Did not find a built-in way to do this … there might be one though.
|
|
10
|
-
*
|
|
11
|
-
* Supports both dot notation (e.g., "response.receipts.0.field") and
|
|
12
|
-
* bracket notation (e.g., "response.receipts[0].field") for array fields.
|
|
13
|
-
*/
|
|
14
|
-
export declare const getFormErrorForNestedKeys: (errors: FormState<AnyObject>["errors"], fieldName: string) => FieldError | FieldError[] | undefined;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { getFormErrorForNestedKeys } from "./getFormErrorForNestedKeys";
|
|
2
|
-
/**
|
|
3
|
-
* Returns the error for a given field name.
|
|
4
|
-
*
|
|
5
|
-
* @throws Error when FormContext is null.
|
|
6
|
-
*/
|
|
7
|
-
export declare const useFormFieldError: (fieldName: string) => ReturnType<typeof getFormErrorForNestedKeys>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FormEvent } from "react";
|
|
2
|
-
export type FormSubmitHandlerAsync = (event?: FormEvent) => Promise<void>;
|
|
3
|
-
export type FormSubmitHandler = (event?: FormEvent) => void;
|
|
4
|
-
/**
|
|
5
|
-
* Turn an async submitHandler into a synchronous one.
|
|
6
|
-
*
|
|
7
|
-
* Reasoning:
|
|
8
|
-
* - we're often talking to the API during form submission. The onSubmit handler will be returning a Promise in this case.
|
|
9
|
-
* - the `form` element, per definition, always expects a synchronous function.
|
|
10
|
-
* - creating on inline function in every form is a bit clumsy, and does not look clean.
|
|
11
|
-
*
|
|
12
|
-
* Then/catch cases should be properly handled by the submit handler itself,
|
|
13
|
-
* the catch supplied here is only a last safety net against an "unhandled promise rejection" error.
|
|
14
|
-
*/
|
|
15
|
-
export declare const syncSubmit: (asyncSubmitHandler: FormSubmitHandlerAsync) => FormSubmitHandler;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { FieldPath, FieldValues, useFieldArray, UseFormProps, UseFormReturn } from "react-hook-form";
|
|
2
|
-
/**
|
|
3
|
-
* Gets a TypeScript-validated field name.
|
|
4
|
-
*/
|
|
5
|
-
export type FieldNameGetter<TFieldValues extends FieldValues> = (fieldName: FieldPath<TFieldValues>) => FieldPath<TFieldValues>;
|
|
6
|
-
/**
|
|
7
|
-
* Not sure what this represents,
|
|
8
|
-
* but it's the seconds generic argument in RHFs type declarations.
|
|
9
|
-
*
|
|
10
|
-
* Using any here seems fine so far.
|
|
11
|
-
*/
|
|
12
|
-
type ReactHookFormContext = any;
|
|
13
|
-
/**
|
|
14
|
-
* The react-hook-form useForm returnType,
|
|
15
|
-
* amended with our custom function to validate a field name.
|
|
16
|
-
*/
|
|
17
|
-
export type FormReturn<TFieldValues extends FieldValues> = UseFormReturn<TFieldValues, ReactHookFormContext> & {
|
|
18
|
-
fieldName: FieldNameGetter<TFieldValues>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Wrapper around react-hook-form's useForm.
|
|
22
|
-
*
|
|
23
|
-
* Should behave like the original function, only exposing a "fieldName"
|
|
24
|
-
* function on top which is used to validate field names.
|
|
25
|
-
*/
|
|
26
|
-
export declare const useHookForm: <TFieldValues extends FieldValues>(props?: Partial<{
|
|
27
|
-
mode: "onBlur" | "onChange" | "onSubmit" | "all" | "onTouched";
|
|
28
|
-
disabled: boolean;
|
|
29
|
-
reValidateMode: "onBlur" | "onChange" | "onSubmit";
|
|
30
|
-
defaultValues: ((payload?: unknown) => Promise<TFieldValues>) | import("react-hook-form").DefaultValues<TFieldValues>;
|
|
31
|
-
values: TFieldValues;
|
|
32
|
-
errors: import("react-hook-form").FieldErrors<TFieldValues>;
|
|
33
|
-
resetOptions: Partial<{
|
|
34
|
-
keepDirtyValues: boolean;
|
|
35
|
-
keepErrors: boolean;
|
|
36
|
-
keepDirty: boolean;
|
|
37
|
-
keepValues: boolean;
|
|
38
|
-
keepDefaultValues: boolean;
|
|
39
|
-
keepIsSubmitted: boolean;
|
|
40
|
-
keepIsSubmitSuccessful: boolean;
|
|
41
|
-
keepTouched: boolean;
|
|
42
|
-
keepIsValidating: boolean;
|
|
43
|
-
keepIsValid: boolean;
|
|
44
|
-
keepSubmitCount: boolean;
|
|
45
|
-
}> | undefined;
|
|
46
|
-
resolver: import("react-hook-form").Resolver<TFieldValues, any>;
|
|
47
|
-
context: any;
|
|
48
|
-
shouldFocusError: boolean;
|
|
49
|
-
shouldUnregister: boolean;
|
|
50
|
-
shouldUseNativeValidation: boolean;
|
|
51
|
-
progressive: boolean;
|
|
52
|
-
criteriaMode: import("react-hook-form").CriteriaMode;
|
|
53
|
-
delayError: number;
|
|
54
|
-
}> | undefined) => FormReturn<TFieldValues>;
|
|
55
|
-
export declare const useHookFormFieldArray: typeof useFieldArray;
|
|
56
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FieldValues } from "react-hook-form";
|
|
2
|
-
import { FormReturn } from "./useHookForm";
|
|
3
|
-
/**
|
|
4
|
-
* Wrapper around react-hook-form's useFormContext.
|
|
5
|
-
*
|
|
6
|
-
* Should behave like the original function, only exposing a "fieldName"
|
|
7
|
-
* function on top which is used to validate field names.
|
|
8
|
-
*/
|
|
9
|
-
export declare const useHookFormContext: <TFieldValues extends FieldValues>() => FormReturn<TFieldValues>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { TFunction } from "i18next";
|
|
2
|
-
import { FormField, FormFieldTranslated } from "../inputTypes";
|
|
3
|
-
/**
|
|
4
|
-
* Merge a form field with defaults.
|
|
5
|
-
*/
|
|
6
|
-
export declare const useMergedFormField: (formField: FormField, t?: TFunction, formFieldDefaults?: Partial<FormField>) => FormFieldTranslated;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TFunction } from "i18next";
|
|
2
|
-
import { TranslatedString } from "../TranslatedString";
|
|
3
|
-
/**
|
|
4
|
-
* Return a function which turns our TranslatedString into a plain string.
|
|
5
|
-
*
|
|
6
|
-
* @throws Error if no t was provided but a translated string.
|
|
7
|
-
*/
|
|
8
|
-
export declare const useTranslateString: () => (input: TranslatedString | string, t?: TFunction) => string;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export { InputAutocomplete } from "./baseTypes/InputAutocomplete/InputAutocomplete";
|
|
2
|
-
export type { InputAutocompleteProps } from "./baseTypes/InputAutocomplete/InputAutocompleteInterfaces";
|
|
3
|
-
export type { GroupLabelSorting } from "./baseTypes/InputAutocomplete/useSortedOptionsWithGroup";
|
|
4
|
-
export { InputCheckbox } from "./baseTypes/InputCheckbox/InputCheckbox";
|
|
5
|
-
export type { InputCheckboxProps } from "./baseTypes/InputCheckbox/InputCheckbox";
|
|
6
|
-
export { InputDatePicker } from "./baseTypes/InputDatePicker/InputDatePicker";
|
|
7
|
-
export type { InputDatePickerProps } from "./baseTypes/InputDatePicker/InputDatePicker";
|
|
8
|
-
export { InputDateTimePicker } from "./baseTypes/InputDateTimePicker/InputDateTimePicker";
|
|
9
|
-
export type { InputDateTimePickerProps } from "./baseTypes/InputDateTimePicker/InputDateTimePicker";
|
|
10
|
-
export { InputNumber } from "./baseTypes/InputNumber/InputNumber";
|
|
11
|
-
export type { InputNumberProps } from "./baseTypes/InputNumber/InputNumber";
|
|
12
|
-
export { InputOutlinedInput, InputOutlinedInput as InputText, } from "./baseTypes/InputOutlinedInput/InputOutlinedInput";
|
|
13
|
-
export type { InputOutlinedInputProps, InputOutlinedInputProps as InputTextProps, } from "./baseTypes/InputOutlinedInput/InputOutlinedInput";
|
|
14
|
-
export { InputRadio } from "./baseTypes/InputRadio/InputRadio";
|
|
15
|
-
export type { InputRadioProps } from "./baseTypes/InputRadio/InputRadio";
|
|
16
|
-
export { InputSelect } from "./baseTypes/InputSelect/InputSelect";
|
|
17
|
-
export type { InputSelectProps } from "./baseTypes/InputSelect/InputSelect";
|
|
18
|
-
export { InputSelectFromEnum } from "./baseTypes/InputSelectFromEnum/InputSelectFromEnum";
|
|
19
|
-
export type { InputSelectFromEnumProps } from "./baseTypes/InputSelectFromEnum/InputSelectFromEnumInterfaces";
|
|
20
|
-
export { InputSlider } from "./baseTypes/InputSlider/InputSlider";
|
|
21
|
-
export type { InputSliderProps } from "./baseTypes/InputSlider/InputSlider";
|
|
22
|
-
export { InputSwitch } from "./baseTypes/InputSwitch/InputSwitch";
|
|
23
|
-
export type { InputSwitchProps } from "./baseTypes/InputSwitch/InputSwitch";
|
|
24
|
-
export { InputTextField } from "./baseTypes/InputTextField/InputTextField";
|
|
25
|
-
export type { InputTextFieldProps } from "./baseTypes/InputTextField/InputTextField";
|
|
26
|
-
export { InputTimePicker } from "./baseTypes/InputTimePicker/InputTimePicker";
|
|
27
|
-
export type { InputTimePickerProps } from "./baseTypes/InputTimePicker/InputTimePicker";
|
|
28
|
-
export { InputToggleButton } from "./baseTypes/InputToggleButton/InputToggleButton";
|
|
29
|
-
export type { InputToggleButtonProps } from "./baseTypes/InputToggleButton/InputToggleButton";
|
|
30
|
-
export { InputToggleButtonGroup } from "./baseTypes/InputToggleButtonGroup/InputToggleButtonGroup";
|
|
31
|
-
export type { InputToggleButtonGroupProps, SingleToggleButton, } from "./baseTypes/InputToggleButtonGroup/InputToggleButtonGroup";
|
|
32
|
-
export { getFormErrorForNestedKeys } from "./errors/getFormErrorForNestedKeys";
|
|
33
|
-
export { useFormFieldError } from "./errors/useFormFieldError";
|
|
34
|
-
export { useFormFieldHasError } from "./errors/useFormFieldHasError";
|
|
35
|
-
export { syncSubmit } from "./formHelper/syncSubmit";
|
|
36
|
-
export type { FormSubmitHandler, FormSubmitHandlerAsync, } from "./formHelper/syncSubmit";
|
|
37
|
-
export { useHookForm, useHookFormFieldArray } from "./formHelper/useHookForm";
|
|
38
|
-
export type { FieldNameGetter, FormReturn } from "./formHelper/useHookForm";
|
|
39
|
-
export { useHookFormContext } from "./formHelper/useHookFormContext";
|
|
40
|
-
export { useMergedFormField } from "./formHelper/useMergedFormField";
|
|
41
|
-
export { useSortedOptionsWithGroup } from "./formHelper/useSortedOptionsWithGroup";
|
|
42
|
-
export { useTranslateString } from "./formHelper/useTranslateString";
|
|
43
|
-
export { HookFormProvider } from "./HookFormProvider";
|
|
44
|
-
export { InputEmail } from "./InputEmail/InputEmail";
|
|
45
|
-
export type { InputEmailProps } from "./InputEmail/InputEmail";
|
|
46
|
-
export { InputPasswordSet } from "./InputPasswordSet/InputPasswordSet";
|
|
47
|
-
export type { InputPasswordSetProps } from "./InputPasswordSet/InputPasswordSetInterfaces";
|
|
48
|
-
export type { FormField, FormFieldTranslated, LabeledValue, LabeledValueWithGrouping, TranslatedValidate, } from "./inputTypes";
|
|
49
|
-
export type { TranslatedString } from "./TranslatedString";
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { TFunction } from "i18next";
|
|
2
|
-
import { RegisterOptions } from "react-hook-form";
|
|
3
|
-
import { TranslatedString } from "./TranslatedString";
|
|
4
|
-
/**
|
|
5
|
-
* An arbitrary value with a human-readable label.
|
|
6
|
-
* To be used for selects/autocompletes/….
|
|
7
|
-
*/
|
|
8
|
-
export interface LabeledValue {
|
|
9
|
-
label: string;
|
|
10
|
-
value: string | number | boolean;
|
|
11
|
-
/**
|
|
12
|
-
* A string can be provided to indicate a reason for being disabled.
|
|
13
|
-
*/
|
|
14
|
-
disabled?: boolean | string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* An arbitrary value, a human-readable label and a group.
|
|
18
|
-
* To be used for selects/autocompletes/….
|
|
19
|
-
*/
|
|
20
|
-
export interface LabeledValueWithGrouping extends LabeledValue {
|
|
21
|
-
group?: string;
|
|
22
|
-
}
|
|
23
|
-
export type TranslatedValidate = (t: TFunction) => RegisterOptions["validate"];
|
|
24
|
-
/**
|
|
25
|
-
* Generic props received by any form field.
|
|
26
|
-
*
|
|
27
|
-
* String values can be given as TranslatedString to faclitate having static defaults.
|
|
28
|
-
*/
|
|
29
|
-
export interface FormField {
|
|
30
|
-
/**
|
|
31
|
-
* The label shown to the user.
|
|
32
|
-
*/
|
|
33
|
-
label?: string | TranslatedString;
|
|
34
|
-
/**
|
|
35
|
-
* The name within the react-hook-form context.
|
|
36
|
-
*/
|
|
37
|
-
name: string;
|
|
38
|
-
/**
|
|
39
|
-
* T Function from i18next for translating stuff.
|
|
40
|
-
*/
|
|
41
|
-
t?: TFunction;
|
|
42
|
-
/**
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
required?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Shown when the field is not filled out, but required.
|
|
48
|
-
*/
|
|
49
|
-
requiredErrorMessage?: string | TranslatedString;
|
|
50
|
-
/**
|
|
51
|
-
* Custom validation function(s) for the field.
|
|
52
|
-
*
|
|
53
|
-
* Note: this is expected to be a function (receiving a TFunction) returning the validation function.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```
|
|
57
|
-
* // validate a string input, returning a translated error message
|
|
58
|
-
* const validate = (t) => (input: string) => {
|
|
59
|
-
* if (!input) {
|
|
60
|
-
* return t("common:invalidStuff")
|
|
61
|
-
* }
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
validate?: RegisterOptions["validate"] | {
|
|
66
|
-
translated: TranslatedValidate;
|
|
67
|
-
} | undefined;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* The FormField with applied translations.
|
|
71
|
-
*/
|
|
72
|
-
export interface FormFieldTranslated extends Omit<FormField, "label" | "requiredErrorMessage" | "validate"> {
|
|
73
|
-
label: string;
|
|
74
|
-
requiredErrorMessage: string;
|
|
75
|
-
validate: RegisterOptions["validate"] | undefined;
|
|
76
|
-
}
|
package/dist/packageExports.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is the main package file, containing everything that our package exports.
|
|
3
|
-
*/
|
|
4
|
-
export { getFormErrorForNestedKeys, HookFormProvider, InputAutocomplete, InputCheckbox, InputDatePicker, InputDateTimePicker, InputEmail, InputNumber, InputOutlinedInput, InputPasswordSet, InputRadio, InputSelect, InputSelectFromEnum, InputSlider, InputSwitch, InputText, InputTextField, InputTimePicker, InputToggleButton, InputToggleButtonGroup, syncSubmit, useFormFieldError, useFormFieldHasError, useHookForm, useHookFormContext, useHookFormFieldArray, useMergedFormField, useSortedOptionsWithGroup, useTranslateString, } from "./formFields";
|
|
5
|
-
export type { FieldNameGetter, FormField, FormFieldTranslated, FormReturn, FormSubmitHandler, FormSubmitHandlerAsync, GroupLabelSorting, InputAutocompleteProps, InputCheckboxProps, InputDatePickerProps, InputDateTimePickerProps, InputEmailProps, InputNumberProps, InputOutlinedInputProps, InputPasswordSetProps, InputRadioProps, InputSelectFromEnumProps, InputSelectProps, InputSliderProps, InputSwitchProps, InputTextFieldProps, InputTextProps, InputTimePickerProps, InputToggleButtonGroupProps, InputToggleButtonProps, LabeledValue, LabeledValueWithGrouping, SingleToggleButton, TranslatedString, TranslatedValidate, } from "./formFields/";
|
|
6
|
-
export { FormFieldError } from "./formFields/errors/FormFieldError";
|
|
7
|
-
export { FormFieldErrorDisplay } from "./formFields/errors/FormFieldErrorDisplay";
|
|
8
|
-
export { LoadingButton, LoadingButtonState, loadingButtonStateFromFormState, loadingButtonStateFromReactQueryMutationStatus, useLoadingButtonStateFromFormContext, } from "./LoadingButton";
|
|
9
|
-
export type { LoadingButtonProps } from "./LoadingButton";
|