Ballmac UI home

Magnetic Button

The Ballmac Button with a magnetic pull: it drifts toward a nearby mouse pointer on a spring, and its label moves a little further for depth. Takes every Button prop.

Installation

$ pnpm dlx shadcn@latest add @ballmac/magnetic-button

Usage

import { MagneticButton } from "@/components/ballmac/magnetic-button"

The full example is in the Code tab above.

API reference

PropTypeDefault
strength

How far the button follows the pointer, as a fraction of the pointer's offset from its center.

number0.2
radius

Distance in pixels outside the button's edge where the pull starts.

number72
wrapperClassName

Classes for the wrapper that holds the button's place in the layout.

string—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Enter / SpaceActivates the button
TabMoves focus to the button

Use with AI

Use like Button (variant, size, shape, loading, onClick…). The pull only reacts to a mouse, stops while disabled or loading, and is off under reduced motion, where it is a plain Button. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Magnetic Button (@ballmac/magnetic-button) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • The single primary call to action in a hero or pricing section
  • A playful secondary action on a marketing page

Not for

  • Forms, toolbars and dense UI (use button)
  • Several buttons side by side; one magnetic button per view keeps it meaningful
  • Rendering a link (not supported; use an <a> with buttonVariants instead)

Registry JSON: https://ui.ballmac.com/r/magnetic-button.json

Credits

Free to use in personal and commercial projects.