Magnet Button - React Component | Kokonut UI
Magnet Button
A call-to-action button wrapped in a field of iron filings that align to its magnetic field and lean toward your cursor.
Installation
Magnet Button is a free, open-source React component in the Kokonut UI Buttons collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/attract-button.tsx, so the code is yours to change.
npx shadcn@latest add @kokonutui/attract-button
Or add it by hand: install its packages, then copy the source from the above command into components/kokonutui/attract-button.tsx.
npm install lucide-react
Usage
import AttractButton from "@/components/kokonutui/attract-button";
export default function Example() {
return <AttractButton />;
}
Props
density
numberDefault1- Filing density. 1 places a filing roughly every 12px; 2 doubles it.
radius
numberDefault64- How far, in px, the field of filings extends past the button's edges.
containerClassName
string- Classes for the wrapper that holds the button and its field.
Also takes every prop of ComponentProps<"button">.
Dependencies
| Needs | Version | Comes from |
|---|---|---|
lucide-react |
^0.556.0 |
npm, installed by the CLI |
cn from lib/utils.ts |
shadcn init | |
| React | 19 |
Your app |
| Tailwind CSS | 4 |
Your app |
No provider, font or global CSS to set up: the file works as soon as it lands.