Skip to Content
Kokonut UI

BT-04Buttons

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.

Install with
lucide-react

PROPay Button and more like it are in Kokonut UI Pro

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 Copy code above 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
numberDefault 1

Filing density. 1 places a filing roughly every 12px; 2 doubles it.

radius
numberDefault 64

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

NeedsVersionComes from
lucide-react^0.556.0npm, installed by the CLI
cn from lib/utils.tsshadcn init
React19Your app
Tailwind CSS4Your app

No provider, font or global CSS to set up: the file works as soon as it lands.