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 = ({
|
2024-07-12 19:27:47 -04:00
|
|
|
type = "text",
|
2024-07-12 18:45:23 -04:00
|
|
|
id,
|
|
|
|
|
label,
|
|
|
|
|
isRequired,
|
2024-07-12 20:01:41 -04:00
|
|
|
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 && (
|
2024-07-12 19:27:47 -04:00
|
|
|
<Typography component="h3">
|
2024-07-12 18:45:23 -04:00
|
|
|
{label}
|
2024-07-12 20:01:41 -04:00
|
|
|
{isRequired ? <span className="field-required">*</span> : ""}
|
|
|
|
|
{isOptional ? <span className="field-optional">(optional)</span> : ""}
|
2024-07-12 18:45:23 -04:00
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
<TextField
|
2024-07-12 19:27:47 -04:00
|
|
|
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}
|
2024-07-12 19:27:47 -04:00
|
|
|
InputProps={{
|
|
|
|
|
startAdornment: type === "url" && (
|
2024-07-12 20:01:41 -04:00
|
|
|
<Stack
|
|
|
|
|
direction="row"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
height="100%"
|
|
|
|
|
sx={{
|
|
|
|
|
borderRight: `solid 1px ${theme.palette.section.borderColor}`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography component="h5">https://</Typography>
|
|
|
|
|
</Stack>
|
2024-07-12 19:27:47 -04:00
|
|
|
),
|
|
|
|
|
endAdornment: type === "password" && (
|
|
|
|
|
<InputAdornment position="end">
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="toggle password visibility"
|
|
|
|
|
onClick={() => setVisibility((show) => !show)}
|
|
|
|
|
tabIndex={-1}
|
|
|
|
|
sx={{
|
|
|
|
|
color: theme.palette.section.borderColor,
|
2024-07-13 13:11:03 -04:00
|
|
|
padding: `calc(${theme.gap.xs} / 2)`,
|
2024-07-12 19:27:47 -04:00
|
|
|
"&:focus": {
|
|
|
|
|
outline: "none",
|
|
|
|
|
},
|
|
|
|
|
"& .MuiTouchRipple-root": {
|
|
|
|
|
pointerEvents: "none",
|
|
|
|
|
display: "none",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{!isVisible ? <VisibilityOff /> : <Visibility />}
|
|
|
|
|
</IconButton>
|
|
|
|
|
</InputAdornment>
|
|
|
|
|
),
|
|
|
|
|
}}
|
2024-07-12 18:45:23 -04:00
|
|
|
/>
|
|
|
|
|
{error && (
|
2024-07-12 19:27:47 -04:00
|
|
|
<Typography component="span" className="input-error" mt={theme.gap.xs}>
|
2024-07-12 18:45:23 -04:00
|
|
|
{error}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Field;
|