Compare commits

..

1 Commits

Author SHA1 Message Date
user
8135b78b5c add visual flash feedback on click-to-copy elements
All checks were successful
check / check (push) Successful in 10s
When a user clicks to copy text, the clicked element now briefly
inverts (foreground/background swap) and fades back over 500ms,
providing immediate localized feedback. The existing flash message
is retained for accessibility.

Closes #100
2026-02-28 15:51:33 -08:00
9 changed files with 61 additions and 54 deletions

View File

@@ -15,20 +15,22 @@
--color-section: #dddddd; --color-section: #dddddd;
} }
@keyframes copy-flash {
0% {
background-color: var(--color-fg);
color: var(--color-bg);
}
100% {
background-color: transparent;
color: inherit;
}
}
.copy-flash {
animation: copy-flash 500ms ease-out;
}
body { body {
width: 396px; width: 396px;
overflow-x: hidden; overflow-x: hidden;
} }
/* Copy-flash feedback: inverts colors then fades back */
.copy-flash-active {
background-color: var(--color-fg) !important;
color: var(--color-bg) !important;
transition: none;
}
.copy-flash-fade {
transition:
background-color 300ms ease-out,
color 300ms ease-out;
}

View File

@@ -2,7 +2,7 @@ const {
$, $,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
balanceLinesForAddress, balanceLinesForAddress,
addressDotHtml, addressDotHtml,
addressTitle, addressTitle,
@@ -238,11 +238,12 @@ function renderTransactions(txs) {
function init(_ctx) { function init(_ctx) {
ctx = _ctx; ctx = _ctx;
$("address-full").addEventListener("click", () => { $("address-full").addEventListener("click", () => {
const addr = $("address-full").dataset.full; const el = $("address-full");
const addr = el.dataset.full;
if (addr) { if (addr) {
navigator.clipboard.writeText(addr); navigator.clipboard.writeText(addr);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback($("address-full"));
} }
}); });
@@ -356,20 +357,22 @@ function init(_ctx) {
}); });
$("export-privkey-value").addEventListener("click", () => { $("export-privkey-value").addEventListener("click", () => {
const key = $("export-privkey-value").textContent; const el = $("export-privkey-value");
const key = el.textContent;
if (key) { if (key) {
navigator.clipboard.writeText(key); navigator.clipboard.writeText(key);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback($("export-privkey-value"));
} }
}); });
$("export-privkey-address").addEventListener("click", () => { $("export-privkey-address").addEventListener("click", () => {
const full = $("export-privkey-address").dataset.full; const el = $("export-privkey-address");
const full = el.dataset.full;
if (full) { if (full) {
navigator.clipboard.writeText(full); navigator.clipboard.writeText(full);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback($("export-privkey-address"));
} }
}); });

View File

@@ -5,7 +5,7 @@ const {
$, $,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
addressDotHtml, addressDotHtml,
addressTitle, addressTitle,
escapeHtml, escapeHtml,
@@ -314,11 +314,12 @@ function renderTransactions(txs) {
function init(_ctx) { function init(_ctx) {
ctx = _ctx; ctx = _ctx;
$("address-token-full").addEventListener("click", () => { $("address-token-full").addEventListener("click", () => {
const addr = $("address-token-full").dataset.full; const el = $("address-token-full");
const addr = el.dataset.full;
if (addr) { if (addr) {
navigator.clipboard.writeText(addr); navigator.clipboard.writeText(addr);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback($("address-token-full"));
} }
}); });
@@ -326,8 +327,8 @@ function init(_ctx) {
const copyEl = e.target.closest("[data-copy]"); const copyEl = e.target.closest("[data-copy]");
if (copyEl) { if (copyEl) {
navigator.clipboard.writeText(copyEl.dataset.copy); navigator.clipboard.writeText(copyEl.dataset.copy);
flashCopyElement(copyEl);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(copyEl);
} }
}); });
@@ -375,8 +376,8 @@ function init(_ctx) {
if (copyEl) { if (copyEl) {
copyEl.addEventListener("click", () => { copyEl.addEventListener("click", () => {
navigator.clipboard.writeText(copyEl.dataset.copy); navigator.clipboard.writeText(copyEl.dataset.copy);
flashCopyElement(copyEl);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(copyEl);
}); });
} }
updateSendBalance(); updateSendBalance();

View File

@@ -15,7 +15,7 @@ const {
hideError, hideError,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
addressTitle, addressTitle,
addressDotHtml, addressDotHtml,
escapeHtml, escapeHtml,
@@ -117,8 +117,8 @@ function show(txInfo) {
if (copyEl) { if (copyEl) {
copyEl.onclick = () => { copyEl.onclick = () => {
navigator.clipboard.writeText(copyEl.dataset.copy); navigator.clipboard.writeText(copyEl.dataset.copy);
flashCopyElement(copyEl);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(copyEl);
}; };
} }
} else { } else {

View File

@@ -76,6 +76,18 @@ function clearFlash() {
$("flash-msg").textContent = ""; $("flash-msg").textContent = "";
} }
function flashCopyElement(el) {
el.classList.remove("copy-flash");
// Force reflow so re-adding the class restarts the animation.
void el.offsetWidth;
el.classList.add("copy-flash");
el.addEventListener(
"animationend",
() => el.classList.remove("copy-flash"),
{ once: true },
);
}
function showFlash(msg, duration = 2000) { function showFlash(msg, duration = 2000) {
clearFlash(); clearFlash();
$("flash-msg").textContent = msg; $("flash-msg").textContent = msg;
@@ -259,26 +271,13 @@ function timeAgo(timestamp) {
return years + " year" + (years !== 1 ? "s" : "") + " ago"; return years + " year" + (years !== 1 ? "s" : "") + " ago";
} }
function flashCopyFeedback(el) {
if (!el) return;
el.classList.remove("copy-flash-fade");
el.classList.add("copy-flash-active");
setTimeout(() => {
el.classList.remove("copy-flash-active");
el.classList.add("copy-flash-fade");
setTimeout(() => {
el.classList.remove("copy-flash-fade");
}, 350);
}, 100);
}
module.exports = { module.exports = {
$, $,
showError, showError,
hideError, hideError,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
balanceLine, balanceLine,
balanceLinesForAddress, balanceLinesForAddress,
addressColor, addressColor,

View File

@@ -2,7 +2,7 @@ const {
$, $,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
balanceLinesForAddress, balanceLinesForAddress,
isoDate, isoDate,
timeAgo, timeAgo,
@@ -88,8 +88,8 @@ function renderActiveAddress() {
`<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`; `<a href="${link}" target="_blank" rel="noopener" class="inline-flex items-center">${EXT_ICON}</a>`;
$("active-addr-copy").addEventListener("click", (e) => { $("active-addr-copy").addEventListener("click", (e) => {
navigator.clipboard.writeText(addr); navigator.clipboard.writeText(addr);
flashCopyElement(e.currentTarget);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(e.currentTarget);
}); });
} else { } else {
el.textContent = ""; el.textContent = "";

View File

@@ -2,7 +2,7 @@ const {
$, $,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
formatAddressHtml, formatAddressHtml,
addressTitle, addressTitle,
} = require("./helpers"); } = require("./helpers");
@@ -61,21 +61,23 @@ function show() {
} }
function init(ctx) { function init(ctx) {
$("receive-address-block").addEventListener("click", (e) => { $("receive-address-block").addEventListener("click", () => {
const addr = $("receive-address-block").dataset.full; const el = $("receive-address-block");
const addr = el.dataset.full;
if (addr) { if (addr) {
navigator.clipboard.writeText(addr); navigator.clipboard.writeText(addr);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(e.currentTarget);
} }
}); });
$("btn-receive-copy").addEventListener("click", () => { $("btn-receive-copy").addEventListener("click", () => {
const addr = $("receive-address-block").dataset.full; const block = $("receive-address-block");
const addr = block.dataset.full;
if (addr) { if (addr) {
navigator.clipboard.writeText(addr); navigator.clipboard.writeText(addr);
flashCopyElement(block);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback($("receive-address-block"));
} }
}); });

View File

@@ -5,7 +5,7 @@ const {
$, $,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
addressDotHtml, addressDotHtml,
addressTitle, addressTitle,
escapeHtml, escapeHtml,
@@ -171,8 +171,8 @@ function render() {
.forEach((el) => { .forEach((el) => {
el.onclick = () => { el.onclick = () => {
navigator.clipboard.writeText(el.dataset.copy); navigator.clipboard.writeText(el.dataset.copy);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(el);
}; };
}); });
} }
@@ -249,8 +249,8 @@ async function loadCalldata(txHash, toAddress) {
container.querySelectorAll("[data-copy]").forEach((el) => { container.querySelectorAll("[data-copy]").forEach((el) => {
el.onclick = () => { el.onclick = () => {
navigator.clipboard.writeText(el.dataset.copy); navigator.clipboard.writeText(el.dataset.copy);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(el);
}; };
}); });
} }

View File

@@ -4,7 +4,7 @@ const {
$, $,
showView, showView,
showFlash, showFlash,
flashCopyFeedback, flashCopyElement,
addressDotHtml, addressDotHtml,
addressTitle, addressTitle,
escapeHtml, escapeHtml,
@@ -77,8 +77,8 @@ function attachCopyHandlers(viewId) {
.forEach((el) => { .forEach((el) => {
el.onclick = () => { el.onclick = () => {
navigator.clipboard.writeText(el.dataset.copy); navigator.clipboard.writeText(el.dataset.copy);
flashCopyElement(el);
showFlash("Copied!"); showFlash("Copied!");
flashCopyFeedback(el);
}; };
}); });
} }