Files
Checkmate/Client/src/Components/TextFields/Email/EmailTextField.jsx
T

98 lines
3.3 KiB
React
Raw Normal View History

2024-05-15 09:40:50 +03:30
import React, { useState } from "react";
import "./emailTextField.css";
import { InputAdornment, TextField } from "@mui/material";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
import { useTheme } from "@mui/material";
/**
2024-05-24 22:17:12 +03:30
* `EmailTextField` is a functional React component that renders a text field for email input.
*
2024-05-15 09:40:50 +03:30
* @component
2024-05-24 22:17:12 +03:30
* @param {Object} props - The properties that define the `EmailTextField` component.
2024-06-06 11:41:34 -07:00
* @param {function} props.onChange - The function to call when the text field changes.
2024-05-24 22:17:12 +03:30
* @param {string} props.id - The id of the text field.
* @param {string} [props.label="Email"] - The label of the text field.
* @param {string} props.variant - The variant of the text field.
* @param {string} props.placeholder - The placeholder of the text field.
* @param {React.Element} props.icon - The icon to be displayed in the text field.
* @param {string} props.helperText - The helper text to be displayed below the text field.
* @param {boolean} props.error - If true, the text field will indicate an error state.
*
* @example
* // To use this component, import it and use it in your JSX like this:
* <EmailTextField id="email" variant="outlined" placeholder="Enter your email" />
*
* @returns {React.Element} The `EmailTextField` component with a text field for email input.
2024-05-15 09:40:50 +03:30
*/
2024-05-24 22:17:12 +03:30
2024-05-15 09:40:50 +03:30
const EmailTextField = ({
2024-06-06 11:41:34 -07:00
onChange,
2024-05-15 09:40:50 +03:30
id,
2024-05-24 18:32:40 +03:30
label = "Email",
2024-05-15 09:40:50 +03:30
variant,
placeholder,
icon,
helperText,
error,
}) => {
const theme = useTheme();
const fontLookup = {
default: theme.font.default.font,
};
const fontFamily = fontLookup["default"];
const [showIcon, setShowIcon] = useState(false);
const handleMouseEnter = () => setShowIcon(true);
const handleMouseLeave = () => setShowIcon(false);
return (
<div style={{ fontFamily: fontFamily }}>
2024-05-24 18:32:40 +03:30
<div className="email-text-field-title">{label}</div>
2024-05-15 09:40:50 +03:30
<div className="email-text-field">
<TextField
2024-06-06 11:41:34 -07:00
onChange={onChange}
2024-05-15 09:40:50 +03:30
error={error}
className="email-text-field-input"
id={id}
variant={variant}
placeholder={placeholder}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<div className="icon-holder">
{error && showIcon && (
<ErrorOutlineIcon
className="text-field-icon"
style={{ fill: "red", width: "16px", height: "16px" }}
/>
)}
{error && !showIcon && (
<ErrorOutlineIcon
className="text-field-icon"
style={{ fill: "red", width: "16px", height: "16px" }}
/>
)}
{!error && showIcon && (
<HelpOutlineIcon
className="text-field-icon"
style={{ width: "16px", height: "16px" }}
/>
)}
</div>
</InputAdornment>
),
}}
helperText={helperText}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
/>
</div>
</div>
);
};
export default EmailTextField;