{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnetic-button",
  "title": "Magnetic Button",
  "description": "Leans toward the pointer from outside its edges, while the label lags behind.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://spotcheckui.com/r/spotcheck-base.json",
    "https://spotcheckui.com/r/button.json"
  ],
  "files": [
    {
      "path": "registry/spotcheck/components/spotcheck/magnetic-button.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { animate, motion, useMotionValue, useReducedMotion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { buttonClass, type ButtonVariant } from \"@/registry/spotcheck/components/spotcheck/button\"\n\nconst FOLLOW_SPRING = { stiffness: 260, damping: 17 }\nconst RELEASE_SPRING = { stiffness: 170, damping: 8 }\nconst PRESS_SPRING = { stiffness: 700, damping: 22 }\nconst LIFT_SPRING = { stiffness: 500, damping: 9 }\nconst PRESSED_SCALE = 0.88\n\ntype MagneticButtonProps = {\n  children: React.ReactNode\n  variant?: ButtonVariant\n  /** How far the button leans, as a share of the pointer's distance. */\n  strength?: number\n  /** How far the label leans, which should be less than `strength` so it lags. */\n  labelStrength?: number\n  onClick?: React.MouseEventHandler<HTMLButtonElement>\n  disabled?: boolean\n  /** Added to the hover zone around the button. */\n  className?: string\n}\n\nexport function MagneticButton({\n  children,\n  variant = \"ink\",\n  strength = 0.32,\n  labelStrength = 0.12,\n  onClick,\n  disabled,\n  className,\n}: MagneticButtonProps) {\n  const reduced = useReducedMotion()\n  const button = React.useRef<HTMLButtonElement>(null)\n  const x = useMotionValue(0)\n  const y = useMotionValue(0)\n  const labelX = useMotionValue(0)\n  const labelY = useMotionValue(0)\n  const scale = useMotionValue(1)\n\n  const lean = (dx: number, dy: number, spring: { stiffness: number; damping: number }) => {\n    if (reduced) return\n    const options = { type: \"spring\", ...spring } as const\n    animate(x, dx * strength, options)\n    animate(y, dy * strength, options)\n    animate(labelX, dx * labelStrength, options)\n    animate(labelY, dy * labelStrength, options)\n  }\n\n  const press = (to: number, spring: { stiffness: number; damping: number }) => {\n    if (!reduced) animate(scale, to, { type: \"spring\", ...spring })\n  }\n\n  return (\n    <div\n      className={cn(\"grid place-items-center p-11\", className)}\n      onPointerMove={(event) => {\n        const rect = button.current?.getBoundingClientRect()\n        if (!rect || event.pointerType === \"touch\") return\n        lean(event.clientX - (rect.left + rect.width / 2), event.clientY - (rect.top + rect.height / 2), FOLLOW_SPRING)\n      }}\n      onPointerLeave={() => lean(0, 0, RELEASE_SPRING)}\n    >\n      <motion.button\n        ref={button}\n        type=\"button\"\n        disabled={disabled}\n        onClick={onClick}\n        onPointerDown={() => press(PRESSED_SCALE, PRESS_SPRING)}\n        onPointerUp={() => press(1, LIFT_SPRING)}\n        onPointerCancel={() => press(1, LIFT_SPRING)}\n        style={{ x, y, scale }}\n        className={buttonClass(variant, \"px-5.5 py-4 text-sm will-change-transform enabled:active:translate-x-0 enabled:active:translate-y-0 enabled:active:shadow-[4px_4px_0_var(--ink)]\")}\n      >\n        <motion.span className=\"inline-block\" style={{ x: labelX, y: labelY }}>\n          {children}\n        </motion.span>\n      </motion.button>\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "springs"
  ],
  "type": "registry:component"
}