diff options
| author | Nikhil M Warrier <nikhilmw.dev@gmail.com> | 2026-03-07 22:07:47 +0530 |
|---|---|---|
| committer | Nikhil M Warrier <nikhilmw.dev@gmail.com> | 2026-03-07 22:07:47 +0530 |
| commit | c604e0390d1b808088ab02fbe1d47992f6fd7ba4 (patch) | |
| tree | 0a2df27a9241dddba7e8fa4b94de747a438c2ead /src/components | |
| parent | a847f2d9ed8332edbccd13266e724c8f95036559 (diff) | |
Assets and style guide page
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/ColorSwatch.astro | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/components/ColorSwatch.astro b/src/components/ColorSwatch.astro new file mode 100644 index 0000000..df01d5a --- /dev/null +++ b/src/components/ColorSwatch.astro @@ -0,0 +1,49 @@ +--- +import { cn } from '@/lib/utils' + +interface Props { + class?: string + color: string + [key: string]: any +} + +const { color: colorName, class: className, ...rest } = Astro.props +--- + +<button + class={cn( + 'cursor-pointer bg-primary text-primary-foreground border-border border flex min-h-20 w-full items-center justify-center rounded font-mono text-sm font-bold', + className, + )} + {...rest} + title={'Click to copy: ' + colorName} + data-color={colorName} + data-color-swatch +> + <span>{colorName}</span> +</button> + +<script> + const initClipboard = () => { + const buttons = document.querySelectorAll( + '[data-color-swatch]', + ) as NodeListOf<HTMLButtonElement> + + buttons.forEach((button) => { + const color = button?.dataset.color as string + button?.addEventListener('click', async () => { + try { + await navigator.clipboard.writeText(color) + button.innerText = 'Copied!' + setTimeout(() => { + button.innerText = color + }, 1000) + } catch (err) { + console.error('Error copying to clipboard.', err) + } + }) + }) + } + + document.addEventListener('astro:page-load', initClipboard) +</script> |
