Magnetic
Wraps one button or link so it leans toward the pointer as it comes near, up to 8px, and settles back when the pointer leaves.
When to use
- The one or two actions you want people to notice, such as a hero button.
- Marketing and onboarding surfaces where a little life helps.
When not to use
- Dense toolbars and tables; many things leaning at once is noise.
- Touch and keyboard: it does nothing there, so nothing may depend on it.
Installation
terminal
pnpm dlx shadcn@latest add @caliper/magnetic
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.
API reference
Magnetic
3 props
Also accepts the native props of its root element and a ref.
PropTypeDefaultDescription
strengthnumber0.28How much of the distance to the pointer it follows. 0.28 is a gentle lean.
maxnumber8The most it moves, in pixels.
reachnumber40How far past its edge the pointer starts to pull, in pixels.
Keyboard
- No custom key handling; Tab and the native activation keys do the work.
Accessibility
It is built on native elements, so roles and focus come from the browser.
Motion
- State changes animate with the library's shared durations and curves, so its timing matches every other part.
- Under reduced motion each change lands on its end state without movement; nothing is hidden or skipped.
Notes for AI
Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.
/docs/components/magnetic.mdThe index of every part is at /llms.txt.
More in Actions
ButtonA familiar action with immediate focus, a tactile press, and optional pending or label feedback that stays on the button itself.Split buttonA primary action joined to its alternatives; the chosen option becomes the label.Action buttonA button that runs async work and reports progress, success or failure on itself, at one width.