{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "copy-button",
  "title": "Copy Button",
  "description": "Copies a text and turns into a check for a moment.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/ui/copy-button.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport { CheckIcon, CopyIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\n\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\n\nconst COPIED_FOR_MS = 1600;\n\nfunction accessibleLabelOf(isCopied: boolean, label: string) {\n  if (isCopied) {\n    return 'Copied';\n  }\n  return label;\n}\n\ntype CopyButtonProps = {\n  text: string;\n  /** What the button copies, as an action: \"Copy the command\". */\n  label: string;\n  className?: string;\n};\n\nexport function CopyButton({ text, label, className }: CopyButtonProps) {\n  const [isCopied, setIsCopied] = useState(false);\n  const { schedule } = useTimeouts();\n  const accessibleLabel = accessibleLabelOf(isCopied, label);\n  const glyphKey = String(isCopied);\n\n  async function copy() {\n    try {\n      await navigator.clipboard.writeText(text);\n    } catch {\n      return;\n    }\n    setIsCopied(true);\n    schedule(() => setIsCopied(false), COPIED_FOR_MS);\n  }\n\n  return (\n    <Button\n      type='button'\n      variant='ghost'\n      size='icon-sm'\n      aria-label={accessibleLabel}\n      onClick={copy}\n      className={cn('text-muted-foreground size-6', className)}\n    >\n      <Swap swapKey={glyphKey}>\n        {isCopied && <CheckIcon className='size-3.5' />}\n        {!isCopied && <CopyIcon className='size-3.5' />}\n      </Swap>\n    </Button>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "primitives",
    "ai"
  ],
  "type": "registry:ui"
}