From 7607e9fd4063d236485e61c2bb3e7cf3f91910da Mon Sep 17 00:00:00 2001 From: Luca Martial Date: Mon, 11 May 2026 00:33:10 -0700 Subject: [PATCH] feat(docs): add CopyButton component Reusable copy-to-clipboard button with animated check on success. Used by CodeBlock for all three modes. --- docs/components/copy-button.tsx | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 docs/components/copy-button.tsx diff --git a/docs/components/copy-button.tsx b/docs/components/copy-button.tsx new file mode 100644 index 00000000..01dbd054 --- /dev/null +++ b/docs/components/copy-button.tsx @@ -0,0 +1,64 @@ +"use client"; + +import { useState } from "react"; + +type Props = { + text: string; + className?: string; +}; + +export function CopyButton({ text, className = "" }: Props) { + const [copied, setCopied] = useState(false); + + const onClick = async () => { + try { + await navigator.clipboard.writeText(text); + setCopied(true); + setTimeout(() => setCopied(false), 1500); + } catch { + // Older browsers or denied permission — fail silently + } + }; + + return ( + + ); +}