frontPanel/src/ui_kit/CustomTextField.tsx

70 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-09-12 09:56:15 +00:00
import {
FormControl,
TextField,
useTheme,
SxProps,
Theme,
} from "@mui/material";
import type { ChangeEvent, KeyboardEvent, FocusEvent } from "react";
interface CustomTextFieldProps {
2023-09-12 09:56:15 +00:00
placeholder: string;
2023-09-12 14:36:22 +00:00
value?: string;
2023-09-12 15:57:48 +00:00
error?: string;
2023-09-12 09:56:15 +00:00
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
text?: string;
sx?: SxProps<Theme>;
}
2023-09-12 09:56:15 +00:00
export default function CustomTextField({
placeholder,
2023-09-12 14:36:22 +00:00
value,
2023-09-12 09:56:15 +00:00
text,
sx,
2023-09-12 15:57:48 +00:00
error,
2023-09-12 09:56:15 +00:00
onChange,
onKeyDown,
onBlur,
}: CustomTextFieldProps) {
const theme = useTheme();
2023-09-12 09:56:15 +00:00
return (
<FormControl fullWidth variant="standard" sx={{ p: 0 }}>
<TextField
defaultValue={text}
fullWidth
2023-09-12 14:36:22 +00:00
value={value}
2023-09-12 09:56:15 +00:00
placeholder={placeholder}
2023-09-12 15:57:48 +00:00
error={!!error}
label={error}
2023-09-12 09:56:15 +00:00
onChange={onChange}
onKeyDown={onKeyDown}
onBlur={onBlur}
sx={{
"& .MuiInputBase-root": {
backgroundColor: theme.palette.background.default,
height: "48px",
borderRadius: "10px",
},
2023-09-12 15:57:48 +00:00
"& .MuiInputLabel-root": {
fontSize: "13.5px",
marginTop: "3px",
},
2023-09-12 09:56:15 +00:00
...sx,
}}
inputProps={{
sx: {
borderRadius: "10px",
fontSize: "18px",
lineHeight: "21px",
py: 0,
},
}}
/>
</FormControl>
);
}