pnpm dlx shadcn@latest add @gammaui/magnetize-button
import { MagnetizeButton } from "@/components/gammaui/magnetize-button"
export default function Example() {
return (
<div className="flex min-h-screen items-center justify-center bg-gray-50 dark:bg-gray-900">
<MagnetizeButton>Hover me</MagnetizeButton>
</div>
)
}The MagnetizeButton releases several particles that magnetically snap toward the button center on hover or touch. When the interaction ends, the particles spring back to random positions.
| Prop | Type | Default | Description |
|---|---|---|---|
| particleCount | number | 12 | Number of particles orbiting the button. |
| attractRadius | number | 50 | Distance at which particles begin attracting. |
| className | string | — | Optional Tailwind classes to style the button. |
| ...props | React.ButtonHTMLAttributes | — | Any additional <button> attributes. |
<MagnetizeButton particleCount={25}>More Particles</MagnetizeButton><MagnetizeButton attractRadius={120}>Stronger Pull</MagnetizeButton><MagnetizeButton className="border-emerald-300 bg-emerald-200 text-emerald-700">
Green Style
</MagnetizeButton>Magnetic Interaction Particles snap toward the button on hover/touch.
Random Particle Generation Each particle starts from a unique random position.
Smooth Framer-Motion Animation Spring-based transitions for natural movement.
Dark Mode Ready Uses Tailwind classes compatible with dark themes.
Highly Customizable Particle count, radius, colors, and size are fully configurable.
particleCount) for dramatic visual effects.relative containers for more controlled particle boundaries.