import { createSignal, type JSX, onCleanup } from "solid-js"; import { CheckIcon, CopyIcon } from "./Icons.tsx"; /** Copies `text()` to the clipboard and swaps to a tick for a moment. */ export const CopyButton = (props: { text: () => string; label: string; class?: string; /** Visible label. Without one the button is a square holding the icon. */ children?: JSX.Element; }) => { const [copied, setCopied] = createSignal(false); let timer: ReturnType | undefined; onCleanup(() => clearTimeout(timer)); const copy = async () => { try { await navigator.clipboard.writeText(props.text()); setCopied(true); } catch {} clearTimeout(timer); timer = setTimeout(() => setCopied(false), 1400); }; return ( ); };