Skip to content

Commit

Permalink
feature update: copy generated password to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeep-jais committed Dec 11, 2023
1 parent b65be1a commit 147ff15
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import usePasswordGenerator from '../hooks/usePasswordGenerator';
const PasswordGenerator = () => {
const [passwordLength, setPasswordLength] = useState(8);
const [checkboxData, setCheckboxData] = useState(characterData);
const [copied, setCopied] = useState(false);

// custom hook
const { error, password, generatePassword } = usePasswordGenerator();
// console.log(error, password);
Expand All @@ -21,6 +23,14 @@ const PasswordGenerator = () => {
setCheckboxData(checkboxData);
};

const handleCopy = () => {
navigator.clipboard.writeText(password);
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 1000);
};

return (
<section className="pwg-app section">
<div className="section-center">
Expand All @@ -35,7 +45,9 @@ const PasswordGenerator = () => {
{password && (
<header className="password">
<p className="pwd">{password}</p>
<button className="btn copyBtn">copy</button>
<button className="btn copyBtn" onClick={handleCopy}>
{copied ? 'copied' : 'copy'}
</button>
</header>
)}

Expand Down

0 comments on commit 147ff15

Please sign in to comment.