39 lines
764 B
TypeScript
39 lines
764 B
TypeScript
|
|
import { FC } from "react";
|
||
|
|
import { TextField as InternalTextField } from "@mui/material";
|
||
|
|
|
||
|
|
type TextFieldProps = {
|
||
|
|
name: string;
|
||
|
|
label: string;
|
||
|
|
formState: Record<string, any>;
|
||
|
|
required?: boolean;
|
||
|
|
lines?: number;
|
||
|
|
helperText?: string;
|
||
|
|
};
|
||
|
|
|
||
|
|
export const TextField: FC<TextFieldProps> = ({
|
||
|
|
name,
|
||
|
|
label,
|
||
|
|
formState,
|
||
|
|
required = false,
|
||
|
|
lines = 1,
|
||
|
|
helperText,
|
||
|
|
}) => (
|
||
|
|
<InternalTextField
|
||
|
|
fullWidth
|
||
|
|
name={name}
|
||
|
|
label={label}
|
||
|
|
size="small"
|
||
|
|
multiline={lines > 1}
|
||
|
|
rows={lines}
|
||
|
|
required={required}
|
||
|
|
defaultValue={formState.values[name]}
|
||
|
|
error={Boolean(formState.errors[name])}
|
||
|
|
helperText={formState.errors[name] ?? helperText}
|
||
|
|
InputProps={{
|
||
|
|
sx: {
|
||
|
|
backgroundColor: "#fff",
|
||
|
|
},
|
||
|
|
}}
|
||
|
|
/>
|
||
|
|
);
|