Skip to content
caliper ui docs

Pro

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.

Pro
pnpm dlx shadcn@latest add @caliper/magnetic

Ledger for teams

Close the month in two days, not nine · free for up to three seats

Installs components/ui/magnetic.tsxDepends on none beyond ReactMotion honours reduced motion

When to use

Use it for

  • The one or two actions you want people to notice, such as a hero button.
  • Marketing and onboarding surfaces where a little life helps.

Skip it when

  • Dense toolbars and tables; many things leaning at once is noise.
  • Touch and keyboard: it does nothing there, so nothing may depend on it.

Decisions

Why it is built this way, so you know what to keep when you change your copy.

Behaviour

Only the wrapper moves
The control inside keeps its own press, focus ring and hit area, so activation never changes. The lean is a follow with a soft settle, not a spring that overshoots.
Fine pointers only
Touch, keyboard focus and reduced motion get no lean at all. Nothing important may depend on it.

Usage

Wrap one child
A lean larger than 8px starts to feel like the button is running away, so the limit is part of the part.

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.

Usage

Import it from your copy of the source. The example behind the preview comes with the source.

example.tsx
import { Magnetic } from "@/components/ui/magnetic"

The worked example comes with Pro

The 27-line example behind the preview opens here, ready to copy.

  • 626 Pro parts, blocks and page templates, all with source
  • $149 once, with lifetime updates. No renewal
  • A full refund within 14 days if it is not for you
Checking your licence…

API reference

Magnetic

component

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.

Accessibility

It is built on native elements, so roles and focus come from the browser.

No custom key handling; Tab and the native activation keys do the work.

Motion

It checks prefers-reduced-motion itself and settles immediately instead of travelling. Every state is still reachable.

All Actions examples