From 6f4d1d869b5fa9709271abf73e78648f7b2ca015 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 29 Jun 2023 21:47:53 -0700 Subject: [PATCH] Add "Copied!" popover on copy --- index.html | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index d832564..7c4401a 100644 --- a/index.html +++ b/index.html @@ -107,6 +107,31 @@ margin-block-end: 16px; } + .copied { + position: relative; + } + + .copied::before { + content: ''; + position: absolute; + inset-inline-start: calc(100% - 4px); + inset-block-start: calc(50% - 4px); + inline-size: 10px; + block-size: 10px; + background: hsl(216deg 50% 90%); + clip-path: polygon(0 50%, 100% 0, 100% 100%); + } + + .copied::after { + content: 'Copied!'; + position: absolute; + inset-inline-start: calc(100% + 4px); + font-weight: 700; + background: hsl(216deg 50% 90%); + padding: 8px; + border-radius: 4px; + } + footer { margin-block: 24px 16px; } @@ -202,10 +227,13 @@ setOutput(encrypted); }); - document.querySelector('#copy').addEventListener('click', e => { + const copyButton = document.querySelector('#copy'); + copyButton.addEventListener('click', e => { e.preventDefault(); const ciphertext = document.querySelector('#ciphertext').textContent; navigator.clipboard.writeText(ciphertext); + copyButton.classList.add('copied'); + setTimeout(() => copyButton.classList.remove('copied'), 2000); }) document.querySelector('#download').addEventListener('click', e => { -- 2.47.3