-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add defaultValue on each form component
- Loading branch information
1 parent
37338c1
commit 8163d00
Showing
8 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TextFieldProps, "onChange">; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
autocomplete?: any; | ||
}; | ||
|
||
const MuiRhfAutocompleteMultiple: React.FC<MuiRhfAutocompleteProps> = ({ | ||
defaultValue = [], | ||
autocomplete: autocompleteProps = {}, | ||
...rest | ||
}) => ( | ||
<MuiRhfAutocomplete | ||
{...rest} | ||
autocomplete={{ ...autocompleteProps, multiple: true }} | ||
defaultValue={defaultValue} | ||
/> | ||
); | ||
|
||
export default MuiRhfAutocompleteMultiple; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TextFieldProps, "onChange">; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
autocomplete?: any; | ||
}; | ||
|
||
const MuiRhfAutocompleteSingle: React.FC<MuiRhfAutocompleteProps> = ({ | ||
defaultValue = null, | ||
autocomplete: autocompleteProps = {}, | ||
...rest | ||
}) => ( | ||
<MuiRhfAutocomplete | ||
{...rest} | ||
autocomplete={{ ...autocompleteProps, multiple: false }} | ||
defaultValue={defaultValue} | ||
/> | ||
); | ||
|
||
export default MuiRhfAutocompleteSingle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import MuiRhfTextField from "~/components/MuiRhfTextField"; | ||
import MuiRhfSelect from "~/components/MuiRhfSelect"; | ||
import MuiRhfCheckbox from "~/components/MuiRhfCheckbox"; | ||
import MuiRhfAutocomplete from "~/components/MuiRhfAutocomplete"; | ||
import MuiRhfAutocompleteSingle from "~/components/MuiRhfAutocompleteSingle"; | ||
import MuiRhfAutocompleteMultiple from "~/components/MuiRhfAutocompleteMultiple"; | ||
|
||
import { MuiRhfFieldComponentMap } from "./typing"; | ||
|
||
export const fieldComponentMap: MuiRhfFieldComponentMap = { | ||
textField: MuiRhfTextField, | ||
select: MuiRhfSelect, | ||
checkbox: MuiRhfCheckbox, | ||
autocomplete: MuiRhfAutocomplete, | ||
autocompleteSingle: MuiRhfAutocompleteSingle, | ||
autocompleteMultiple: MuiRhfAutocompleteMultiple, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters