{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ripple-button",
  "title": "Ripple button",
  "description": "Material-style ink ripple that grows from the exact press point and fades on release, pure CSS, across five variants and icon buttons.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/buttons/ripple-button.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens } from \"@/lib/goodui-motion\"\n\nconst CSS = `\n@keyframes pc-ripple-button-grow { to { transform: translate(-50%, -50%) scale(1) } }\n.pc-ripple-button-wave {\n  position: absolute; border-radius: 9999px; pointer-events: none;\n  background: var(--pc-ripple-color, currentColor); opacity: var(--pc-ripple-opacity, .22);\n  transform: translate(-50%, -50%) scale(0);\n  animation: pc-ripple-button-grow var(--pc-ripple-duration, 550ms) var(--pc-ease-out) forwards;\n  transition: opacity 420ms ease-out;\n}\n.pc-ripple-button-wave[data-out] { opacity: 0 }\n@media (prefers-reduced-motion: reduce) { .pc-ripple-button-wave { display: none } }\n`\n\nconst VARIANTS = {\n  default: \"bg-primary text-primary-foreground shadow-[var(--pc-e1)] hover:bg-primary/90\",\n  secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n  outline: \"border bg-background text-foreground shadow-xs hover:bg-muted dark:bg-input/30 dark:hover:bg-input/50\",\n  ghost: \"text-foreground hover:bg-muted\",\n  destructive: \"bg-destructive text-white shadow-[var(--pc-e1)] hover:bg-destructive/90\",\n} as const\n\nconst SIZES = {\n  sm: \"h-8 gap-1.5 rounded-md px-3 text-xs [&_svg]:size-3.5\",\n  md: \"h-10 gap-2 rounded-lg px-4 text-sm [&_svg]:size-4\",\n  lg: \"h-11 gap-2 rounded-lg px-6 text-base [&_svg]:size-5\",\n  icon: \"size-10 rounded-full [&_svg]:size-4\",\n} as const\n\ntype Wave = { id: number; x: number; y: number; size: number; out: boolean }\n\nexport type RippleButtonProps = React.ComponentProps<\"button\"> & {\n  /** \"default\" | \"secondary\" | \"outline\" | \"ghost\" | \"destructive\", matching shadcn's button variants. */\n  variant?: keyof typeof VARIANTS\n  /** \"sm\" | \"md\" | \"lg\" | \"icon\"; \"icon\" is a round 40px button. */\n  size?: keyof typeof SIZES\n  /** Ripple color; defaults to the text color. */\n  rippleColor?: string\n  /** Ripple opacity at its peak (0–1). */\n  rippleOpacity?: number\n  /** Milliseconds for the ripple to cover the button. */\n  rippleDuration?: number\n  /** Always start the ripple from the center (good for icon buttons). */\n  centerRipple?: boolean\n}\n\n/** Button with a material-style ink ripple that grows from the press point and fades on release. Pure CSS animation. */\nexport function RippleButton({\n  variant = \"default\",\n  size = \"md\",\n  rippleColor,\n  rippleOpacity,\n  rippleDuration = 550,\n  centerRipple,\n  className,\n  style,\n  children,\n  onPointerDown,\n  onPointerUp,\n  onPointerLeave,\n  onPointerCancel,\n  onKeyDown,\n  onKeyUp,\n  onBlur,\n  ...props\n}: RippleButtonProps) {\n  const reduce = useReducedMotion() ?? false\n  const [waves, setWaves] = React.useState<Wave[]>([])\n  const nextId = React.useRef(0)\n  const timers = React.useRef<number[]>([])\n\n  React.useEffect(() => {\n    const list = timers.current\n    return () => list.forEach((t) => window.clearTimeout(t))\n  }, [])\n\n  const spawn = (el: HTMLElement, clientX?: number, clientY?: number) => {\n    if (reduce) return\n    const r = el.getBoundingClientRect()\n    const x = clientX === undefined || centerRipple ? r.width / 2 : clientX - r.left\n    const y = clientY === undefined || centerRipple ? r.height / 2 : clientY - r.top\n    const size = 2 * Math.hypot(Math.max(x, r.width - x), Math.max(y, r.height - y))\n    const id = nextId.current++\n    setWaves((w) => [...w.slice(-4), { id, x, y, size, out: false }])\n  }\n\n  const release = () => {\n    setWaves((w) => (w.some((x) => !x.out) ? w.map((x) => ({ ...x, out: true })) : w))\n    const t = window.setTimeout(() => setWaves((w) => w.filter((x) => !x.out)), 520)\n    timers.current.push(t)\n  }\n\n  return (\n    <button\n      data-slot=\"button\"\n      className={cn(\n        \"pc-press relative isolate inline-flex shrink-0 items-center justify-center overflow-hidden font-medium whitespace-nowrap transition-[background-color,box-shadow,color] outline-none select-none focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:shrink-0\",\n        VARIANTS[variant],\n        SIZES[size],\n        className,\n      )}\n      style={{\n        ...style,\n        [\"--pc-ripple-duration\" as string]: `${rippleDuration}ms`,\n        ...(rippleColor ? { [\"--pc-ripple-color\" as string]: rippleColor } : {}),\n        ...(rippleOpacity !== undefined ? { [\"--pc-ripple-opacity\" as string]: rippleOpacity } : {}),\n      }}\n      onPointerDown={(e) => {\n        if (e.button === 0) spawn(e.currentTarget, e.clientX, e.clientY)\n        onPointerDown?.(e)\n      }}\n      onPointerUp={(e) => {\n        release()\n        onPointerUp?.(e)\n      }}\n      onPointerLeave={(e) => {\n        release()\n        onPointerLeave?.(e)\n      }}\n      onPointerCancel={(e) => {\n        release()\n        onPointerCancel?.(e)\n      }}\n      onKeyDown={(e) => {\n        if ((e.key === \" \" || e.key === \"Enter\") && !e.repeat) spawn(e.currentTarget)\n        onKeyDown?.(e)\n      }}\n      onKeyUp={(e) => {\n        release()\n        onKeyUp?.(e)\n      }}\n      onBlur={(e) => {\n        release()\n        onBlur?.(e)\n      }}\n      {...props}\n    >\n      <GooduiTokens />\n      <style href=\"pc-ripple-button\" precedence=\"default\">\n        {CSS}\n      </style>\n      <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10\">\n        {waves.map((w) => (\n          <span\n            key={w.id}\n            data-out={w.out || undefined}\n            className=\"pc-ripple-button-wave\"\n            style={{ left: w.x, top: w.y, width: w.size, height: w.size }}\n          />\n        ))}\n      </span>\n      {children}\n    </button>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/ripple-button.tsx"
    }
  ],
  "categories": [
    "components",
    "buttons"
  ],
  "type": "registry:component"
}