Dock
wise-ui/dockFreeComponent
A macOS-style dock with magnification effect on hover.
Live preview
live · rendered by the registry
Rendered by wise-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://wise-ui.com/r/dock.jsonSource
1"use client"23import * as React from "react"4import {5 motion,6 useMotionValue,7 useSpring,8 useTransform,9 AnimatePresence,10} from "motion/react"11import { cn } from "@/registry/wise-ui/lib/utils"1213interface DockItem {14 id: string15 icon: React.ReactNode16 label: string17 href?: string18}1920interface DockProps {21 items: DockItem[]22 onItemClick?: (item: DockItem) => void23 magnification?: number24 distance?: number25 className?: string26}2728function Dock({29 items,30 onItemClick,31 magnification = 1.5,32 distance = 150,33 className,34}: DockProps) {35 const mouseX = useMotionValue(Infinity)3637 return (38 <div39 className={cn(40 "inline-flex items-end gap-2 rounded-2xl border border-border bg-background/80 px-3 py-2 backdrop-blur-md",41 className42 )}43 onMouseMove={(e) => mouseX.set(e.clientX)}44 onMouseLeave={() => mouseX.set(Infinity)}45 >46 {items.map((item) => (47 <DockIcon48 key={item.id}49 item={item}50 mouseX={mouseX}51 magnification={magnification}52 distance={distance}53 onClick={() => onItemClick?.(item)}54 />55 ))}56 </div>57 )58}59Dock.displayName = "Dock"6061function DockIcon({62 item,63 mouseX,64 magnification,65 distance,66 onClick,67}: {68 item: DockItem69 mouseX: ReturnType<typeof useMotionValue<number>>70 magnification: number71 distance: number72 onClick: () => void73}) {74 const ref = React.useRef<HTMLButtonElement>(null)75 const [hovered, setHovered] = React.useState(false)7677 const distanceCalc = useTransform(mouseX, (val) => {78 const el = ref.current79 if (!el) return distance80 const rect = el.getBoundingClientRect()81 const center = rect.left + rect.width / 282 return Math.abs(val - center)83 })8485 const baseSize = 4086 const scaleRaw = useTransform(87 distanceCalc,88 [0, distance],89 [magnification, 1]90 )91 const scale = useSpring(scaleRaw, { stiffness: 300, damping: 25 })92 const size = useTransform(scale, (s) => s * baseSize)9394 const Wrapper = item.href ? "a" : "button"95 const wrapperProps = item.href96 ? { href: item.href, target: "_blank" as const, rel: "noopener noreferrer" }97 : {}9899 return (100 <div className="relative flex flex-col items-center">101 <AnimatePresence>102 {hovered && (103 <motion.div104 initial={{ opacity: 0, y: 4 }}105 animate={{ opacity: 1, y: -4 }}106 exit={{ opacity: 0, y: 4 }}107// … truncated
What it pulls in
npm packages
Files it writes
More from wise-ui
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Tabsanimated-tabs | wise-ui | Components | Free | 3 deps | |
| Border Beamborder-beam | wise-ui | Components | Free | 3 deps | |
| Data Tabledata-table | wise-ui | Components | Free | 3 deps | |
| Dot Matrixdot-matrix | wise-ui | Components | Free | 2 deps | |
| Editable Texteditable-text | wise-ui | Components | Free | 4 deps | |
| Gradient Sidebargradient-sidebar | wise-ui | Components | Free | 3 deps | |
| Kanban Boardkanban-board | wise-ui | Components | Free | 6 deps | |
| Magnetic Buttonmagnetic-button | wise-ui | Components | Free | 3 deps |
