'use client'; import { useCallback, useState } from 'react'; import { Check, Copy } from 'lucide-react'; interface CodeBlockProps { /** The literal code/command to render and copy. */ code: string; /** Optional small uppercase label shown above the block (e.g. "bash", "tsx"). */ label?: string; } /** * A copy-to-clipboard code block for the docs page. Leans on the site's global * `pre`/`code` styling (mono font, --bg-tertiary surface) and adds a small copy * button in the corner — the same interaction the waypoints packages expose. * No syntax-highlighting dependency; the site has none and we keep it that way. */ export default function CodeBlock({ code, label }: CodeBlockProps) { const [copied, setCopied] = useState(false); const handleCopy = useCallback(async () => { try { await navigator.clipboard.writeText(code); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch { // Clipboard unavailable (insecure context / denied) — fail quietly. } }, [code]); return (
{code}