{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnetic-button",
  "title": "Magnetic Button",
  "description": "Button that drifts toward the pointer for a magnetic hover effect.",
  "dependencies": [
    "@vllnt/ui@^0.2.1"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/default/magnetic-button/magnetic-button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@vllnt/ui\";\n\n/** Props for {@link MagneticButton}. */\nexport type MagneticButtonProps = React.ComponentPropsWithoutRef<\"button\"> & {\n  /** Fraction of the pointer offset applied as pull. Defaults to `0.4`. */\n  strength?: number;\n};\n\nfunction usePrefersReducedMotion(): boolean {\n  const [reduced, setReduced] = React.useState(false);\n\n  React.useEffect(() => {\n    if (\n      typeof window === \"undefined\" ||\n      typeof window.matchMedia !== \"function\"\n    ) {\n      return;\n    }\n\n    const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const onChange = (): void => {\n      setReduced(query.matches);\n    };\n\n    onChange();\n    query.addEventListener(\"change\", onChange);\n\n    return () => {\n      query.removeEventListener(\"change\", onChange);\n    };\n  }, []);\n\n  return reduced;\n}\n\n/**\n * Button that drifts toward the pointer while hovered, then snaps back.\n *\n * Respects `prefers-reduced-motion`: the button stays put.\n *\n * @example\n * ```tsx\n * <MagneticButton>Hover me</MagneticButton>\n * ```\n */\nexport const MagneticButton = ({\n  children,\n  className,\n  ref,\n  strength = 0.4,\n  style,\n  ...props\n}: MagneticButtonProps & { ref?: React.Ref<HTMLButtonElement> }) => {\n  const reduced = usePrefersReducedMotion();\n  const [transform, setTransform] = React.useState<string>();\n\n  const handlePointerMove = (\n    event: React.PointerEvent<HTMLButtonElement>,\n  ): void => {\n    if (reduced) {\n      return;\n    }\n\n    const bounds = event.currentTarget.getBoundingClientRect();\n    const offsetX = (event.clientX - bounds.left - bounds.width / 2) * strength;\n    const offsetY = (event.clientY - bounds.top - bounds.height / 2) * strength;\n\n    setTransform(`translate(${offsetX}px, ${offsetY}px)`);\n  };\n\n  return (\n    <button\n      className={cn(\n        \"transition-transform duration-200 ease-out will-change-transform\",\n        className,\n      )}\n      onPointerLeave={() => {\n        setTransform(undefined);\n      }}\n      onPointerMove={handlePointerMove}\n      ref={ref}\n      style={{ transform, ...style }}\n      type=\"button\"\n      {...props}\n    >\n      {children}\n    </button>\n  );\n};\nMagneticButton.displayName = \"MagneticButton\";\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component",
  "version": "0.2.1",
  "stability": "stable"
}
