'use client'; import { Check, Copy } from 'lucide-react'; import { useState } from 'react'; import { t } from '@/i18n'; import { cn } from '@/lib/cn'; /** Small "Copy" button for code snippets (clipboard API; falls back to a hidden textarea select). */ export function CopyButton({ text, className, label }: { text: string; className?: string; label?: string }) { const [done, setDone] = useState(false); const copy = async () => { try { await navigator.clipboard.writeText(text); } catch { const ta = document.createElement('textarea'); ta.value = text; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); ta.remove(); } setDone(true); setTimeout(() => setDone(false), 1600); }; return ( ); } /** Monospace code block with a thin toolbar (language · copy) above the scrollable code — the button never covers code. */ export function CodeBlock({ code, className, lang }: { code: string; className?: string; lang?: string }) { return (
{code}