Skip to Content
Prisma UI - React component library
ComponentsComponentsMagnetic

Magnetic

A magnetic wrapper component that attracts its children towards the mouse cursor. Inspired by Motion Primitives’ Magnetic . Supports self, parent, and global action areas.

Installation

npx shadcn@latest add https://prismaui.com/components/magnetic.json

Import

import { Magnetic } from '@/components/ui/magnetic';

Preview

<Magnetic> <Button>Hover me</Button> </Magnetic>

Custom Intensity & Range

<Magnetic intensity={0.8} range={200}> <Button variant='outline'>Stronger pull</Button> </Magnetic>

Action Areas

Control which element triggers the magnetic effect.

{ /* Default: self */ } <Magnetic actionArea='self'> <Button>Self</Button> </Magnetic>; { /* Parent triggers the effect */ } <Magnetic actionArea='parent'> <Button>Parent</Button> </Magnetic>; { /* Global mouse tracking */ } <Magnetic actionArea='global' range={300}> <Button>Global</Button> </Magnetic>;

Props

PropTypeDefaultDescription
childrenReact.ReactNodeContent to apply the effect to.
classNamestringAdditional CSS classes.
intensitynumber0.6Strength of the magnetic pull.
rangenumber100Effective range in pixels.
actionArea'self' | 'parent' | 'global''self'Trigger area.
springOptionsSpringOptions{ stiffness: 26.7, damping: 4.1, mass: 0.2 }Spring config.
Last updated on