front-hub/src/components/InputTextfield.tsx

95 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-03-18 15:52:18 +00:00
import {
2023-07-07 13:49:14 +00:00
FormControl,
InputLabel,
SxProps,
TextField,
TextFieldProps,
Theme,
useMediaQuery,
useTheme,
2023-03-18 15:52:18 +00:00
} from "@mui/material";
2022-11-19 20:31:42 +00:00
2023-07-06 21:52:07 +00:00
import "./text-input.css";
2022-11-19 20:31:42 +00:00
interface Props {
2023-07-07 13:49:14 +00:00
id: string;
label?: string;
bold?: boolean;
gap?: string;
color?: string;
FormInputSx?: SxProps<Theme>;
TextfieldProps: TextFieldProps;
onChange: (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
2022-11-19 20:31:42 +00:00
}
2023-03-18 15:52:18 +00:00
export default function InputTextfield({
2023-07-07 13:49:14 +00:00
id,
label,
bold = false,
gap = "10px",
onChange,
TextfieldProps,
color,
FormInputSx,
2023-03-18 15:52:18 +00:00
}: Props) {
2023-07-07 13:49:14 +00:00
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
2022-11-19 20:31:42 +00:00
2023-07-07 13:49:14 +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-07-07 13:49:14 +00:00
const placeholderFont = upMd ? undefined : { fontWeight: 400, fontSize: "16px", lineHeight: "19px" };
2022-11-19 20:31:42 +00:00
2023-07-07 13:49:14 +00:00
return (
<FormControl
fullWidth
variant="standard"
sx={{
gap,
// mt: "10px",
...FormInputSx,
}}
>
{label &&
<InputLabel
shrink
htmlFor={id}
sx={{
position: "inherit",
color: "black",
transform: "none",
...labelFont,
}}
>
{label}
</InputLabel>
}
<TextField
{...TextfieldProps}
fullWidth
id={id}
sx={{
"& .MuiInputBase-root": {
height: "48px",
borderRadius: "8px",
},
}}
inputProps={{
sx: {
backgroundColor: color,
borderRadius: "8px",
height: "48px",
py: 0,
color: "black",
...placeholderFont,
},
}}
onChange={onChange}
/>
</FormControl>
);
2023-03-18 15:52:18 +00:00
}