UniqueUI

Magnetic Button

Button that stretches toward the cursor when nearby and snaps back with spring physics.

npx uniqueui add magnetic-button

Preview

Usage

import { MagneticButton } from "@/components/ui/magnetic-button";

export default function Example() {
  return (
    <div className="flex flex-wrap gap-8 items-center justify-center p-20 text-white">
      <MagneticButton>Hover near me</MagneticButton>
      <MagneticButton
        magneticStrength={0.5}
        magneticRadius={200}
        className="bg-gradient-to-b from-purple-700 to-purple-900"
      >
        Stronger pull
      </MagneticButton>
    </div>
  );
}

Props

PropTypeDescription
childrenReact.ReactNodeThe internal content of the button.
classNamestringStyle overrides appended to the interactive boundary.
magneticStrengthnumberFloat determining how fast/far the button lerps toward the cursor.
magneticRadiusnumberPixel radius extending outward from the button where gravity begins.
onClick() => voidStandard click event handler.
disabledbooleanDisables interaction and magnetic gravitational pull.