{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "copy-button",
  "title": "Copy Button",
  "description": "Icon button that copies a value to the clipboard, swaps to a checkmark for a moment, and announces 'Copied' to screen readers. Hit area extends past the small visual size. onCopy only fires when the clipboard write succeeds. Icons are swappable. Built on the shadcn Button and the useCopy hook.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "@0xui/use-copy"
  ],
  "files": [
    {
      "path": "registry/default/components/copy-button.tsx",
      "content": "// Docs: https://0xui.io/components/copy-button.md\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport type { ComponentProps, ComponentType } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { useCopy } from \"@/hooks/use-copy\";\nimport { cn } from \"@/lib/utils\";\n\ntype IconComponent = ComponentType<{ className?: string }>;\n\nexport type CopyButtonProps = Omit<\n  ComponentProps<typeof Button>,\n  \"value\" | \"onClick\" | \"children\"\n> & {\n  /** Text written to the clipboard. */\n  value: string;\n  /** Accessible label. Defaults to \"Copy\". Use something specific, e.g. \"Copy address\". */\n  label?: string;\n  /** How long the copied state lasts, in ms. */\n  timeout?: number;\n  /** Called after a successful copy. */\n  onCopy?: (value: string) => void;\n  /** Custom copy icon. Pass false to hide. */\n  copyIcon?: IconComponent | false;\n  /** Custom icon shown after copying. Pass false to hide. */\n  copiedIcon?: IconComponent | false;\n};\n\n/**\n * Icon button that copies `value` and confirms with a checkmark.\n * The confirmation is also announced to screen readers.\n */\nexport function CopyButton({\n  value,\n  label = \"Copy\",\n  timeout,\n  onCopy,\n  copyIcon,\n  copiedIcon,\n  variant = \"ghost\",\n  size = \"icon-xs\",\n  className,\n  ...props\n}: CopyButtonProps) {\n  const { copied, copy } = useCopy({ timeout });\n  const Copy = copyIcon === false ? null : (copyIcon ?? CopyIcon);\n  const Copied = copiedIcon === false ? null : (copiedIcon ?? CheckIcon);\n  const Icon = copied ? Copied : Copy;\n\n  return (\n    <Button\n      type=\"button\"\n      variant={variant}\n      size={size}\n      aria-label={label}\n      title={label}\n      data-copied={copied || undefined}\n      onClick={async () => {\n        if (await copy(value)) onCopy?.(value);\n      }}\n      className={cn(\n        // Grow the hit area past the small visual size.\n        \"relative after:absolute after:-inset-2\",\n        className\n      )}\n      {...props}\n    >\n      {Icon && <Icon className={cn(copied && \"text-emerald-500\")} />}\n      <span role=\"status\" className=\"sr-only\">\n        {copied ? \"Copied\" : \"\"}\n      </span>\n    </Button>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/copy-button.md",
  "categories": [
    "utilities"
  ],
  "type": "registry:component"
}