link-stack/packages/ui/components/TextField.tsx

39 lines
764 B
TypeScript
Raw Normal View History

2024-04-24 21:44:05 +02:00
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",
},
}}
/>
);