An element pulled toward the pointer inside a radius.
Installation
Install the packages
npm install @prequelui/react motion@prequelui/react reuses the primitive library your components already depend on.
Add the component
npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/magnetic.jsonnpx shadcn@latest add https://animate.prequelui.terravidhal.me/r/magnetic.json
Turn on the motion
npx @prequelui/cli@latest animate magneticThe CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { Magnetic } from "@/components/prequelui/effects/magnetic";
export default function Demo() {
return (
<Magnetic range={120} strength={0.5}>
<button className="rounded-lg bg-primary px-4 py-2 text-primary-foreground">
Pull me closer
</button>
</Magnetic>
);
}import { Magnetic } from "@/components/prequelui/magnetic";
export function Variant() {
return (
<Magnetic tempo={1.2}>
…
</Magnetic>
);
}Animation
A magnetic element watches the pointer, measures the distance from its own centre and moves toward the cursor with a falloff. The displacement is a continuous motion value driven by a spring, so entering, leaving and interrupting are all the same gesture.
- Spring: stiffness 100, damping 10, mass 0.5.
- Strength 0.5 at the centre, falling linearly to zero at the range edge.
- The window listener is removed when the element is disabled or off-screen.
- Touch pointers and reduced motion disable the effect entirely.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.
Magnetic
| Prop | Type | Default |
|---|---|---|
| strength | number | 0.5 |
| range | number | 120 |
| springOptions | SpringOptions | 100 / 10 / 0.5 |
| onlyOnHover | boolean | false |
| disableOnTouch | boolean | true |
| className | string | — |