front-hub/src/components/passwordInput.tsx

129 lines
3.1 KiB
TypeScript
Raw Normal View History

import {
2023-08-04 08:21:15 +00:00
FormControl,
IconButton,
InputLabel,
SxProps,
TextField,
TextFieldProps,
Theme,
useMediaQuery,
useTheme,
} from "@mui/material";
import * as React from "react";
import InputAdornment from "@mui/material/InputAdornment";
import Visibility from "@mui/icons-material/Visibility";
import VisibilityOff from "@mui/icons-material/VisibilityOff";
2023-08-04 08:21:15 +00:00
interface Props {
id: string;
label?: string;
bold?: boolean;
gap?: string;
color?: string;
FormInputSx?: SxProps<Theme>;
TextfieldProps: TextFieldProps;
2023-08-05 22:15:18 +00:00
onChange: (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
2023-08-04 08:21:15 +00:00
}
2023-08-04 08:21:15 +00:00
export default function PasswordInput({
id,
label,
bold = false,
gap = "10px",
onChange,
TextfieldProps,
color,
FormInputSx,
}: Props) {
const theme = useTheme();
const upMd = useMediaQuery(theme.breakpoints.up("md"));
2023-08-04 08:21:15 +00:00
const labelFont = upMd
? bold
? theme.typography.p1
: { ...theme.typography.body1, fontWeight: 500 }
: theme.typography.body2;
2023-08-05 22:15:18 +00:00
const placeholderFont = upMd ? undefined : { fontWeight: 400, fontSize: "16px", lineHeight: "19px" };
2023-08-04 08:21:15 +00:00
const [showPassword, setShowPassword] = React.useState(false);
const handleClickShowPassword = () => setShowPassword((show) => !show);
2023-08-05 22:15:18 +00:00
const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => {
2023-08-04 08:21:15 +00:00
event.preventDefault();
};
return (
<FormControl
fullWidth
variant="standard"
sx={{
gap,
// mt: "10px",
...FormInputSx,
position: "relative",
}}
>
<InputLabel
shrink
htmlFor={id}
sx={{
2023-08-04 08:21:15 +00:00
position: "inherit",
color: "black",
transform: "none",
...labelFont,
}}
>
2023-08-04 08:21:15 +00:00
{label}
</InputLabel>
<TextField
{...TextfieldProps}
fullWidth
id={id}
sx={{
"& .MuiInputBase-root": {
height: "48px",
borderRadius: "8px",
},
}}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
sx={{
position: "absolute",
right: "15px",
top: "5px",
}}
>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
),
sx: {
padding: "0px",
2023-08-22 10:28:22 +00:00
border: "1px solid" + theme.palette.gray.main,
2023-08-04 08:21:15 +00:00
backgroundColor: color,
borderRadius: "8px",
height: "48px",
color: "black",
2023-08-04 08:21:15 +00:00
...placeholderFont,
"& .MuiInputBase-input": {
boxSizing: "border-box",
height: "100%",
padding: "14px",
},
2023-08-04 08:21:15 +00:00
},
}}
onChange={onChange}
type={showPassword ? "text" : "password"}
/>
</FormControl>
);
}