Skip to content

Commit

Permalink
docs: use single listener in icons reference
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Dec 6, 2024
1 parent cf12beb commit eac6ff0
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions docs/src/components/icons-list.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ const icons = Object.keys(Icons) as (keyof typeof Icons)[];
</div>

<script>
const iconGrid = document.querySelector<HTMLDivElement>('.icons-grid');
const copiedLabel = document.querySelector<HTMLDivElement>('.icons-grid')?.dataset.labelCopied!;
const icons = document.querySelectorAll<HTMLButtonElement>('.icon-preview');
icons.forEach((icon) => {
icon.addEventListener('click', () => {
const iconName = icon.dataset.name!;
navigator.clipboard.writeText(iconName);
iconGrid?.addEventListener('click', (event) => {
if (!(event.target instanceof Element)) return;
const icon = event.target.closest('.icon-preview');
if (!(icon instanceof HTMLButtonElement)) return;
const iconName = icon.dataset.name!;
navigator.clipboard.writeText(iconName);

const iconLabel = icon.querySelector('[aria-live]');
if (iconLabel) {
iconLabel.textContent = copiedLabel;
setTimeout(() => {
iconLabel.textContent = iconName;
}, 1000);
}
});
const iconLabel = icon.querySelector('[aria-live]');
if (iconLabel) {
iconLabel.textContent = copiedLabel;
setTimeout(() => {
iconLabel.textContent = iconName;
}, 1000);
}
});
</script>

Expand Down

0 comments on commit eac6ff0

Please sign in to comment.