From 8163d005c909d5e78200857330300e680e1d2b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Faure?= Date: Sun, 28 Mar 2021 18:44:28 +0200 Subject: [PATCH] Add defaultValue on each form component --- src/components/MuiRhfAutocompleteMultiple.tsx | 28 +++++++++++++++++++ src/components/MuiRhfAutocompleteSingle.tsx | 28 +++++++++++++++++++ src/components/MuiRhfCheckbox.tsx | 2 +- src/components/MuiRhfSelect.tsx | 2 +- src/components/MuiRhfTextField.tsx | 2 +- src/components/index.tsx | 4 +-- src/models/form/consts.ts | 6 ++-- src/models/form/typing.ts | 3 +- 8 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/components/MuiRhfAutocompleteMultiple.tsx create mode 100644 src/components/MuiRhfAutocompleteSingle.tsx diff --git a/src/components/MuiRhfAutocompleteMultiple.tsx b/src/components/MuiRhfAutocompleteMultiple.tsx new file mode 100644 index 0000000..048b3e5 --- /dev/null +++ b/src/components/MuiRhfAutocompleteMultiple.tsx @@ -0,0 +1,28 @@ +import * as React from "react"; + +import { TextFieldProps } from "@material-ui/core"; + +import { MuiRhfFieldProps } from "~/models/fields"; + +import MuiRhfAutocomplete from "./MuiRhfAutocomplete"; + +type MuiRhfAutocompleteProps = MuiRhfFieldProps & { + defaultValue?: unknown; + textField?: Omit; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + autocomplete?: any; +}; + +const MuiRhfAutocompleteMultiple: React.FC = ({ + defaultValue = [], + autocomplete: autocompleteProps = {}, + ...rest +}) => ( + +); + +export default MuiRhfAutocompleteMultiple; diff --git a/src/components/MuiRhfAutocompleteSingle.tsx b/src/components/MuiRhfAutocompleteSingle.tsx new file mode 100644 index 0000000..4f5d186 --- /dev/null +++ b/src/components/MuiRhfAutocompleteSingle.tsx @@ -0,0 +1,28 @@ +import * as React from "react"; + +import { TextFieldProps } from "@material-ui/core"; + +import { MuiRhfFieldProps } from "~/models/fields"; + +import MuiRhfAutocomplete from "./MuiRhfAutocomplete"; + +type MuiRhfAutocompleteProps = MuiRhfFieldProps & { + defaultValue?: unknown; + textField?: Omit; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + autocomplete?: any; +}; + +const MuiRhfAutocompleteSingle: React.FC = ({ + defaultValue = null, + autocomplete: autocompleteProps = {}, + ...rest +}) => ( + +); + +export default MuiRhfAutocompleteSingle; diff --git a/src/components/MuiRhfCheckbox.tsx b/src/components/MuiRhfCheckbox.tsx index 9a33428..5e19f11 100644 --- a/src/components/MuiRhfCheckbox.tsx +++ b/src/components/MuiRhfCheckbox.tsx @@ -15,7 +15,7 @@ const MuiRhfCheckbox: React.FC = ({ control, errors, name, - defaultValue, + defaultValue = false, label, required, disabled, diff --git a/src/components/MuiRhfSelect.tsx b/src/components/MuiRhfSelect.tsx index ba6e0c2..4b835ff 100644 --- a/src/components/MuiRhfSelect.tsx +++ b/src/components/MuiRhfSelect.tsx @@ -17,7 +17,7 @@ const MuiRhfSelect: React.FC = ({ errors, name, label, - defaultValue, + defaultValue = "", options, select: selectProps, }) => ( diff --git a/src/components/MuiRhfTextField.tsx b/src/components/MuiRhfTextField.tsx index 60098ea..2d1dc1e 100644 --- a/src/components/MuiRhfTextField.tsx +++ b/src/components/MuiRhfTextField.tsx @@ -10,7 +10,7 @@ const MuiRhfTextField: React.FC = ({ control, errors, name, - defaultValue, + defaultValue = "", ...rest }) => ( ; select: React.FC; checkbox: React.FC; - autocomplete: React.FC; + autocompleteSingle: React.FC; + autocompleteMultiple: React.FC; }; /** Form */