import PropTypes from "prop-types"; 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 ContentCopyIcon from "@mui/icons-material/ContentCopy"; import Button from "../../Button"; import "./index.css"; import { useState } from "react"; /** * @param {Object} props * @param {string} [props.type] - Type of input field (e.g., 'text', 'password'). * @param {string} props.id - ID of the input field. * @param {string} [props.label] - Label for the input field. * @param {boolean} [props.https] - Indicates if it should display http or https. * @param {boolean} [props.isRequired] - Indicates if the field is required, will display a red asterisk. * @param {boolean} [props.isOptional] - Indicates if the field is optional, will display optional text. * @param {string} [props.optionalLabel] - Optional label for the input field. * @param {boolean} [props.hasCopy] - Indicates if the field supports copying. * @param {string} [props.autoComplete] - Autocomplete value for the input field. * @param {string} [props.placeholder] - Placeholder text for the input field. * @param {string} props.value - Value of the input field. * @param {function} props.onChange - Function called on input change. * @param {string} [props.error] - Error message to display for the input field. * @param {boolean} [props.disabled] - Indicates if the input field is disabled. */ const Field = ({ type = "text", id, label, https, isRequired, isOptional, optionalLabel, hasCopy, autoComplete, placeholder, value, onChange, error, disabled, }) => { const theme = useTheme(); // TODO - are we using this feature anywhere ? const [copy, setCopy] = useState(false); const handleCopy = () => { setCopy(true); setTimeout(() => setCopy(false), 1000); }; const [isVisible, setVisible] = useState(false); return ( {label && ( {label} {isRequired ? * : ""} {isOptional ? ( {optionalLabel || "(optional)"} ) : ( "" )} )} {https ? "https" : "http"}:// ), endAdornment: type === "password" ? ( setVisible((show) => !show)} tabIndex={-1} sx={{ color: theme.palette.section.borderColor, padding: `calc(${theme.gap.xs} / 2)`, "&:focus": { outline: "none", }, "& .MuiTouchRipple-root": { pointerEvents: "none", display: "none", }, }} > {!isVisible ? : } ) : ( hasCopy && (