front-hub/src/components/InputTextfield.tsx

108 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-03-18 15:52:18 +00:00
import {
2023-11-05 23:33:40 +00:00
FormControl,
InputLabel,
SxProps,
TextField,
TextFieldProps,
Theme,
useMediaQuery,
useTheme,
} from "@mui/material"
2022-11-19 20:31:42 +00:00
2023-11-05 23:33:40 +00:00
import "./text-input.css"
2023-07-06 21:52:07 +00:00
2022-11-19 20:31:42 +00:00
interface Props {
2023-08-04 08:21:15 +00:00
id: string;
label?: string;
bold?: boolean;
gap?: string;
color?: string;
FormInputSx?: SxProps<Theme>;
TextfieldProps: TextFieldProps;
onChange: (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
onBlur?: () => void
onFocus?: () => void
2022-11-19 20:31:42 +00:00
}
2023-03-18 15:52:18 +00:00
export default function InputTextfield({
2023-11-05 23:33:40 +00:00
id,
label,
bold = false,
gap = "10px",
onChange,
TextfieldProps,
color,
FormInputSx,
onBlur = ()=>{},
onFocus = ()=>{}
2023-03-18 15:52:18 +00:00
}: Props) {
2023-11-05 23:33:40 +00:00
const theme = useTheme()
const upMd = useMediaQuery(theme.breakpoints.up("md"))
2022-11-19 20:31:42 +00:00
2023-11-05 23:33:40 +00:00
const labelFont = upMd
? bold
? theme.typography.p1
: { ...theme.typography.body1, fontWeight: 500 }
: theme.typography.body2
2022-11-25 18:50:37 +00:00
2023-11-05 23:33:40 +00:00
const placeholderFont = upMd ? undefined : { fontWeight: 400, fontSize: "16px", lineHeight: "19px" }
2022-11-19 20:31:42 +00:00
2023-11-05 23:33:40 +00:00
return (
<FormControl
2023-11-05 23:33:40 +00:00
fullWidth
variant="standard"
sx={{
gap,
// mt: "10px",
...FormInputSx,
}}
>
{label && (
<InputLabel
shrink
htmlFor={id}
sx={{
position: "inherit",
color: "black",
transform: "none",
...labelFont,
}}
>
{label}
</InputLabel>
)}
<TextField
onBlur={(e) => {
onBlur()
}}
onFocus={(e) => {
onFocus()
}}
2023-11-05 23:33:40 +00:00
{...TextfieldProps}
fullWidth
id={id}
sx={{
"& .MuiInputBase-root": {
height: "48px",
borderRadius: "8px",
},
}}
inputProps={{
sx: {
boxSizing: "border-box",
backgroundColor: color,
border: "1px solid" + theme.palette.gray.main,
borderRadius: "8px",
height: "48px",
py: 0,
color: "black",
...placeholderFont,
},
}}
onChange={onChange}
/>
</FormControl>
)
2023-03-18 15:52:18 +00:00
}