diff --git a/src/components/AuthUser/SignInForm/InputField/InputField.tsx b/src/components/AuthUser/SignInForm/InputField/InputField.tsx new file mode 100644 index 0000000000000000000000000000000000000000..a0093c9c7bacc5ab2a82c2a924b83e12100332f8 --- /dev/null +++ b/src/components/AuthUser/SignInForm/InputField/InputField.tsx @@ -0,0 +1,46 @@ +import React, { FC } from 'react'; +import { TextField } from '@material-ui/core'; +import { Control, Controller, FieldValues } from 'react-hook-form'; + +type Props = { + /** + * Name of the elemement. ex. email, password + */ + name: string; + label: string; + error: boolean; + errorMessage: string; + /** + * react-hook-form control + */ + control: Control<FieldValues> | undefined; + rules: Partial<unknown>; +}; + +export const InputField: FC<Props> = (props: Props) => { + const { name, label, error, errorMessage, control, rules } = props; + return ( + <Controller + name={name} + control={control} + rules={rules} + render={({ onChange, value }) => ( + <TextField + variant="outlined" + margin="normal" + required + fullWidth + id={name} + label={label} + name={name} + onChange={onChange} + value={value} + autoComplete={name} + autoFocus + error={error} + helperText={error && errorMessage} + /> + )} + /> + ); +};