2024-01-29 11:26:10 +00:00
|
|
|
import { FormControl, TextField as MuiTextField, SxProps, Theme, useTheme } from "@mui/material";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-29 11:26:10 +00:00
|
|
|
import type { InputProps, TextFieldProps } from "@mui/material";
|
|
|
|
import type { ChangeEvent, FC, FocusEvent, KeyboardEvent } from "react";
|
2024-05-31 16:41:18 +00:00
|
|
|
import { Answer } from "@stores/quizView.ts";
|
2024-01-29 11:26:10 +00:00
|
|
|
|
|
|
|
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
interface CustomTextFieldProps {
|
2024-05-31 16:41:18 +00:00
|
|
|
placeholder: string;
|
|
|
|
value?: Answer;
|
|
|
|
error?: string;
|
|
|
|
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
|
|
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
|
|
|
onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
|
|
|
|
text?: string;
|
|
|
|
sx?: SxProps<Theme>;
|
|
|
|
InputProps?: Partial<InputProps>;
|
2023-12-16 14:55:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function CustomTextField({
|
2024-05-31 16:41:18 +00:00
|
|
|
placeholder,
|
|
|
|
value,
|
|
|
|
text,
|
|
|
|
sx,
|
|
|
|
error,
|
|
|
|
onChange,
|
|
|
|
onKeyDown,
|
|
|
|
onBlur,
|
|
|
|
InputProps,
|
2023-12-16 14:55:56 +00:00
|
|
|
}: CustomTextFieldProps) {
|
2024-05-31 16:41:18 +00:00
|
|
|
const theme = useTheme();
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-05-31 16:41:18 +00:00
|
|
|
return (
|
|
|
|
<FormControl fullWidth variant="standard" sx={{ p: 0 }}>
|
|
|
|
<TextField
|
|
|
|
defaultValue={text}
|
|
|
|
fullWidth
|
|
|
|
value={value}
|
|
|
|
placeholder={placeholder}
|
|
|
|
error={!!error}
|
|
|
|
label={error}
|
|
|
|
onChange={onChange}
|
|
|
|
onKeyDown={onKeyDown}
|
|
|
|
onBlur={onBlur}
|
|
|
|
sx={{
|
|
|
|
"& .MuiInputBase-root": {
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
height: "48px",
|
|
|
|
borderRadius: "10px",
|
|
|
|
},
|
|
|
|
"& .MuiInputLabel-root": {
|
|
|
|
fontSize: "13.5px",
|
|
|
|
marginTop: "3px",
|
|
|
|
},
|
|
|
|
...sx,
|
|
|
|
}}
|
|
|
|
InputProps={InputProps}
|
|
|
|
inputProps={{
|
|
|
|
sx: {
|
|
|
|
borderRadius: "10px",
|
|
|
|
fontSize: "18px",
|
|
|
|
lineHeight: "21px",
|
|
|
|
py: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
data-cy="textfield"
|
|
|
|
/>
|
|
|
|
</FormControl>
|
|
|
|
);
|
2023-12-16 14:55:56 +00:00
|
|
|
}
|