dock
cult-ui/dockUnverifiedComponent
macOS-style dock component with hover effects and smooth animations
Install it
npx shadcn@latest add https://raw.githubusercontent.com/nolly-studio/cult-ui/HEAD/apps/www/dock.jsonSource
1"use client"23import React, {4 createContext,5 ReactNode,6 useCallback,7 useContext,8 useEffect,9 useMemo,10 useRef,11 useState,12} from "react"13import {14 animate,15 AnimatePresence,16 motion,17 MotionValue,18 useAnimation,19 useMotionValue,20 useSpring,21 useTransform,22} from "motion/react"2324import { cn } from "@/lib/utils"2526// Interface to define the types for our Dock context27interface DockContextType {28 width: number // Width of the dock29 hovered: boolean // If the dock is hovered30 setIsZooming: (value: boolean) => void // Function to set zooming state31 zoomLevel: MotionValue<number> // Motion value for zoom level32 mouseX: MotionValue<number> // Motion value for mouse X position33 animatingIndexes: number[] // Array of animating indexes34 setAnimatingIndexes: (indexes: number[]) => void // Function to set animating indexes35}3637// Initial width for the dock38const INITIAL_WIDTH = 483940// Create a context to manage Dock state41const DockContext = createContext<DockContextType>({42 width: 0,43 hovered: false,44 setIsZooming: () => {},45 zoomLevel: null as any,46 mouseX: null as any,47 animatingIndexes: [],48 setAnimatingIndexes: () => {},49})5051// Custom hook to use Dock context52const useDock = () => useContext(DockContext)5354// Props for the Dock component55interface DockProps {56 className?: string57 children: ReactNode // React children to be rendered within the dock58}5960// Main Dock component: orchestrating the dock's animation behavior61function Dock({ className, children }: DockProps) {62 const [hovered, setHovered] = useState(false) // State to track if the dock is hovered. When the mouse hovers over the dock, this state changes to true.63 const [width, setWidth] = useState(0) // State to track the width of the dock. This dynamically updates based on the dock's current width.64 const dockRef = useRef<HTMLDivElement>(null) // Reference to the dock element in the DOM. This allows direct manipulation and measurement of the dock.65 const isZooming = useRef(false) // Reference to track if the zooming animation is active. This prevents conflicting animations.66 const [animatingIndexes, setAnimatingIndexes] = useState<number[]>([]) // State to track which dock items are currently animating. This array holds the indices of animating items.6768 // Callback to toggle the zooming state. This ensures that we don't trigger hover animations while zooming.69 const setIsZooming = useCallback((value: boolean) => {70// … truncated
What it pulls in
npm packages
Files it writes
More from cult/ui
All 157 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-instructionsai-instructions | cult/ui | Components | Unverified | 2 deps | |
| ai-instructions-demoai-instructions-demo | cult/ui | Components | Unverified | no deps | |
| animated-numberanimated-number | cult/ui | Components | Unverified | 1 dep | |
| animated-number-demoanimated-number-demo | cult/ui | Components | Unverified | no deps | |
| bg-animate-buttonbg-animate-button | cult/ui | Components | Unverified | no deps | |
| bg-animate-button-demobg-animate-button-demo | cult/ui | Components | Unverified | no deps | |
| bg-animated-fractal-dot-gridbg-animated-fractal-dot-grid | cult/ui | Components | Unverified | 1 dep | |
| bg-animated-fractal-dot-grid-demobg-animated-fractal-dot-grid-demo | cult/ui | Components | Unverified | no deps |
