Files
Checkmate/Client/src/Components/TextFields/Field/index.jsx
T

93 lines
2.4 KiB
React
Raw Normal View History

2024-07-12 18:45:23 -04:00
import { useTheme } from "@emotion/react";
import {
IconButton,
InputAdornment,
Stack,
TextField,
Typography,
} from "@mui/material";
import VisibilityOff from "@mui/icons-material/VisibilityOff";
import Visibility from "@mui/icons-material/Visibility";
import "./index.css";
const Field = ({
type = "text",
2024-07-12 18:45:23 -04:00
id,
label,
isRequired,
isOptional,
2024-07-12 18:45:23 -04:00
isVisible,
setVisibility,
autoComplete,
placeholder,
value,
onChange,
error,
disabled,
}) => {
const theme = useTheme();
return (
<Stack gap={theme.gap.xs} className={`field field-${type}`}>
{label && (
<Typography component="h3">
2024-07-12 18:45:23 -04:00
{label}
{isRequired ? <span className="field-required">*</span> : ""}
{isOptional ? <span className="field-optional">(optional)</span> : ""}
2024-07-12 18:45:23 -04:00
</Typography>
)}
<TextField
type={type === "password" ? (isVisible ? "text" : type) : type}
2024-07-12 18:45:23 -04:00
id={id}
autoComplete={autoComplete}
placeholder={placeholder}
value={value}
onChange={onChange}
disabled={disabled}
InputProps={{
startAdornment: type === "url" && (
<Stack
direction="row"
alignItems="center"
height="100%"
sx={{
borderRight: `solid 1px ${theme.palette.section.borderColor}`,
}}
>
<Typography component="h5">https://</Typography>
</Stack>
),
endAdornment: type === "password" && (
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={() => setVisibility((show) => !show)}
tabIndex={-1}
sx={{
color: theme.palette.section.borderColor,
padding: theme.gap.xs,
"&:focus": {
outline: "none",
},
"& .MuiTouchRipple-root": {
pointerEvents: "none",
display: "none",
},
}}
>
{!isVisible ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
),
}}
2024-07-12 18:45:23 -04:00
/>
{error && (
<Typography component="span" className="input-error" mt={theme.gap.xs}>
2024-07-12 18:45:23 -04:00
{error}
</Typography>
)}
</Stack>
);
};
export default Field;