@nwon/react-mui-hook-form 1.0.1 → 1.0.3
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 +1 -1
- 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 -11
- package/dist/formFields/InputPasswordSet/InputPasswordSet.d.ts +0 -8
- package/dist/formFields/InputPasswordSet/InputPasswordSetInterfaces.d.ts +0 -15
- package/dist/formFields/TranslatedString.d.ts +0 -13
- package/dist/formFields/baseTypes/InputAutocomplete/InputAutocomplete.d.ts +0 -8
- package/dist/formFields/baseTypes/InputAutocomplete/InputAutocompleteInterfaces.d.ts +0 -22
- package/dist/formFields/baseTypes/InputCheckbox/InputCheckbox.d.ts +0 -19
- package/dist/formFields/baseTypes/InputDateTimePicker/InputDateTimePicker.d.ts +0 -12
- package/dist/formFields/baseTypes/InputRadio/InputRadio.d.ts +0 -10
- package/dist/formFields/baseTypes/InputSelect/InputSelect.d.ts +0 -23
- package/dist/formFields/baseTypes/InputSelectFromEnum/InputSelectFromEnum.d.ts +0 -6
- package/dist/formFields/baseTypes/InputSelectFromEnum/InputSelectFromEnumInterfaces.d.ts +0 -10
- package/dist/formFields/baseTypes/InputText/InputText.d.ts +0 -14
- package/dist/formFields/errorMessages.d.ts +0 -1
- package/dist/formFields/formHelper/getFormError.d.ts +0 -11
- package/dist/formFields/formHelper/syncSubmit.d.ts +0 -15
- package/dist/formFields/formHelper/useHookForm.d.ts +0 -50
- 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 -28
- package/dist/formFields/inputTypes.d.ts +0 -76
- package/dist/packageExports.d.ts +0 -7
- package/dist/packageExports.js +0 -731
- package/dist/packageExports.js.map +0 -1
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@nwon/react-mui-hook-form","version":"1.0.
|
|
1
|
+
{"name":"@nwon/react-mui-hook-form","version":"1.0.3","type":"module","keywords":["react","MUI","React Hook Form","forms","typescript"],"repository":{"type":"git","url":"https://gitlab.com/nwon-group/nwon-tooling/npm-packages/react-mui-hook-form"},"description":"Making react forms easy - A connection of MUI and React Hook Form","types":"dist/packageExports.d.ts","main":"dist/packageExports.js","cracoConfig":"craco.config.cjs","scripts":{},"files":["dist","readme.md","license"],"author":"NWON","license":"MIT","devDependencies":{"@babel/core":"^7.21.3","@babel/plugin-transform-runtime":"^7.21.0","@babel/preset-flow":"^7.18.6","@babel/preset-react":"^7.18.6","@craco/craco":"^6.4.3","@nvon/eslint-config":"^1.21.1","@nvon/node-toolbox":"^0.20.4","@rollup/plugin-babel":"^6.0.3","@types/lodash-es":"^4.17.6","@types/node":"^18.11.11","@types/react-dom":">=17.0.0","@types/webpack":"^4.41.32","cross-env":"^7.0.3","npm":"^9.5.0","react-scripts":"^4.0.3","rimraf":"^3.0.2","rollup":"^3.19.1","rollup-plugin-sass":"^1.12.17","rollup-plugin-typescript2":"^0.34.1","typescript":"^4.9.5"},"dependencies":{"@babel/runtime":"^7.21.0","@mui/lab":"^5.0.0-alpha.134","@mui/material":"^5.13.5","@mui/x-date-pickers":"^5.0.20","@nvon/baseline":"^0.33.0","dayjs":"^1.11.10","fuse.js":"^6.5.3","i18next":"^22.4.10","lodash-es":"^4.17.21","react-hook-form":"^7.41.3","react-i18next":"^11.18.5"},"peerDependencies":{"react":">=17.0.0","react-dom":">=17.0.0"},"browserslist":{"production":[">0.2%","not dead","not op_mini all"],"development":["last 1 chrome version","last 1 firefox version","last 1 safari version"]}}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { LoadingButtonProps } from "./LoadingButtonInterfaces";
|
|
3
|
-
/**
|
|
4
|
-
* A loading button component.
|
|
5
|
-
*/
|
|
6
|
-
export declare const LoadingButton: ({ buttonText, buttonTextSuccess, loadingButtonProps, loadingButtonPropsPropsSuccess, buttonState, successIcon, }: LoadingButtonProps) => JSX.Element;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { LoadingButtonProps as MuiLoadingButtonProps } from "@mui/lab";
|
|
2
|
-
import { ReactElement } from "react";
|
|
3
|
-
export declare enum LoadingButtonState {
|
|
4
|
-
Idle = "idle",
|
|
5
|
-
Loading = "loading",
|
|
6
|
-
Success = "success"
|
|
7
|
-
}
|
|
8
|
-
type SelectedButtonProps = Omit<MuiLoadingButtonProps, "children">;
|
|
9
|
-
export interface LoadingButtonProps {
|
|
10
|
-
buttonState: LoadingButtonState;
|
|
11
|
-
/**
|
|
12
|
-
* Button label.
|
|
13
|
-
*/
|
|
14
|
-
buttonText: string;
|
|
15
|
-
/**
|
|
16
|
-
* Button label that is displayed on success.
|
|
17
|
-
*/
|
|
18
|
-
buttonTextSuccess?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Provide an icon that is displayed in front of the text
|
|
21
|
-
* when state is successful.
|
|
22
|
-
*/
|
|
23
|
-
successIcon?: JSX.Element | ReactElement;
|
|
24
|
-
/**
|
|
25
|
-
* Adjust the button when the state is any other than successful.
|
|
26
|
-
*/
|
|
27
|
-
loadingButtonProps?: SelectedButtonProps;
|
|
28
|
-
/**
|
|
29
|
-
* Adjust the button when the state is successful.
|
|
30
|
-
*/
|
|
31
|
-
loadingButtonPropsPropsSuccess?: SelectedButtonProps;
|
|
32
|
-
}
|
|
33
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { FormState } from "react-hook-form";
|
|
2
|
-
import { LoadingButtonState } from "./LoadingButtonInterfaces";
|
|
3
|
-
/**
|
|
4
|
-
* Redefinition of mutation status defined by react query. By doing this
|
|
5
|
-
* we don't need to import react-query in the package.
|
|
6
|
-
*/
|
|
7
|
-
declare type MutationStatus = "idle" | "loading" | "success" | "error";
|
|
8
|
-
/**
|
|
9
|
-
* Get loading button state from react-query mutation status.
|
|
10
|
-
*/
|
|
11
|
-
export declare const loadingButtonStateFromReactQueryMutationStatus: (mutationStatus: MutationStatus) => LoadingButtonState;
|
|
12
|
-
/**
|
|
13
|
-
* Get loading button state from a react-hook-form context.
|
|
14
|
-
*/
|
|
15
|
-
export declare const useLoadingButtonStateFromFormContext: () => LoadingButtonState;
|
|
16
|
-
/**
|
|
17
|
-
* Get loading button state from a react-hook-form state.
|
|
18
|
-
*/
|
|
19
|
-
export declare const loadingButtonStateFromFormState: (formState: FormState<any>) => LoadingButtonState;
|
|
20
|
-
export {};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { LoadingButton } from "./LoadingButton";
|
|
2
|
-
export { LoadingButtonState } from "./LoadingButtonInterfaces";
|
|
3
|
-
export type { LoadingButtonProps } from "./LoadingButtonInterfaces";
|
|
4
|
-
export { loadingButtonStateFromFormState, loadingButtonStateFromReactQueryMutationStatus, useLoadingButtonStateFromFormContext, } from "./getLoadingButtonState";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
/**
|
|
3
|
-
* Reexport of FormProvider.
|
|
4
|
-
*
|
|
5
|
-
* This became necessary as context is not available when the FormProvider is initialized outside of the package. Most likely this is some kind of instance mismatch.
|
|
6
|
-
*/
|
|
7
|
-
export declare const HookFormProvider: <TFieldValues extends import("react-hook-form").FieldValues, TContext = any>(props: import("react-hook-form").FormProviderProps<TFieldValues, TContext>) => JSX.Element;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { InputTextProps } from "../baseTypes/InputText/InputText";
|
|
3
|
-
import { FormField } from "../inputTypes";
|
|
4
|
-
export interface InputEmailProps {
|
|
5
|
-
formField: FormField;
|
|
6
|
-
textFieldProps?: InputTextProps["textFieldProps"];
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Renders a MUI input for an email address that is embedded in a react hook form context.
|
|
10
|
-
*/
|
|
11
|
-
export declare const InputEmail: (props: InputEmailProps) => JSX.Element;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { InputPasswordSetProps } from "./InputPasswordSetInterfaces";
|
|
3
|
-
/**
|
|
4
|
-
* Two fields for setting a password set: input & validation.
|
|
5
|
-
*
|
|
6
|
-
* Checks for equality of both.
|
|
7
|
-
*/
|
|
8
|
-
export declare const InputPasswordSet: ({ passwordField, passwordValidationField, doNotMatchError, }: InputPasswordSetProps) => JSX.Element;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { FormField } from "../inputTypes";
|
|
2
|
-
export interface InputPasswordSetProps {
|
|
3
|
-
/**
|
|
4
|
-
* Partial entry, assuming by default a "password"-named field.
|
|
5
|
-
*/
|
|
6
|
-
passwordField: FormField;
|
|
7
|
-
/**
|
|
8
|
-
* Partial entry, assuming by default a "passwordConfirmation"-named field.
|
|
9
|
-
*/
|
|
10
|
-
passwordValidationField: FormField;
|
|
11
|
-
/**
|
|
12
|
-
* Error that is displayed when the passwords do not match.
|
|
13
|
-
*/
|
|
14
|
-
doNotMatchError: string;
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TFunction } from "react-i18next";
|
|
2
|
-
/**
|
|
3
|
-
* Used for static data definitions outside of react:
|
|
4
|
-
* ```.
|
|
5
|
-
* // Static definition, somewhere:
|
|
6
|
-
* const myString = (t) => t("my.string");
|
|
7
|
-
*
|
|
8
|
-
* // Using the translated string inside a component:
|
|
9
|
-
* const t = useTranslation();
|
|
10
|
-
* const string = myString(t);
|
|
11
|
-
* ```.
|
|
12
|
-
*/
|
|
13
|
-
export type TranslatedString = (t: TFunction) => string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { InputAutocompleteProps } from "./InputAutocompleteInterfaces";
|
|
3
|
-
/**
|
|
4
|
-
* Renders a MUI autocomplete input that is embedded in a react hook form context.
|
|
5
|
-
*
|
|
6
|
-
* @throws Error when FormContext is null.
|
|
7
|
-
*/
|
|
8
|
-
export declare const InputAutocomplete: ({ formField, selectableOptions, multiSelect, noOptions, autoCompleteProps, }: InputAutocompleteProps) => JSX.Element;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AutocompleteProps, TextFieldProps } from "@mui/material";
|
|
2
|
-
import { FormField, LabeledValue } from "../../inputTypes";
|
|
3
|
-
interface InputAutocompleteBaseProps {
|
|
4
|
-
formField: FormField;
|
|
5
|
-
selectableOptions: LabeledValue[];
|
|
6
|
-
/**
|
|
7
|
-
* Text that is displayed when there are no more options.
|
|
8
|
-
*/
|
|
9
|
-
noOptions: string;
|
|
10
|
-
}
|
|
11
|
-
export type MuiAutoCompleteNonMultipleProps = Omit<AutocompleteProps<TextFieldProps, false, undefined, undefined>, "multiple">;
|
|
12
|
-
export type MuiAutoCompleteMultipleProps = Omit<AutocompleteProps<TextFieldProps, true, undefined, undefined>, "multiple">;
|
|
13
|
-
interface InputAutocompleteMultipleProps extends InputAutocompleteBaseProps {
|
|
14
|
-
multiSelect: true;
|
|
15
|
-
autoCompleteProps?: MuiAutoCompleteMultipleProps;
|
|
16
|
-
}
|
|
17
|
-
interface InputAutocompleteNonMultipleProps extends InputAutocompleteBaseProps {
|
|
18
|
-
multiSelect: false;
|
|
19
|
-
autoCompleteProps?: MuiAutoCompleteNonMultipleProps;
|
|
20
|
-
}
|
|
21
|
-
export type InputAutocompleteProps = InputAutocompleteNonMultipleProps | InputAutocompleteMultipleProps;
|
|
22
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { CheckboxProps, FormControlLabelProps } from "@mui/material";
|
|
3
|
-
import { FormField } from "../../inputTypes";
|
|
4
|
-
export interface InputCheckboxProps {
|
|
5
|
-
formField: FormField;
|
|
6
|
-
checkboxProps?: Omit<CheckboxProps, "checked">;
|
|
7
|
-
formControlLabelProps?: Omit<FormControlLabelProps, "control" | "label">;
|
|
8
|
-
/**
|
|
9
|
-
* In contrast to other FormFields,
|
|
10
|
-
* the checkbox supports jsx elements as a label.
|
|
11
|
-
*
|
|
12
|
-
* If this is provided, formField.label will be ignored.
|
|
13
|
-
*/
|
|
14
|
-
jsxLabel?: JSX.Element;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Input for Checking a box indicating acceptance of something.
|
|
18
|
-
*/
|
|
19
|
-
export declare const InputCheckbox: ({ formField, jsxLabel, checkboxProps, formControlLabelProps, }: InputCheckboxProps) => JSX.Element;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { TextFieldProps } from "@mui/material";
|
|
3
|
-
import { DateTimePickerProps } from "@mui/x-date-pickers";
|
|
4
|
-
import { FormField } from "../../inputTypes";
|
|
5
|
-
export interface InputDateTimePickerProps {
|
|
6
|
-
formField: FormField;
|
|
7
|
-
dateTimePickerProps?: Pick<DateTimePickerProps<TextFieldProps, TextFieldProps>, "ampm">;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* A Datetime picker that works with react hook form.
|
|
11
|
-
*/
|
|
12
|
-
export declare const InputDateTimePicker: ({ formField, dateTimePickerProps, }: InputDateTimePickerProps) => JSX.Element;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { FormField, LabeledValue } from "../../inputTypes";
|
|
3
|
-
export interface InputRadioProps {
|
|
4
|
-
formField: FormField;
|
|
5
|
-
selectableOptions: LabeledValue[];
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Input for selecting between a list of options using radio buttons.
|
|
9
|
-
*/
|
|
10
|
-
export declare const InputRadio: ({ formField, selectableOptions, }: InputRadioProps) => JSX.Element;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { SelectProps } from "@mui/material";
|
|
3
|
-
import { FormField, LabeledValueWithGrouping } from "../../inputTypes";
|
|
4
|
-
export interface InputSelectProps {
|
|
5
|
-
formField: FormField;
|
|
6
|
-
selectableOptions: LabeledValueWithGrouping[];
|
|
7
|
-
placeholderText: string;
|
|
8
|
-
selectComponentProps?: Pick<SelectProps, "sx">;
|
|
9
|
-
/**
|
|
10
|
-
* Element that is rendered in the end of a select item and holds
|
|
11
|
-
* a tooltip with the disabled message for this option.
|
|
12
|
-
*
|
|
13
|
-
* If none is given the element is disabled without rendering a tooltip.
|
|
14
|
-
*/
|
|
15
|
-
tooltipHolder?: JSX.Element;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Renders a MUI select based that is embedded in a react hook
|
|
19
|
-
* form context.
|
|
20
|
-
*
|
|
21
|
-
* @throws Error when FormContext is null.
|
|
22
|
-
*/
|
|
23
|
-
export declare const InputSelect: ({ formField, selectableOptions, placeholderText, selectComponentProps, tooltipHolder, }: InputSelectProps) => JSX.Element;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { InputSelectFromEnumProps } from "./InputSelectFromEnumInterfaces";
|
|
3
|
-
/**
|
|
4
|
-
* Renders a MUI select based on an enum that is embedded in a react hook form context.
|
|
5
|
-
*/
|
|
6
|
-
export declare const InputSelectFromEnum: <EnumType extends Record<string, string>>({ enumData, formField, placeholderText, }: InputSelectFromEnumProps<EnumType>) => JSX.Element;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TranslatedString } from "../../TranslatedString";
|
|
2
|
-
import { InputSelectProps } from "../InputSelect/InputSelect";
|
|
3
|
-
export interface InputSelectFromEnumProps<EnumType> extends Omit<InputSelectProps, "selectableOptions"> {
|
|
4
|
-
enumData: EnumSelectData<EnumType>;
|
|
5
|
-
placeholderText: string;
|
|
6
|
-
}
|
|
7
|
-
export interface EnumSelectData<EnumType> {
|
|
8
|
-
enumToUse: EnumType;
|
|
9
|
-
labelsForEnum: Record<keyof EnumType, TranslatedString | string>;
|
|
10
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { OutlinedInputProps } from "@mui/material";
|
|
3
|
-
import { FormField } from "../../inputTypes";
|
|
4
|
-
export interface InputTextProps {
|
|
5
|
-
formField: FormField;
|
|
6
|
-
textFieldProps?: Omit<OutlinedInputProps, "required" | "label">;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Renders a MUI input text fields that is embedded in a react
|
|
10
|
-
* hook form context.
|
|
11
|
-
*
|
|
12
|
-
* @throws Error when FormContext is null.
|
|
13
|
-
*/
|
|
14
|
-
export declare const InputText: ({ formField, textFieldProps, }: InputTextProps) => JSX.Element | null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const formContextNull = "FormContext is null. This should not happen. You may need to use the HookFormProvider instead of the FormProvider exported by react-hook-form";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AnyObject } from "@nvon/baseline";
|
|
2
|
-
import { 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
|
-
export declare const getFormError: (errors: FormState<AnyObject>["errors"], fieldName: string) => FieldError | undefined;
|
|
@@ -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,50 +0,0 @@
|
|
|
1
|
-
import { FieldPath, FieldValues, 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: keyof import("react-hook-form").ValidationMode;
|
|
28
|
-
reValidateMode: "onBlur" | "onChange" | "onSubmit";
|
|
29
|
-
defaultValues: import("react-hook-form").DeepPartial<TFieldValues> | ((payload?: unknown) => Promise<TFieldValues>);
|
|
30
|
-
values: TFieldValues;
|
|
31
|
-
resetOptions: Partial<{
|
|
32
|
-
keepDirtyValues: boolean;
|
|
33
|
-
keepErrors: boolean;
|
|
34
|
-
keepDirty: boolean;
|
|
35
|
-
keepValues: boolean;
|
|
36
|
-
keepDefaultValues: boolean;
|
|
37
|
-
keepIsSubmitted: boolean;
|
|
38
|
-
keepTouched: boolean;
|
|
39
|
-
keepIsValid: boolean;
|
|
40
|
-
keepSubmitCount: boolean;
|
|
41
|
-
}> | undefined;
|
|
42
|
-
resolver: import("react-hook-form").Resolver<TFieldValues, any>;
|
|
43
|
-
context: any;
|
|
44
|
-
shouldFocusError: boolean;
|
|
45
|
-
shouldUnregister: boolean;
|
|
46
|
-
shouldUseNativeValidation: boolean;
|
|
47
|
-
criteriaMode: import("react-hook-form").CriteriaMode;
|
|
48
|
-
delayError: number;
|
|
49
|
-
}> | undefined) => FormReturn<TFieldValues>;
|
|
50
|
-
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,28 +0,0 @@
|
|
|
1
|
-
export { HookFormProvider } from "./HookFormProvider";
|
|
2
|
-
export { InputEmail } from "./InputEmail/InputEmail";
|
|
3
|
-
export type { InputEmailProps } from "./InputEmail/InputEmail";
|
|
4
|
-
export { InputPasswordSet } from "./InputPasswordSet/InputPasswordSet";
|
|
5
|
-
export type { InputPasswordSetProps } from "./InputPasswordSet/InputPasswordSetInterfaces";
|
|
6
|
-
export type { TranslatedString } from "./TranslatedString";
|
|
7
|
-
export { InputAutocomplete } from "./baseTypes/InputAutocomplete/InputAutocomplete";
|
|
8
|
-
export type { InputAutocompleteProps } from "./baseTypes/InputAutocomplete/InputAutocompleteInterfaces";
|
|
9
|
-
export { InputCheckbox } from "./baseTypes/InputCheckbox/InputCheckbox";
|
|
10
|
-
export type { InputCheckboxProps } from "./baseTypes/InputCheckbox/InputCheckbox";
|
|
11
|
-
export { InputDateTimePicker } from "./baseTypes/InputDateTimePicker/InputDateTimePicker";
|
|
12
|
-
export type { InputDateTimePickerProps } from "./baseTypes/InputDateTimePicker/InputDateTimePicker";
|
|
13
|
-
export { InputRadio } from "./baseTypes/InputRadio/InputRadio";
|
|
14
|
-
export type { InputRadioProps } from "./baseTypes/InputRadio/InputRadio";
|
|
15
|
-
export { InputSelect } from "./baseTypes/InputSelect/InputSelect";
|
|
16
|
-
export type { InputSelectProps } from "./baseTypes/InputSelect/InputSelect";
|
|
17
|
-
export { InputSelectFromEnum } from "./baseTypes/InputSelectFromEnum/InputSelectFromEnum";
|
|
18
|
-
export type { InputSelectFromEnumProps } from "./baseTypes/InputSelectFromEnum/InputSelectFromEnumInterfaces";
|
|
19
|
-
export { InputText } from "./baseTypes/InputText/InputText";
|
|
20
|
-
export type { InputTextProps } from "./baseTypes/InputText/InputText";
|
|
21
|
-
export { getFormError } from "./formHelper/getFormError";
|
|
22
|
-
export { syncSubmit } from "./formHelper/syncSubmit";
|
|
23
|
-
export { useHookForm } from "./formHelper/useHookForm";
|
|
24
|
-
export { useHookFormContext } from "./formHelper/useHookFormContext";
|
|
25
|
-
export { useMergedFormField } from "./formHelper/useMergedFormField";
|
|
26
|
-
export { useSortedOptionsWithGroup } from "./formHelper/useSortedOptionsWithGroup";
|
|
27
|
-
export { useTranslateString } from "./formHelper/useTranslateString";
|
|
28
|
-
export type { FormField, FormFieldTranslated, LabeledValue, TranslatedValidate, } from "./inputTypes";
|
|
@@ -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;
|
|
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,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is the main package file, containing everything that our package exports.
|
|
3
|
-
*/
|
|
4
|
-
export { LoadingButton, LoadingButtonState, loadingButtonStateFromFormState, loadingButtonStateFromReactQueryMutationStatus, useLoadingButtonStateFromFormContext, } from "./LoadingButton";
|
|
5
|
-
export type { LoadingButtonProps } from "./LoadingButton";
|
|
6
|
-
export { HookFormProvider, InputAutocomplete, InputCheckbox, InputDateTimePicker, InputEmail, InputPasswordSet, InputRadio, InputSelect, InputSelectFromEnum, InputText, getFormError, syncSubmit, useHookForm, useHookFormContext, useMergedFormField, useSortedOptionsWithGroup, useTranslateString, } from "./formFields";
|
|
7
|
-
export type { FormField, FormFieldTranslated, InputAutocompleteProps, InputCheckboxProps, InputDateTimePickerProps, InputEmailProps, InputPasswordSetProps, InputRadioProps, InputSelectFromEnumProps, InputSelectProps, InputTextProps, LabeledValue, TranslatedString, TranslatedValidate, } from "./formFields/";
|