Skip to content

Magnetic Cursor Button

Magnetic pull with a custom follower dot that snaps to the field.

CSS 3DTypeScriptLight + AMOLED
Example.tsx
import { Buttons3D } from "@/components/3d/buttons";

export default function Example() {
  return (
    <div style={{ height: 260 }}>
      <Buttons3D
        variant="cursor"
        theme="light"
      />
    </div>
  );
}

Deps: framer-motion, gsap, lucide-react

Installation

Install the runtime dependencies, then copy the component module (and the shared 3D core when the component uses WebGL).

terminal
npm install framer-motion gsap lucide-react

# Copy the component module
cp -r src/components/3d/buttons <your-project>/src/components/3d/buttons

Dependencies: framer-motion, gsap, lucide-react

Usage

Every category module exposes one typed component. Pick an implementation with variant and pass props grouped by concern.

Example.tsx
import { Buttons3D } from "@/components/3d/buttons";

export default function Example() {
  return (
    <div style={{ height: 260 }}>
      <Buttons3D
        variant="cursor"
        theme="light"
      />
    </div>
  );
}

React implementation

With every prop set explicitly. The complete, copyable source of src/components/3d/buttons/index.tsx is available in the playground’s Source tab.

Example.tsx
import { Buttons3D } from "@/components/3d/buttons";

export default function Example() {
  return (
    <div style={{ height: 260 }}>
      <Buttons3D
        variant="cursor"
        theme="amoled"
        label="Get started"
        color="#5255ff"
        size={56}
        duration={0.4}
        depth={8}
        disabled={false}
        loading={false}
        reducedMotion={false}
      />
    </div>
  );
}

Next.js implementation

This component is DOM based, but it is still code-split with next/dynamic so interaction code ships only where it's used.

app/magnetic-cursor-button/page.tsx
// app/magnetic-cursor-button/page.tsx  (Next.js App Router)
"use client";

import dynamic from "next/dynamic";

// Heavy interactive code is split into its own chunk.
const Buttons3D = dynamic(
  () => import("@/components/3d/buttons").then((m) => m.Buttons3D),
  { ssr: false, loading: () => <div aria-busy="true" style={{ height: 260 }} /> },
);

export default function Page() {
  return (
    <main>
      <div style={{ height: 260 }}>
        <Buttons3D
          variant="cursor"
          theme="light"
        />
      </div>
    </main>
  );
}

TypeScript interfaces

MagneticCursorButton.types.ts
export type Theme = "light" | "amoled";

export interface MagneticCursorButtonProps {
  /** Which 3D Buttons implementation to render */
  variant: "cursor";
  theme: Theme;

  /* Content */
  label?: string; // default "Get started"

  /* Visual */
  color?: string; // default "#5255ff"
  size?: number; // 36–96, default 56
  depth?: number; // 2–16, default 8

  /* Animation */
  duration?: number; // 0.1–1.5, default 0.4

  /* Interaction */
  disabled?: boolean; // default false
  loading?: boolean; // default false

  /* Accessibility */
  reducedMotion?: boolean; // default false
}

Props reference

PropTypeDefaultGroupDescription
variant"cursor"—CoreSelects the implementation.
theme"light" | "amoled"—CoreThemes surfaces, materials and lighting.
labelstring"Get started"ContentLabel
colorstring (hex)"#5255ff"VisualColor
sizenumber56VisualSize (height px) (36 – 96)
durationnumber0.4AnimationAnimation duration (s) (0.1 – 1.5)
depthnumber8VisualPress depth (px) (2 – 16)
disabledbooleanfalseInteractionDisabled
loadingbooleanfalseInteractionLoading
reducedMotionbooleanfalseAccessibilityForce reduced motion

Customization

Colour props accept any hex string. Content props accept plain strings. Every value shown in the playground maps 1:1 to a prop, so you can design visually and copy the generated code. Use Share to send a pre-configured link or Export to download the configuration JSON.

Customized.tsx
import { Buttons3D } from "@/components/3d/buttons";

export default function Example() {
  return (
    <div style={{ height: 260 }}>
      <Buttons3D
        variant="cursor"
        theme="light"
        color="#ff5a36"
      />
    </div>
  );
}

Animation settings

  • durationAnimation duration (s) · 0.1–1.5
  • disabledDisabled
  • loadingLoading

All motion is suspended when prefers-reduced-motion is on.

Theme support

Pass theme="light" or theme="amoled". Surfaces, borders, shadows and text switch via CSS variables (--bg, --card, --fg, --border, --accent). AMOLED uses true #000000. Use the theme switch in the playground toolbar to preview both.

Responsive behavior

The component fills its parent, so size it with the container. Use the playground’s desktop / tablet / mobile selector to test. Layouts use fluid widths and container-relative sizing.

Accessibility notes

  • — Every variant renders a native <button>, so Enter and Space work out of the box.
  • — Loading sets aria-busy and disables the control; disabled state is conveyed visually and semantically.
  • — Label colour is chosen automatically for WCAG contrast against the fill.

Performance notes

  • — Pure CSS 3D transforms and springs — no WebGL context required.
  • — Pointer handlers update motion values without re-rendering React.
  • — Particle bursts create short-lived DOM nodes animated by GSAP and remove them on completion.