Magnetic pull
An element that gently chases the pointer within a magnetic field, then springs back.
API reference
Components
<Magnetic />
Drop-in magnetic wrapper with padded field zone.
children?
Element to pull.
className?
Merged onto the field-zone wrapper.
<MagneticButton />
Styled compact-pill trigger for use inside Magnetic.
children?
Button label.
className?
Merged onto the button.
onClick?
Click handler.
type?
Button type. Default "button".
Hooks
useMagnetic
Magnetic-pull hook: springs, field handlers, reduced-motion gate.
useMagnetic(options: UseMagneticOptions): UseMagneticResult<T>pullStrength?
Fraction of pointer offset applied as translate. Default 0.35.
maxPull?
Hard clamp on displacement in px. Default 26.
Returns
ref
Ref for the pulled element.
style
Motion style with smoothed x/y springs.
fieldProps
Pointer handlers for the field zone wrapper.
motionAllowed
Whether pull is live (false under reduced motion).
Functions
magneticPull
Pure clamped magnetic displacement for one pointer move.
magneticPull(options: MagneticPullInput): { x: number; y: number }pointer
Pointer position in client coordinates.
rect
Element bounding rect including current transform.
current
Current translate so rest centre can be recovered from the live rect.
pullStrength
Fraction of offset from rest centre applied as translate.
maxPull
Hard clamp on displacement in px.
Featured in
See the magnetic pull composed into full sections.
