Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/plays/password-generator/PasswordGenerator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ function PasswordGenerator(props) {
const onCopyClick = (e) => {
e.preventDefault();
navigator.clipboard.writeText(password.password);
setPassword({ ...password, status: true });
setPassword((prev) => ({ ...prev, status: true }));

setTimeout(() => {
setPassword((prev) => ({ ...prev, status: false }));
}, 1500);
};

const ErrorBox = () => {
Expand Down Expand Up @@ -109,8 +113,14 @@ function PasswordGenerator(props) {
<h1 className="title">Password Generator</h1>
{error && <ErrorBox />}
<div className="inputfield">
<input disabled readOnly className="text" type="text" value={password.password} />
<button className="copy copybtn" onClick={onCopyClick}>
<input
disabled
readOnly
className={`text ${password.status ? 'copied' : ''}`}
type="text"
value={password.password}
/>
<button className="copy copybtn" disabled={password.status} onClick={onCopyClick}>
{password?.status ? 'Copied' : 'Copy'}
</button>
</div>
Expand Down
14 changes: 14 additions & 0 deletions src/plays/password-generator/password-generator-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
padding: 0.6em 1em;
border-radius: 0.7em;
text-transform: uppercase;
min-width: 100px;
text-align: center;
}

.password-generator .main .inputfield .text.copied {
background-color: #b3daff;
border-radius: 0.4em;
transition: background-color 0.3s ease;
}

.password-generator .main .inputfield .copybtn:disabled {
opacity: 0.55;
background-color: #18c0f4;
cursor: not-allowed;
}

.password-generator .main .block {
Expand Down
Loading