{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ripple-button","type":"registry:ui","title":"Ripple Button","description":"A button whose ripple spreads from the exact point that was pressed.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/ripple-button.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { useRef, useState, type ComponentProps } from \"react\";\n\ntype RippleButtonProps = ComponentProps<\"button\"> & {\n  /** Color of the ripple. */\n  color?: string;\n  /** How long a ripple takes to spread and fade, in seconds. */\n  duration?: number;\n};\n\ntype Ripple = { id: number; x: number; y: number; size: number };\n\n/** A button whose ripple spreads from the exact point that was pressed. */\nexport function RippleButton({\n  color = \"#f4ede3\",\n  duration = 0.6,\n  className = \"\",\n  children,\n  type = \"button\",\n  onPointerDown,\n  onKeyDown,\n  ...rest\n}: RippleButtonProps) {\n  const reduce = useReducedMotion();\n  const [ripples, setRipples] = useState<Ripple[]>([]);\n  const nextId = useRef(0);\n\n  function spawn(el: HTMLButtonElement, clientX?: number, clientY?: number) {\n    const rect = el.getBoundingClientRect();\n    const x = clientX === undefined ? rect.width / 2 : clientX - rect.left;\n    const y = clientY === undefined ? rect.height / 2 : clientY - rect.top;\n    // Wide enough to reach the farthest corner from where it starts.\n    const size = 2 * Math.hypot(Math.max(x, rect.width - x), Math.max(y, rect.height - y));\n    const id = nextId.current++;\n    setRipples((list) => [...list.slice(-4), { id, x, y, size }]);\n  }\n\n  return (\n    <button\n      type={type}\n      {...rest}\n      onPointerDown={(e) => {\n        onPointerDown?.(e);\n        if (!e.defaultPrevented && e.button === 0) spawn(e.currentTarget, e.clientX, e.clientY);\n      }}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        // Keyboard presses ripple from the center.\n        if (!e.defaultPrevented && !e.repeat && (e.key === \"Enter\" || e.key === \" \")) spawn(e.currentTarget);\n      }}\n      className={`relative isolate inline-flex items-center justify-center gap-2 overflow-hidden rounded-full bg-ember px-7 py-3.5 font-display font-semibold text-ink-950 transition-colors hover:bg-ember-soft disabled:cursor-not-allowed disabled:opacity-50 ${className}`}\n    >\n      <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 z-0\">\n        {ripples.map((r) => (\n          <motion.span\n            key={r.id}\n            className=\"absolute rounded-full\"\n            style={{ left: r.x - r.size / 2, top: r.y - r.size / 2, width: r.size, height: r.size, backgroundColor: color }}\n            initial={{ scale: reduce ? 1 : 0, opacity: reduce ? 0.2 : 0.38 }}\n            animate={{ scale: 1, opacity: 0 }}\n            transition={\n              reduce\n                ? { duration: 0.3 }\n                : { scale: { duration, ease: [0.2, 0.7, 0.3, 1] }, opacity: { duration: duration * 1.15, ease: \"easeIn\" } }\n            }\n            onAnimationComplete={() => setRipples((list) => list.filter((item) => item.id !== r.id))}\n          />\n        ))}\n      </span>\n      <span className=\"relative z-10 inline-flex items-center gap-2\">{children}</span>\n    </button>\n  );\n}\n"}]}