{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "copy-button",
  "type": "registry:ui",
  "title": "Copy Button",
  "description": "An icon button that copies a value to the clipboard and confirms with a check.",
  "dependencies": [
    "lucide-react@^1.49.0"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/copy-button.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/copy-button.tsx",
      "content": "import { useEffect, useRef, useState, useSyncExternalStore } from 'react';\nimport { Check, Copy } from 'lucide-react';\nimport { cn } from '../lib/utils';\n\nconst noSubscribe = () => () => {};\n\n/** Icon button that copies `value` to the clipboard and confirms for a moment. Not rendered in HTML read without JavaScript.\n *  `label` names the button and `copiedLabel` is the confirmation shown and announced, so a Swedish screen passes both. */\nexport function CopyButton({ value, label = 'Copy', copiedLabel = 'Copied', className }: { value: string; label?: string; copiedLabel?: string; className?: string }) {\n  // Copying needs JavaScript: in server-rendered HTML read without scripts there is no button to do nothing.\n  const interactive = useSyncExternalStore(noSubscribe, () => true, () => false);\n  const [done, setDone] = useState(false);\n  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  useEffect(() => () => clearTimeout(timer.current), []);\n  if (!interactive) return null;\n  return (\n    <>\n      {/* The live region exists before its text changes, so screen readers announce the confirmation; sighted users see the pill on the button. */}\n      <span role=\"status\" className=\"sr-only\">{done ? copiedLabel : ''}</span>\n      <button\n        type=\"button\"\n        aria-label={label}\n        onClick={async () => {\n          try {\n            await navigator.clipboard.writeText(value);\n            setDone(true);\n            clearTimeout(timer.current);\n            timer.current = setTimeout(() => setDone(false), 1600);\n          } catch {\n            /* clipboard unavailable: leave the button as is */\n          }\n        }}\n        className={cn(\n          'relative inline-flex size-9 shrink-0 items-center justify-center rounded-kh text-kh-muted transition-colors duration-(--kh-dur) hover:bg-kh-surface-3 hover:text-kh-ink',\n          'after:absolute after:-inset-1 after:content-[\"\"] focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-(--kh-focus)',\n          className,\n        )}\n      >\n        {done ? <Check aria-hidden className=\"size-4\" /> : <Copy aria-hidden className=\"size-4\" />}\n        {done ? (\n          <span aria-hidden className=\"pointer-events-none absolute bottom-full right-0 z-10 mb-1 whitespace-nowrap rounded-kh bg-kh-ink px-2 py-1 text-kh-caption text-kh-canvas\">{copiedLabel}</span>\n        ) : null}\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}
