{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"magnetic-button","type":"registry:ui","title":"Magnetic button","description":"Button that pulls toward the cursor with spring physics while its label drifts slightly further for depth.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/magnetic-button/magnetic-button.tsx","type":"registry:ui","target":"components/facade/magnetic-button.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useMotionValue, useReducedMotion, useSpring, useTransform } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type MagneticButtonVariant = \"brand\" | \"solid\" | \"outline\";\n\nexport interface MagneticButtonProps\n  extends Omit<\n    React.ButtonHTMLAttributes<HTMLButtonElement>,\n    \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\" | \"onAnimationEnd\"\n  > {\n  /** How strongly the shell follows the cursor, 0 to 1. Defaults to 0.35. */\n  strength?: number;\n  /** Extra multiplier applied to the inner label. Defaults to 1.6. */\n  labelStrength?: number;\n  /** Distance in px outside the button where the pull starts. Defaults to 40. */\n  radius?: number;\n  variant?: MagneticButtonVariant;\n  /** Pass `href` to render an `<a>` instead of a `<button>`. */\n  href?: string;\n  className?: string;\n  children?: React.ReactNode;\n}\n\nconst variants: Record<MagneticButtonVariant, string> = {\n  brand: \"bg-brand text-brand-foreground hover:bg-[color-mix(in_srgb,var(--brand)_88%,black)]\",\n  solid: \"bg-foreground text-background hover:opacity-90\",\n  outline: \"bg-muted text-foreground hover:bg-foreground/10\",\n};\n\nconst spring = { stiffness: 320, damping: 32, mass: 0.6 };\n\nexport function MagneticButton({\n  strength = 0.35,\n  labelStrength = 1.6,\n  radius = 40,\n  variant = \"brand\",\n  href,\n  className,\n  children,\n  type = \"button\",\n  ...rest\n}: MagneticButtonProps) {\n  const reduce = useReducedMotion();\n  const zoneRef = React.useRef<HTMLSpanElement>(null);\n\n  const x = useMotionValue(0);\n  const y = useMotionValue(0);\n  const sx = useSpring(x, spring);\n  const sy = useSpring(y, spring);\n  const lx = useTransform(sx, (v) => v * labelStrength);\n  const ly = useTransform(sy, (v) => v * labelStrength);\n\n  const handleMove = (e: React.PointerEvent<HTMLSpanElement>) => {\n    if (reduce || e.pointerType === \"touch\") return;\n    const el = zoneRef.current;\n    if (!el) return;\n    const rect = el.getBoundingClientRect();\n    x.set((e.clientX - (rect.left + rect.width / 2)) * strength);\n    y.set((e.clientY - (rect.top + rect.height / 2)) * strength);\n  };\n\n  const reset = () => {\n    x.set(0);\n    y.set(0);\n  };\n\n  const shellClass = cn(\n    \"relative z-[1] inline-flex h-12 items-center justify-center rounded-full px-6 text-[15px] font-medium tracking-[-0.01em] will-change-transform\",\n    \"transition-[background-color,opacity] duration-200\",\n    \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n    \"disabled:pointer-events-none disabled:opacity-50\",\n    variants[variant],\n    className,\n  );\n\n  const label = (\n    <motion.span style={{ x: lx, y: ly }} className=\"relative inline-flex items-center gap-2 [&_svg]:size-4\">\n      {children}\n    </motion.span>\n  );\n\n  return (\n    <span\n      ref={zoneRef}\n      onPointerMove={handleMove}\n      onPointerLeave={reset}\n      className=\"relative inline-flex\"\n      style={{ padding: radius, margin: -radius }}\n    >\n      {href !== undefined ? (\n        <motion.a\n          href={href}\n          style={{ x: sx, y: sy }}\n          className={shellClass}\n          onBlur={reset}\n          {...(rest as Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\" | \"onAnimationEnd\">)}\n        >\n          {label}\n        </motion.a>\n      ) : (\n        <motion.button\n          type={type}\n          style={{ x: sx, y: sy }}\n          className={shellClass}\n          whileTap={reduce ? undefined : { scale: 0.98 }}\n          onBlur={reset}\n          {...rest}\n        >\n          {label}\n        </motion.button>\n      )}\n    </span>\n  );\n}\n\nexport default MagneticButton;\n"}],"categories":["buttons"],"meta":{"tier":"free","demo":"import { ArrowUpRight, Calendar } from \"lucide-react\";\nimport { MagneticButton } from \"./magnetic-button\";\n\nexport default function Demo() {\n  return (\n    <div className=\"w-full max-w-2xl rounded-[28px] bg-muted px-6 py-14 text-center text-foreground sm:px-12 sm:py-16\">\n      <p className=\"text-xs font-medium uppercase tracking-wider text-muted-foreground\">Studio Juniper, Portland</p>\n      <h3 className=\"mx-auto mt-4 max-w-md font-display text-[32px] font-semibold leading-[1.05] tracking-[-0.03em] sm:text-[40px]\">\n        Have a space that deserves better light?\n      </h3>\n      <p className=\"mx-auto mt-4 max-w-sm text-[15px] leading-relaxed text-muted-foreground\">\n        Interior design for homes and boutique hospitality. Taking four new projects this fall.\n      </p>\n      <div className=\"mt-9 flex flex-wrap items-center justify-center gap-3\">\n        <MagneticButton>\n          Start a project\n          <ArrowUpRight aria-hidden />\n        </MagneticButton>\n        <MagneticButton variant=\"outline\" className=\"bg-background dark:bg-secondary\">\n          <Calendar aria-hidden />\n          Book a 20 min call\n        </MagneticButton>\n      </div>\n      <p className=\"mt-8 text-xs text-muted-foreground\">Move your cursor near the buttons</p>\n    </div>\n  );\n}\n"}}