Files
Checkmate/Client/src/components/TextFields/Website/WebsiteTextField.jsx
T

72 lines
2.2 KiB
React
Raw Normal View History

2024-05-07 17:32:35 +03:30
import React, { useState } from "react";
import "./websiteTextField.css";
2024-05-07 17:32:35 +03:30
import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
2024-05-14 11:06:34 +03:30
import { useTheme } from "@mui/material";
2024-05-12 21:32:39 +03:30
/**
* @component
* @param {Object} props
* @param {boolean} [props.showHelp=true] - Controls the visibility of the help icon (defaults to true)
* @param {boolean} [props.hasCopyButton=false] - Controls the visibility of the copy button (defaults to false)
* @param {string} props.hintText - The hint text displayed below the text field (required)
* @returns {JSX.Element} - Renders the website text field component with optional help and copy features
*/
2024-05-11 22:48:09 +03:30
const WebsiteTextField = ({
2024-05-07 17:32:35 +03:30
showHelp = true,
hasCopyButton = false,
hintText,
2024-05-11 22:48:09 +03:30
}) => {
2024-05-14 11:06:34 +03:30
const theme = useTheme();
const fontLookup = {
default: theme.font.default.font,
};
const fontFamily = fontLookup["default"];
2024-05-07 17:32:35 +03:30
const [copied, setCopied] = useState(false);
const handleCopy = () => {
setCopied(true);
setTimeout(() => setCopied(false), 1000);
};
return (
2024-05-14 11:06:34 +03:30
<div style={{ fontFamily: fontFamily }}>
2024-05-07 20:40:01 +03:30
<div className="website-textfield-title">Website</div>
2024-05-07 17:32:35 +03:30
<div className="website-textfield">
2024-05-11 22:48:09 +03:30
<label className="website-label">http://</label>
2024-05-07 17:32:35 +03:30
<input
type="url"
name="website-url"
id="website-url"
className="website-url"
/>
{showHelp && (
<div
className={
`website-icon-holder ` + !hasCopyButton
? "with-no-copy-button"
: ""
}
>
<HelpOutlineIcon style={{ fill: "var(--icon-color)" }} />
</div>
)}
{hasCopyButton && (
<div className="copy-to-clipboard-button" onClick={handleCopy}>
2024-05-11 22:48:09 +03:30
<ContentCopyIcon
className="copy-icon"
style={{ width: "20px", height: "20px" }}
/>
<span className="">{copied ? " Copied " : " Copy "}</span>
2024-05-07 17:32:35 +03:30
</div>
)}
</div>
<label className="website-textfield-hint">{hintText}</label>
2024-05-14 11:06:34 +03:30
</div>
2024-05-07 17:32:35 +03:30
);
2024-05-11 22:48:09 +03:30
};
export default WebsiteTextField;