{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-copy",
  "type": "registry:component",
  "title": "Button Copy",
  "description": "Copies a string to the clipboard. The icon morphs into a check and the label swaps from Copy to Copied, then reverts after 1.6 seconds.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "copy",
    "clipboard",
    "code",
    "icon",
    "feedback"
  ],
  "docs": "https://hyperblur.dev/effects/button-copy",
  "files": [
    {
      "path": "registry/hyperblur/button-copy.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-copy.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonCopyProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\" | \"value\"> {\n  value?: string;\n  copiedLabel?: React.ReactNode;\n  resetAfter?: number;\n  onCopied?: (value: string) => void;\n  variant?: \"outline\" | \"solid\" | \"ghost\";\n  accent?: string;\n  size?: \"sm\" | \"md\" | \"lg\";\n}\n\nconst css = `\n.hb-qa8 {\n  --hb-qa8-c: #2f7bff;\n  --hb-qa8-bg: #141414;\n  --hb-qa8-fg: #ededed;\n  --hb-qa8-ring: #2a2a2a;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  gap: 0.55em;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 0.55em 0.95em 0.55em 0.8em;\n  font: inherit;\n  font-size: 14px;\n  font-weight: 600;\n  line-height: 1.2;\n  color: var(--hb-qa8-fg);\n  background: var(--hb-qa8-bg);\n  border: 0;\n  border-radius: 9px;\n  box-shadow: inset 0 0 0 1px var(--hb-qa8-ring);\n  cursor: pointer;\n  user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: manipulation;\n  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;\n}\n.hb-qa8[data-size=\"sm\"] { font-size: 12px; }\n.hb-qa8[data-size=\"lg\"] { font-size: 16px; }\n.hb-qa8[data-variant=\"solid\"] {\n  --hb-qa8-bg: var(--hb-qa8-c);\n  --hb-qa8-fg: #ffffff;\n  --hb-qa8-ring: transparent;\n}\n.hb-qa8[data-variant=\"ghost\"] {\n  --hb-qa8-bg: transparent;\n  --hb-qa8-ring: transparent;\n  --hb-qa8-fg: #a1a1a1;\n}\n.hb-qa8:hover:not(:disabled) { --hb-qa8-ring: color-mix(in srgb, var(--hb-qa8-c) 60%, #2a2a2a); }\n.hb-qa8[data-variant=\"ghost\"]:hover:not(:disabled) { --hb-qa8-bg: rgba(255, 255, 255, 0.06); --hb-qa8-fg: #ededed; }\n.hb-qa8[data-variant=\"solid\"]:hover:not(:disabled) { filter: brightness(1.1); }\n.hb-qa8[data-copied=\"true\"] {\n  --hb-qa8-fg: #4ade80;\n  --hb-qa8-ring: color-mix(in srgb, #4ade80 45%, transparent);\n}\n.hb-qa8[data-variant=\"solid\"][data-copied=\"true\"] { --hb-qa8-bg: #16a34a; --hb-qa8-fg: #ffffff; }\n.hb-qa8-i {\n  position: relative;\n  width: 1.15em;\n  height: 1.15em;\n  flex: none;\n}\n.hb-qa8-g {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 2;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  transition: opacity 0.2s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-qa8-ck { opacity: 0; transform: scale(0.4) rotate(-20deg); stroke-dasharray: 24; stroke-dashoffset: 24; }\n.hb-qa8[data-copied=\"true\"] .hb-qa8-cp { opacity: 0; transform: scale(0.4) rotate(20deg); }\n.hb-qa8[data-copied=\"true\"] .hb-qa8-ck {\n  opacity: 1;\n  transform: none;\n  animation: hb-qa8-draw 0.4s cubic-bezier(0.65, 0, 0.35, 1) 0.08s forwards;\n}\n.hb-qa8:not([data-copied=\"true\"]):not(:hover):not(:disabled) .hb-qa8-cp { animation: hb-qa8-nudge 5s ease-in-out 1.5s infinite; }\n.hb-qa8-w {\n  position: relative;\n  display: grid;\n  overflow: hidden;\n  height: 1.3em;\n  line-height: 1.3;\n}\n.hb-qa8-a, .hb-qa8-b {\n  grid-area: 1 / 1;\n  white-space: nowrap;\n  text-align: left;\n  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease;\n}\n.hb-qa8-b { transform: translateY(110%); opacity: 0; }\n.hb-qa8[data-copied=\"true\"] .hb-qa8-a { transform: translateY(-110%); opacity: 0; }\n.hb-qa8[data-copied=\"true\"] .hb-qa8-b { transform: none; opacity: 1; }\n.hb-qa8:active:not(:disabled) { transform: scale(0.96); }\n.hb-qa8:focus-visible { outline: 2px solid var(--hb-qa8-c); outline-offset: 3px; }\n.hb-qa8:disabled { opacity: 0.45; cursor: not-allowed; }\n@keyframes hb-qa8-draw { to { stroke-dashoffset: 0; } }\n@keyframes hb-qa8-nudge {\n  0%, 84%, 100% { transform: none; }\n  90% { transform: translateY(-1.5px) rotate(-6deg); }\n  95% { transform: translateY(0) rotate(4deg); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qa8, .hb-qa8-g, .hb-qa8-a, .hb-qa8-b { transition-duration: 0.01s; }\n  .hb-qa8 .hb-qa8-cp { animation: none !important; }\n  .hb-qa8[data-copied=\"true\"] .hb-qa8-ck { animation: none; stroke-dashoffset: 0; }\n  .hb-qa8:active:not(:disabled) { transform: none; }\n}\n`;\n\nfunction fallbackCopy(text: string) {\n  const area = document.createElement(\"textarea\");\n  area.value = text;\n  area.setAttribute(\"readonly\", \"\");\n  area.style.position = \"fixed\";\n  area.style.opacity = \"0\";\n  area.style.pointerEvents = \"none\";\n  document.body.appendChild(area);\n  area.select();\n  let ok = false;\n  try {\n    ok = document.execCommand(\"copy\");\n  } catch {\n    ok = false;\n  }\n  document.body.removeChild(area);\n  return ok;\n}\n\nexport function ButtonCopy({\n  children = \"Copy\",\n  copiedLabel = \"Copied\",\n  value = \"npx shadcn@latest add https://hyperblur.dev/r/button-copy.json\",\n  resetAfter = 1600,\n  onCopied,\n  onClick,\n  variant = \"outline\",\n  accent = \"#2f7bff\",\n  size = \"md\",\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  ...rest\n}: ButtonCopyProps) {\n  const [copied, setCopied] = React.useState(false);\n  const timer = React.useRef(0);\n\n  React.useEffect(() => {\n    return () => window.clearTimeout(timer.current);\n  }, []);\n\n  async function handleClick(e: React.MouseEvent<HTMLButtonElement>) {\n    onClick?.(e);\n    let ok = false;\n    try {\n      await navigator.clipboard.writeText(value);\n      ok = true;\n    } catch {\n      ok = fallbackCopy(value);\n    }\n    if (!ok) return;\n    onCopied?.(value);\n    setCopied(true);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => setCopied(false), Math.max(0, resetAfter));\n  }\n\n  const vars = { \"--hb-qa8-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-button-copy\" precedence=\"default\">{css}</style>\n      <button\n        type={type}\n        className={`hb-qa8 ${className}`}\n        style={vars}\n        data-variant={variant}\n        data-size={size}\n        data-copied={copied ? \"true\" : \"false\"}\n        disabled={disabled}\n        aria-live=\"polite\"\n        onClick={handleClick}\n        {...rest}\n      >\n        <span className=\"hb-qa8-i\" aria-hidden=\"true\">\n          <svg className=\"hb-qa8-g hb-qa8-cp\" viewBox=\"0 0 24 24\" focusable=\"false\">\n            <rect x=\"9\" y=\"9\" width=\"11\" height=\"11\" rx=\"2.5\" />\n            <path d=\"M5 15V6.5A2.5 2.5 0 0 1 7.5 4H15\" />\n          </svg>\n          <svg className=\"hb-qa8-g hb-qa8-ck\" viewBox=\"0 0 24 24\" focusable=\"false\">\n            <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n          </svg>\n        </span>\n        <span className=\"hb-qa8-w\">\n          <span className=\"hb-qa8-a\" aria-hidden={copied || undefined}>{children}</span>\n          <span className=\"hb-qa8-b\" aria-hidden={copied ? undefined : true}>{copiedLabel}</span>\n        </span>\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}