family-drawer
cult-ui/family-drawerUnverifiedComponent
A multi-view drawer component with smooth animations, view navigation, and customizable content views
Install it
npx shadcn@latest add https://raw.githubusercontent.com/nolly-studio/cult-ui/HEAD/apps/www/family-drawer.jsonSource
1"use client"23import {4 createContext,5 useContext,6 useMemo,7 useRef,8 useState,9 type ReactNode,10} from "react"11import { Slot } from "@radix-ui/react-slot"12import clsx from "clsx"13import { AnimatePresence, motion } from "motion/react"14import useMeasure from "react-use-measure"15import { Drawer } from "vaul"1617// ============================================================================18// Types19// ============================================================================2021type ViewComponent = React.ComponentType<Record<string, unknown>>2223interface ViewsRegistry {24 [viewName: string]: ViewComponent25}2627// ============================================================================28// Context29// ============================================================================3031interface FamilyDrawerContextValue {32 isOpen: boolean33 view: string34 setView: (view: string) => void35 opacityDuration: number36 elementRef: ReturnType<typeof useMeasure>[0]37 bounds: ReturnType<typeof useMeasure>[1]38 views: ViewsRegistry | undefined39}4041const FamilyDrawerContext = createContext<FamilyDrawerContextValue | undefined>(42 undefined43)4445function useFamilyDrawer() {46 const context = useContext(FamilyDrawerContext)47 if (!context) {48 throw new Error(49 "FamilyDrawer components must be used within FamilyDrawerRoot"50 )51 }52 return context53}5455// ============================================================================56// Root Component57// ============================================================================5859interface FamilyDrawerRootProps {60 children: ReactNode61 open?: boolean62 defaultOpen?: boolean63 onOpenChange?: (open: boolean) => void64 defaultView?: string65 onViewChange?: (view: string) => void66 views?: ViewsRegistry67}6869function FamilyDrawerRoot({70 children,71 open: controlledOpen,72 defaultOpen = false,73 onOpenChange,74 defaultView = "default",75 onViewChange,76 views: customViews,77}: FamilyDrawerRootProps) {78 const [internalOpen, setInternalOpen] = useState(defaultOpen)79 const [view, setView] = useState(defaultView)80 const [elementRef, bounds] = useMeasure()81 const previousHeightRef = useRef<number>(0)8283 const isOpen = controlledOpen !== undefined ? controlledOpen : internalOpen84 const setIsOpen = onOpenChange || setInternalOpen8586 const opacityDuration = useMemo(() => {87 const currentHeight = bounds.height88 const previousHeight = previousHeightRef.current8990 const MIN_DURATION = 0.1591 const MAX_DURATION = 0.279293// … 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 |
