{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "copy-button",
  "title": "Copy Button",
  "description": "An icon button that copies a value and swaps to a check mark, announcing it to screen readers.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/button"
  ],
  "files": [
    {
      "path": "registry/default/ui/copy-button.tsx",
      "content": "\"use client\";\n\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport { useEffect, useRef, useState, type ComponentProps, type MouseEvent } from \"react\";\n\nimport { cn } from \"@/registry/default/lib/utils\";\nimport { Button } from \"@/registry/default/ui/button\";\n\nconst SIZES = { sm: \"icon-sm\", default: \"icon\", lg: \"icon-lg\" } as const;\n\ninterface CopyButtonProps extends Omit<\n  ComponentProps<typeof Button>,\n  \"value\" | \"size\" | \"children\" | \"asChild\" | \"loading\"\n> {\n  /** The text that lands on the clipboard. */\n  value: string;\n  size?: keyof typeof SIZES;\n  /** How long the check mark stays before the button resets, in ms. */\n  timeout?: number;\n  /** Called after the text was copied, not when the browser refused. */\n  onCopied?: (value: string) => void;\n  /** Accessible name of the button. */\n  label?: string;\n  /** Announced to screen readers once the text is on the clipboard. */\n  copiedLabel?: string;\n}\n\n/**\n * An icon button that copies `value` and swaps its icon for a check mark.\n * \"Copied\" is announced through a live region and only claimed when the\n * clipboard accepted the text. The button stays enabled while it shows the\n * check, so keyboard focus is never dropped.\n *\n * `data-state` is `idle` or `copied`, and the icons are\n * `data-slot=\"copy-button-copy-icon\"` and `\"copy-button-check-icon\"`, e.g.\n * `className=\"[&_[data-slot=copy-button-check-icon]]:text-success\"`.\n *\n * @example\n * <CopyButton value=\"pnpm dlx shadcn@latest add @corsair-ui/copy-button\" />\n */\nfunction CopyButton({\n  value,\n  size = \"default\",\n  timeout = 1600,\n  onCopied,\n  label = \"Copy to clipboard\",\n  copiedLabel = \"Copied\",\n  variant = \"ghost\",\n  className,\n  onClick,\n  ...props\n}: CopyButtonProps) {\n  const [copied, setCopied] = useState(false);\n  const timer = useRef<ReturnType<typeof setTimeout>>(undefined);\n\n  useEffect(() => () => clearTimeout(timer.current), []);\n\n  const copy = async () => {\n    try {\n      await navigator.clipboard.writeText(value);\n    } catch {\n      // Refused, or not a secure context: nothing was copied, so claim nothing.\n      return;\n    }\n    setCopied(true);\n    onCopied?.(value);\n    clearTimeout(timer.current);\n    timer.current = setTimeout(() => setCopied(false), timeout);\n  };\n\n  const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n    onClick?.(event);\n    if (!event.defaultPrevented) void copy();\n  };\n\n  const icon =\n    \"col-start-1 row-start-1 motion-safe:transition-[opacity,transform,filter] motion-safe:duration-200 motion-safe:ease-out\";\n\n  return (\n    <>\n      <Button\n        type=\"button\"\n        data-slot=\"copy-button\"\n        data-state={copied ? \"copied\" : \"idle\"}\n        variant={variant}\n        size={SIZES[size]}\n        aria-label={label}\n        className={cn(\"grid place-items-center active:scale-95\", className)}\n        onClick={handleClick}\n        {...props}\n      >\n        <CheckIcon\n          aria-hidden=\"true\"\n          data-slot=\"copy-button-check-icon\"\n          className={cn(icon, copied ? \"scale-100 opacity-100\" : \"scale-50 opacity-0 blur-[2px]\")}\n        />\n        <CopyIcon\n          aria-hidden=\"true\"\n          data-slot=\"copy-button-copy-icon\"\n          className={cn(icon, copied ? \"scale-50 opacity-0 blur-[2px]\" : \"scale-100 opacity-100\")}\n        />\n      </Button>\n      <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n        {copied ? copiedLabel : \"\"}\n      </span>\n    </>\n  );\n}\n\nexport { CopyButton, type CopyButtonProps };\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}