Magnetic Button
A shadcn-compatible button that subtly follows the cursor using spring-based motion.
Installation
npx shadcn@latest add @navui/magnetic-buttonUsage
Use it like Button. The pointer effect enhances the action without changing keyboard activation or disabled behavior.
import { MagneticButton } from '@/components/navui/magnetic-button'
export function Example() {
return <MagneticButton movement={8} variant="outline" render={<a href="/docs" />}>Documentation</MagneticButton>
}API reference
Extends UI SDK Button with pointer movement and spring configuration. Button props are inherited; see UI SDK for their complete API. See the UI SDK Button documentation for the complete inherited API.
| Prop | Type | Default | Description |
|---|---|---|---|
movement | number | 6 | How far (in px) the button drifts toward the cursor on hover. |
wrapperClassName | string | — | Classes applied to the animated wrapper without changing button styles. |
springOptions | SpringOptions | { stiffness: 180, damping: 10, mass: 0.5 } | Custom Motion spring configuration for cursor movement and settling. |
Accessibility
- Pointer enhancement over canonical NavUI Button. Disabled and reduced-motion states return the wrapper to its origin.