Floating Dock
A floating dock navigation component with smooth hover animations. Features desktop and mobile variants with interactive icon scaling.
Installation
npm install motion/react lucide-react reactpnpm install motion/react lucide-react reactyarn add motion/react lucide-react reactbun add motion/react lucide-react reactUsage
import { FloatingDock } from "@/components/ui/floating-dock";
import { Home, Github, Twitter } from "lucide-react";
export default function MyComponent() {
const links = [
{
title: "Home",
icon: <Home className="h-full w-full" />,
href: "/",
},
{
title: "GitHub",
icon: <Github className="h-full w-full" />,
href: "https://github.com",
},
{
title: "Twitter",
icon: <Twitter className="h-full w-full" />,
href: "https://twitter.com",
},
];
return (
<div className="flex items-center justify-center h-screen">
<FloatingDock items={links} />
</div>
);
}Features
- 🎯 Interactive Icons: Icons scale smoothly on hover with spring animations
- 📱 Responsive: Separate desktop and mobile layouts
- 🎨 Smooth Animations: Powered by motion/react for fluid transitions
- 🌙 Dark Mode: Seamlessly works with light and dark themes
- 🖱️ Hover Effects: Icons expand based on mouse position
- 📱 Mobile Menu: Collapsible menu for mobile devices
Positioning
The component supports custom positioning via className props:
<FloatingDock
desktopClassName="fixed bottom-4 left-1/2 -translate-x-1/2"
mobileClassName="fixed bottom-4 right-4"
items={links}
/>Note:
- Desktop navbar is better positioned at the bottom
- Mobile navbar is better positioned at bottom right
Customization
You can customize the dock by:
- Icons: Use any React node as icons (lucide-react, custom SVGs, images)
- Colors: Modify Tailwind classes for background and text colors
- Sizes: Adjust the dock height and icon sizes via className
- Animations: The spring animations are configurable in the component
Examples
Custom Icons with Images
const links = [
{
title: "Logo",
icon: (
<img
src="/logo.png"
width={20}
height={20}
alt="Logo"
className="rounded-full"
/>
),
href: "/",
},
];Fixed Position Dock
<FloatingDock
desktopClassName="fixed bottom-8 left-1/2 -translate-x-1/2 z-50"
items={links}
/>