import * as React from "react"; import { IconCheck, IconCopy } from "@tabler/icons-react"; import { Button, cn } from "@colineapp/ui"; export function useCopy() { const [copied, setCopied] = React.useState(false); const timer = React.useRef(0); React.useEffect(() => () => window.clearTimeout(timer.current), []); return { copied, copy: (text: string) => { void navigator.clipboard?.writeText(text).then(() => { setCopied(true); window.clearTimeout(timer.current); timer.current = window.setTimeout(() => setCopied(false), 1400); }); }, }; } export function CopyButton({ text, label = "Copy", className }: { text: string; label?: string; className?: string }) { const { copied, copy } = useCopy(); return ( ); } /** Code, monochrome, with a copy button. */ export function CodeBlock({ code, className, title, wrap = false }: { code: string; className?: string; title?: string; wrap?: boolean }) { return (
{code}