Dock
magicui/dockFreeComponent
An implementation of the MacOS dock using react + tailwindcss + motion
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/dock.jsonSource
1"use client"23import React, { useRef, type PropsWithChildren } from "react"4import { cva, type VariantProps } from "class-variance-authority"5import {6 motion,7 MotionValue,8 useMotionValue,9 useSpring,10 useTransform,11} from "motion/react"12import type { MotionProps } from "motion/react"1314import { cn } from "@/lib/utils"1516export interface DockProps extends VariantProps<typeof dockVariants> {17 className?: string18 iconSize?: number19 iconMagnification?: number20 disableMagnification?: boolean21 iconDistance?: number22 direction?: "top" | "middle" | "bottom"23 children: React.ReactNode24}2526const DEFAULT_SIZE = 4027const DEFAULT_MAGNIFICATION = 6028const DEFAULT_DISTANCE = 14029const DEFAULT_DISABLEMAGNIFICATION = false3031const dockVariants = cva(32 "supports-backdrop-blur:bg-white/10 supports-backdrop-blur:dark:bg-black/10 mx-auto mt-8 flex h-[58px] w-max items-center justify-center gap-2 rounded-2xl border p-2 backdrop-blur-md"33)3435const Dock = React.forwardRef<HTMLDivElement, DockProps>(36 (37 {38 className,39 children,40 iconSize = DEFAULT_SIZE,41 iconMagnification = DEFAULT_MAGNIFICATION,42 disableMagnification = DEFAULT_DISABLEMAGNIFICATION,43 iconDistance = DEFAULT_DISTANCE,44 direction = "middle",45 ...props46 },47 ref48 ) => {49 const mouseX = useMotionValue(Infinity)5051 const renderChildren = () => {52 return React.Children.map(children, (child) => {53 if (54 React.isValidElement<DockIconProps>(child) &&55 child.type === DockIcon56 ) {57 return React.cloneElement(child, {58 ...child.props,59 mouseX: mouseX,60 size: iconSize,61 magnification: iconMagnification,62 disableMagnification: disableMagnification,63 distance: iconDistance,64 })65 }66 return child67 })68 }6970 return (71 <motion.div72 ref={ref}73 onMouseMove={(e) => mouseX.set(e.pageX)}74 onMouseLeave={() => mouseX.set(Infinity)}75 {...props}76 className={cn(dockVariants({ className }), {77 "items-start": direction === "top",78 "items-center": direction === "middle",79 "items-end": direction === "bottom",80 })}81 >82 {renderChildren()}83 </motion.div>84 )85 }86)8788Dock.displayName = "Dock"8990export interface DockIconProps extends Omit<91 MotionProps & React.HTMLAttributes<HTMLDivElement>,92 "children"93> {94 size?: number95 magnification?: number96// … truncated
What it pulls in
npm packages
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
