Skip to content

Commit

Permalink
handle concurrent button highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
jelni committed Dec 22, 2023
1 parent d9a5673 commit 224b0b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
9 changes: 6 additions & 3 deletions public/scripts/password-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const charsets = {

let password = null;

let concurrentButtonActions = 0;

const preferences = {
form: document.getElementById("password-preferences"),
autoGenerate: document.getElementById("auto-generate"),
Expand Down Expand Up @@ -106,11 +108,12 @@ async function copyPassword() {
success = false;
}
}
const className = success ? "copy-success" : "copy-error";
const copyButton = document.getElementById("password-copy");
copyButton.classList.add(className);
concurrentButtonActions += 1;
copyButton.setAttribute("highlight", success ? "success" : "error");
setTimeout(() => {
copyButton.classList.remove(className);
concurrentButtonActions -= 1;
if (concurrentButtonActions <= 0) copyButton.removeAttribute("highlight");
}, 1_000);
}

Expand Down
24 changes: 12 additions & 12 deletions public/styles/password-generator.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ button {
transition-timing-function: ease-out;
}

button:hover {
background: var(--gray-20);
}

.flex-center {
display: flex;
justify-content: center;
Expand Down Expand Up @@ -78,6 +74,18 @@ button,
border-radius: 1em;
}

button:hover {
background: var(--gray-20);
}

button[highlight="success"] {
background: var(--green);
}

button[highlight="error"] {
background: var(--red);
}

.password {
font-family: "JetBrains Mono", monospace;
font-size: 1rem;
Expand All @@ -102,14 +110,6 @@ button,
}
}

.copy-success {
background: var(--green);
}

.copy-error {
background: var(--red);
}

.password-stats {
text-align: left;
}
Expand Down

0 comments on commit 224b0b6

Please sign in to comment.