Command Palette

Search for a command to run...

Docs
Magnetic Dock

Magnetic Dock

macOS-style dock with magnetic hover effects and smooth icon animations

Loading...

Installation

Usage

import MagneticDock from "@/components/ruixen/magnetic-dock";
import { Home, Search, Settings, User, Bell } from "lucide-react";
 
const dockItems = [
  { id: 1, icon: <Home className="h-7 w-7" />, label: "Home" },
  { id: 2, icon: <Search className="h-7 w-7" />, label: "Search" },
  { id: 3, icon: <Bell className="h-7 w-7" />, label: "Alerts" },
  { id: 4, icon: <Settings className="h-7 w-7" />, label: "Settings" },
  { id: 5, icon: <User className="h-7 w-7" />, label: "Profile" },
];
 
export default function App() {
  return (
    <MagneticDock
      items={dockItems}
      position="bottom"
      magneticStrength={18}
      hoverScale={1.35}
    />
  );
}

Props

PropTypeDefaultDescription
itemsDockItem[]Default itemsArray of dock items
positionstring"bottom"Dock placement: "bottom", "top", "left"
magneticStrengthnumber18How strong the magnetic effect is
hoverScalenumber1.35How much the hovered icon enlarges

Features

  • Magnetic Effect: Icons push away from hovered icon
  • Scale Animation: Hovered icon scales up smoothly
  • Position Variants: Support for bottom, top, and left placement
  • Glassmorphism: Semi-transparent background with backdrop blur
  • Labels: Optional labels appear on hover

Types

interface DockItem {
  id: number;
  icon: React.ReactNode;
  label?: string;
}

Magnetic Algorithm

The magnetic effect calculates distance from hovered icon:

  • Icons within 2 positions are affected
  • Displacement is inversely proportional to distance
  • Uses spring animations for smooth movement