{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "drawer", "type": "registry:block", "title": "Drawer", "description": "Mobile drawers with snap points, drag handles, and side layouts.", "author": "Wensity ", "dependencies": [ "@base-ui/react", "@tabler/icons-react", "clsx", "tailwind-merge" ], "registryDependencies": [], "files": [ { "path": "registry/wensity/lib/utils.ts", "type": "registry:lib", "target": "@lib/utils.ts", "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n" }, { "path": "registry/wensity/drawer.tsx", "type": "registry:component", "target": "@components/wensity/drawer.tsx", "content": "\"use client\";\n\n/**\n * Drawer — Base UI Drawer foundation (Phase 4B).\n * Swipe dismiss, snap points, portal, focus trap, and scroll lock from Base UI.\n * Motion is CSS keyed to data-starting-style / data-ending-style + swipe CSS vars.\n * D-17: onOpenChange simplified to (open: boolean) => void; asChild → render;\n * snapPoints are viewport-height fractions (0–1), not horizontal carousel panels.\n */\n\nimport * as React from \"react\";\nimport { Drawer as BaseDrawer } from \"@base-ui/react/drawer\";\nimport { IconX } from \"@tabler/icons-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type DrawerSide = \"bottom\" | \"top\" | \"left\" | \"right\" | \"fullscreen\";\n\nconst elevatedSurfaceClass = cn(\n \"border border-[var(--border)] bg-[var(--primitive-surface-elevated)]\",\n \"[box-shadow:var(--primitive-shadow-modal)]\",\n \"isolate overflow-hidden\",\n);\n\nconst backdropClass = cn(\n \"fixed inset-0 z-[var(--primitive-z-overlay)] bg-[var(--primitive-backdrop)]\",\n \"transition-opacity duration-[300ms] ease-[var(--primitive-ease,cubic-bezier(0.23,1,0.32,1))]\",\n \"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0\",\n \"motion-reduce:transition-none\",\n);\n\nconst drawerMotionBase = cn(\n \"transition-[opacity,translate,scale] duration-[500ms] ease-[var(--primitive-ease,cubic-bezier(0.23,1,0.32,1))]\",\n \"data-[ending-style]:duration-[250ms]\",\n \"motion-reduce:transition-none\",\n);\n\nconst sideSwipeDirection: Record =\n {\n bottom: \"down\",\n top: \"up\",\n left: \"left\",\n right: \"right\",\n fullscreen: \"down\",\n };\n\nconst sideLayout: Record = {\n bottom: cn(\n \"fixed bottom-4 left-1/2 z-[var(--primitive-z-overlay)]\",\n \"w-[min(calc(100vw-2rem),26rem)] max-w-full -translate-x-1/2\",\n \"rounded-[var(--primitive-radius-surface)]\",\n \"max-h-[min(72vh,26rem)]\",\n ),\n top: cn(\n \"fixed left-1/2 top-4 z-[var(--primitive-z-overlay)]\",\n \"w-[min(calc(100vw-2rem),26rem)] max-w-full -translate-x-1/2\",\n \"rounded-[var(--primitive-radius-surface)]\",\n \"max-h-[min(72vh,26rem)]\",\n ),\n left: cn(\n \"fixed inset-y-0 left-0 z-[var(--primitive-z-overlay)]\",\n \"flex h-full w-[min(100vw,22rem)] flex-col rounded-none border-l-0\",\n ),\n right: cn(\n \"fixed inset-y-0 right-0 z-[var(--primitive-z-overlay)]\",\n \"flex h-full w-[min(100vw,22rem)] flex-col rounded-none border-r-0\",\n ),\n fullscreen: cn(\n \"fixed inset-3 z-[var(--primitive-z-overlay)] flex flex-col\",\n \"rounded-[var(--primitive-radius-surface)] sm:inset-4 md:inset-6\",\n ),\n};\n\nconst sideMotion: Record = {\n bottom: cn(\n drawerMotionBase,\n \"translate-y-[calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px))]\",\n \"data-[starting-style]:translate-y-[105%] data-[ending-style]:translate-y-[105%]\",\n \"motion-reduce:data-[starting-style]:translate-y-0 motion-reduce:data-[ending-style]:translate-y-0\",\n ),\n top: cn(\n drawerMotionBase,\n \"translate-y-[calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px))]\",\n \"data-[starting-style]:-translate-y-[105%] data-[ending-style]:-translate-y-[105%]\",\n \"motion-reduce:data-[starting-style]:translate-y-0 motion-reduce:data-[ending-style]:translate-y-0\",\n ),\n left: cn(\n drawerMotionBase,\n \"translate-x-[var(--drawer-swipe-movement-x,0px)]\",\n \"data-[starting-style]:-translate-x-full data-[ending-style]:-translate-x-full\",\n \"motion-reduce:data-[starting-style]:translate-x-0 motion-reduce:data-[ending-style]:translate-x-0\",\n ),\n right: cn(\n drawerMotionBase,\n \"translate-x-[var(--drawer-swipe-movement-x,0px)]\",\n \"data-[starting-style]:translate-x-full data-[ending-style]:translate-x-full\",\n \"motion-reduce:data-[starting-style]:translate-x-0 motion-reduce:data-[ending-style]:translate-x-0\",\n ),\n fullscreen: cn(\n drawerMotionBase,\n \"translate-y-[var(--drawer-swipe-movement-y,0px)]\",\n \"data-[starting-style]:opacity-0 data-[ending-style]:opacity-0\",\n \"data-[starting-style]:scale-[0.985] data-[ending-style]:scale-[0.985]\",\n \"motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100\",\n ),\n};\n\nfunction adaptOpenChange(\n onOpenChange?: (open: boolean) => void,\n): ((open: boolean, details: unknown) => void) | undefined {\n if (!onOpenChange) return undefined;\n return (open) => onOpenChange(open);\n}\n\ntype DrawerContextValue = {\n side: DrawerSide;\n};\n\nconst DrawerContext = React.createContext({\n side: \"bottom\",\n});\n\nexport interface DrawerProps\n extends Omit<\n React.ComponentPropsWithoutRef,\n \"onOpenChange\" | \"swipeDirection\" | \"children\"\n > {\n side?: DrawerSide;\n onOpenChange?: (open: boolean) => void;\n children: React.ReactNode;\n}\n\nexport function Drawer({\n side = \"bottom\",\n onOpenChange,\n snapPoints,\n modal = true,\n children,\n ...props\n}: DrawerProps) {\n return (\n \n \n {children}\n \n \n );\n}\n\nexport interface DrawerTriggerProps\n extends React.ComponentPropsWithoutRef {\n asChild?: boolean;\n}\n\nexport function DrawerTrigger({\n asChild = false,\n children,\n ...props\n}: DrawerTriggerProps) {\n if (asChild && React.isValidElement(children)) {\n const nativeButton =\n typeof children.type === \"string\" ? children.type === \"button\" : true;\n return (\n \n );\n }\n return {children};\n}\n\nexport interface DrawerCloseProps\n extends React.ComponentPropsWithoutRef {\n asChild?: boolean;\n}\n\nexport function DrawerClose({\n asChild = false,\n children,\n ...props\n}: DrawerCloseProps) {\n if (asChild && React.isValidElement(children)) {\n const nativeButton =\n typeof children.type === \"string\" ? children.type === \"button\" : true;\n return (\n \n );\n }\n return {children};\n}\n\nexport interface DrawerSnapPanelProps {\n children: React.ReactNode;\n className?: string;\n}\n\n/** Simple content section wrapper for multi-section drawer layouts (no horizontal drag). */\nexport function DrawerSnapPanel({ children, className }: DrawerSnapPanelProps) {\n return (\n
\n {children}\n
\n );\n}\n\nconst drawerScrollBodyClass = cn(\n \"min-h-0 flex-1 overflow-y-auto overscroll-contain touch-pan-y\",\n \"[&_input]:select-text [&_textarea]:select-text [&_[contenteditable=true]]:select-text\",\n);\n\nexport function DrawerScrollBody({\n className,\n ...props\n}: React.HTMLAttributes) {\n return (\n \n );\n}\n\nexport interface DrawerContentProps {\n children: React.ReactNode;\n className?: string;\n title?: React.ReactNode;\n description?: React.ReactNode;\n container?: React.ComponentPropsWithoutRef<\n typeof BaseDrawer.Portal\n >[\"container\"];\n showHandle?: boolean;\n showClose?: boolean;\n}\n\nexport function DrawerContent({\n children,\n className,\n title,\n description,\n container,\n showHandle = true,\n showClose = true,\n}: DrawerContentProps) {\n const { side } = React.useContext(DrawerContext);\n const isFullscreen = side === \"fullscreen\";\n const isBottom = side === \"bottom\";\n const isTop = side === \"top\";\n const showGrabHandle = showHandle && (isBottom || isTop);\n\n return (\n \n \n \n \n \n \n {typeof title === \"string\" ? title : \"Drawer\"}\n \n {description ? (\n \n {typeof description === \"string\" ? description : \"Drawer panel\"}\n \n ) : null}\n\n {isBottom && showGrabHandle ? (\n
\n \n
\n ) : null}\n\n {(title || description) && (\n \n {title ? (\n \n {title}\n

\n ) : null}\n {description ? (\n \n {description}\n

\n ) : null}\n \n )}\n\n {isFullscreen ? (\n \n
\n {children}\n
\n
\n ) : (\n \n {children}\n \n )}\n\n {isTop && showGrabHandle ? (\n
\n \n
\n ) : null}\n\n {showClose ? (\n \n \n \n ) : null}\n
\n
\n
\n
\n );\n}\n" } ], "cssVars": { "theme": { "font-sans": "var(--font-satoshi, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif)", "font-display": "var(--font-cabinet, ui-sans-serif, system-ui, sans-serif)", "color-background": "var(--background)", "color-foreground": "var(--foreground)", "color-surface": "var(--surface)", "color-surface-muted": "var(--surface-muted)", "color-border": "var(--border)", "color-border-strong": "var(--border-strong)", "color-muted": "var(--muted)", "color-muted-foreground": "var(--muted-foreground)", "color-ring": "var(--ring)", "color-chili-50": "#fff1ee", "color-chili-100": "#ffe2db", "color-chili-200": "#ffa896", "color-chili-300": "#ff8a73", "color-chili-400": "#f15a45", "color-chili-500": "#cd1c18", "color-chili-600": "#b31614", "color-chili-700": "#9b1313", "color-chili-800": "#6a0d0e", "color-chili-900": "#38000a", "color-chili-950": "#1f0006", "color-primitive-surface-elevated": "var(--primitive-surface-elevated)", "color-primitive-surface-overlay": "var(--primitive-surface-overlay)", "color-primitive-surface-hover": "var(--primitive-surface-hover)", "color-primitive-surface-active": "var(--primitive-surface-active)", "color-primitive-surface-selected": "var(--primitive-surface-selected)", "color-primitive-border-subtle": "var(--primitive-border-subtle)", "color-primitive-ring": "var(--primitive-ring)", "color-primitive-text-secondary": "var(--primitive-text-secondary)", "color-primitive-text-placeholder": "var(--primitive-text-placeholder)", "color-primitive-text-inverse": "var(--primitive-text-inverse)", "color-primitive-destructive": "var(--primitive-destructive)", "color-primitive-destructive-hover": "var(--primitive-destructive-hover)", "color-primitive-destructive-active": "var(--primitive-destructive-active)", "color-primitive-destructive-foreground": "var(--primitive-destructive-foreground)", "color-primitive-destructive-surface": "var(--primitive-destructive-surface)", "color-primitive-destructive-border": "var(--primitive-destructive-border)", "color-primitive-success": "var(--primitive-success)", "color-primitive-warning": "var(--primitive-warning)", "color-primitive-info": "var(--primitive-info)", "color-primitive-control-solid": "var(--primitive-control-solid)", "color-primitive-control-solid-hover": "var(--primitive-control-solid-hover)", "color-primitive-control-solid-active": "var(--primitive-control-solid-active)", "color-primitive-control-solid-foreground": "var(--primitive-control-solid-foreground)", "color-primitive-chart-1": "var(--primitive-chart-1)", "color-primitive-chart-2": "var(--primitive-chart-2)", "color-primitive-chart-3": "var(--primitive-chart-3)", "color-primitive-chart-4": "var(--primitive-chart-4)", "color-primitive-chart-5": "var(--primitive-chart-5)", "color-primitive-chart-6": "var(--primitive-chart-6)", "radius-primitive": "var(--primitive-radius)", "radius-primitive-control": "var(--primitive-radius-control)", "radius-primitive-control-sm": "var(--primitive-radius-control-sm)", "radius-primitive-surface": "var(--primitive-radius-surface)", "radius-primitive-item": "var(--primitive-radius-item)", "font-primitive-sans": "var(--primitive-font-sans)", "font-primitive-display": "var(--primitive-font-display)", "font-primitive-mono": "var(--primitive-font-mono)", "spacing-primitive-control-height-sm": "var(--primitive-control-height-sm)", "spacing-primitive-control-height-md": "var(--primitive-control-height-md)", "spacing-primitive-control-height-lg": "var(--primitive-control-height-lg)" }, "light": { "background": "#fafafa", "foreground": "#0a0a0a", "surface": "#ffffff", "surface-muted": "#f4f4f5", "border": "rgba(10, 10, 10, 0.08)", "border-strong": "rgba(10, 10, 10, 0.16)", "muted": "#f4f4f5", "muted-foreground": "#52525b", "ring": "#cd1c18", "pattern-fg": "rgba(10, 10, 10, 0.07)", "llb-primary": "#18181b", "llb-primary-fg": "#ffffff", "llb-success": "#1f883d", "llb-error": "#cf222e", "primitive-surface-elevated": "#ffffff", "primitive-surface-overlay": "#ffffff", "primitive-surface-hover": "color-mix(in srgb, var(--foreground) 4%, transparent)", "primitive-surface-active": "color-mix(in srgb, var(--foreground) 7%, transparent)", "primitive-surface-selected": "color-mix(in srgb, var(--foreground) 6%, transparent)", "primitive-border-subtle": "color-mix(in srgb, var(--border) 60%, transparent)", "primitive-ring": "color-mix(in srgb, var(--foreground) 45%, transparent)", "primitive-text-secondary": "color-mix(in srgb, var(--foreground) 72%, transparent)", "primitive-text-placeholder": "color-mix(in srgb, var(--muted-foreground) 85%, transparent)", "primitive-radius": "0.875rem", "primitive-font-sans": "var(--font-sans)", "primitive-font-display": "var(--font-display)", "primitive-font-mono": "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace", "primitive-control-solid": "#24292d", "primitive-control-solid-hover": "#2c3237", "primitive-control-solid-active": "#1e2326", "primitive-control-solid-foreground": "#ffffff", "primitive-chart-1": "#2a78d6", "primitive-chart-2": "#1baf7a", "primitive-chart-3": "#eda100", "primitive-chart-4": "#008300", "primitive-chart-5": "#4a3aa7", "primitive-chart-6": "#e34948", "primitive-text-inverse": "#ffffff", "primitive-text-hint": "0.6875rem", "primitive-destructive": "#dc2626", "primitive-destructive-hover": "#b91c1c", "primitive-destructive-active": "#991b1b", "primitive-destructive-foreground": "#ffffff", "primitive-destructive-surface": "rgba(220, 38, 38, 0.10)", "primitive-destructive-border": "rgba(220, 38, 38, 0.45)", "primitive-success": "#047857", "primitive-success-surface": "rgba(4, 120, 87, 0.10)", "primitive-success-border": "rgba(4, 120, 87, 0.45)", "primitive-warning": "#b45309", "primitive-warning-surface": "rgba(180, 83, 9, 0.10)", "primitive-warning-border": "rgba(180, 83, 9, 0.45)", "primitive-info": "#0369a1", "primitive-info-surface": "rgba(3, 105, 161, 0.10)", "primitive-info-border": "rgba(3, 105, 161, 0.45)", "primitive-radius-control": "var(--primitive-radius)", "primitive-radius-control-sm": "max(0px, calc(var(--primitive-radius) - 4px))", "primitive-radius-surface": "calc(var(--primitive-radius) + min(2px, var(--primitive-radius)))", "primitive-radius-item": "max(0px, calc(var(--primitive-radius-surface) - 6px))", "primitive-control-height-sm": "2rem", "primitive-control-height-md": "2.25rem", "primitive-control-height-lg": "2.5rem", "primitive-shadow-raised": "0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px -12px rgba(0, 0, 0, 0.08)", "primitive-shadow-overlay": "0 1px 2px rgba(0, 0, 0, 0.06), 0 18px 48px -24px rgba(0, 0, 0, 0.35)", "primitive-shadow-modal": "0 1px 2px rgba(0, 0, 0, 0.08), 0 24px 64px -28px rgba(0, 0, 0, 0.42)", "primitive-z-overlay": "100", "primitive-z-popover": "130", "primitive-z-toast": "140", "primitive-backdrop": "rgba(0, 0, 0, 0.6)", "primitive-ease": "cubic-bezier(0.23, 1, 0.32, 1)" }, "dark": { "background": "#0a0a0b", "foreground": "#f5f5f6", "surface": "#111113", "surface-muted": "#18181b", "border": "rgba(255, 255, 255, 0.08)", "border-strong": "rgba(255, 255, 255, 0.14)", "muted": "#1c1c1f", "muted-foreground": "#a1a1aa", "ring": "#cd1c18", "pattern-fg": "rgba(255, 255, 255, 0.06)", "llb-primary": "#f5f5f6", "llb-primary-fg": "#0a0a0b", "llb-success": "#2da44e", "llb-error": "#f85149", "primitive-surface-elevated": "#0f0f10", "primitive-surface-overlay": "#141415", "primitive-surface-hover": "color-mix(in srgb, var(--foreground) 5%, transparent)", "primitive-surface-active": "color-mix(in srgb, var(--foreground) 10%, transparent)", "primitive-surface-selected": "color-mix(in srgb, var(--foreground) 8%, transparent)", "primitive-border-subtle": "color-mix(in srgb, var(--border) 60%, transparent)", "primitive-ring": "color-mix(in srgb, var(--foreground) 45%, transparent)", "primitive-text-secondary": "color-mix(in srgb, var(--foreground) 72%, transparent)", "primitive-text-placeholder": "color-mix(in srgb, var(--muted-foreground) 85%, transparent)", "primitive-radius": "0.875rem", "primitive-font-sans": "var(--font-sans)", "primitive-font-display": "var(--font-display)", "primitive-font-mono": "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace", "primitive-control-solid": "#f5f3ee", "primitive-control-solid-hover": "#ffffff", "primitive-control-solid-active": "#e8e4da", "primitive-control-solid-foreground": "#151719", "primitive-chart-1": "#3987e5", "primitive-chart-2": "#199e70", "primitive-chart-3": "#c98500", "primitive-chart-4": "#008300", "primitive-chart-5": "#9085e9", "primitive-chart-6": "#e66767", "primitive-text-inverse": "#151719", "primitive-text-hint": "0.6875rem", "primitive-destructive": "#e11d2e", "primitive-destructive-hover": "#c1121f", "primitive-destructive-active": "#a4161a", "primitive-destructive-foreground": "#ffffff", "primitive-destructive-surface": "rgba(225, 29, 46, 0.12)", "primitive-destructive-border": "rgba(225, 29, 46, 0.52)", "primitive-success": "#34d399", "primitive-success-surface": "rgba(52, 211, 153, 0.12)", "primitive-success-border": "rgba(52, 211, 153, 0.45)", "primitive-warning": "#fbbf24", "primitive-warning-surface": "rgba(251, 191, 36, 0.12)", "primitive-warning-border": "rgba(251, 191, 36, 0.45)", "primitive-info": "#38bdf8", "primitive-info-surface": "rgba(56, 189, 248, 0.12)", "primitive-info-border": "rgba(56, 189, 248, 0.45)", "primitive-radius-control": "var(--primitive-radius)", "primitive-radius-control-sm": "max(0px, calc(var(--primitive-radius) - 4px))", "primitive-radius-surface": "calc(var(--primitive-radius) + min(2px, var(--primitive-radius)))", "primitive-radius-item": "max(0px, calc(var(--primitive-radius-surface) - 6px))", "primitive-control-height-sm": "2rem", "primitive-control-height-md": "2.25rem", "primitive-control-height-lg": "2.5rem", "primitive-shadow-raised": "0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6)", "primitive-shadow-overlay": "0 1px 2px rgba(0, 0, 0, 0.4), 0 20px 56px -28px rgba(0, 0, 0, 0.72)", "primitive-shadow-modal": "0 1px 2px rgba(0, 0, 0, 0.45), 0 28px 72px -32px rgba(0, 0, 0, 0.8)", "primitive-z-overlay": "100", "primitive-z-popover": "130", "primitive-z-toast": "140", "primitive-backdrop": "rgba(0, 0, 0, 0.6)", "primitive-ease": "cubic-bezier(0.23, 1, 0.32, 1)" } }, "css": { "@layer base": { ":where([data-wensity-primitive])": { "font-family": "var(--primitive-font-sans)" } }, "@utility scrollbar-hidden": { "scrollbar-width": "none", "-ms-overflow-style": "none", "&::-webkit-scrollbar": { "display": "none" } }, "@keyframes wensity-marquee-x": { "from": { "transform": "translate3d(0, 0, 0)" }, "to": { "transform": "translate3d(-50%, 0, 0)" } }, "@keyframes wensity-marquee-x-reverse": { "from": { "transform": "translate3d(-50%, 0, 0)" }, "to": { "transform": "translate3d(0, 0, 0)" } }, "@keyframes wensity-morph-rot-cw": { "from": { "transform": "rotate(0deg)" }, "to": { "transform": "rotate(360deg)" } }, "@keyframes wensity-morph-rot-ccw": { "from": { "transform": "rotate(0deg)" }, "to": { "transform": "rotate(-360deg)" } } }, "docs": "Free Wensity component. Installs to @components/wensity/drawer.tsx. For Pro components and updates, use pnpm dlx wensity@latest add drawer.", "categories": [ "UI Primitives", "wensity", "free" ], "meta": { "wensity": { "slug": "drawer", "access": "free", "category": "UI Primitives", "kind": "component", "componentUrl": "https://ui.wensity.com/primitives/drawer", "shadcnUrl": "https://ui.wensity.com/r/drawer", "cliInstall": "pnpm dlx wensity@latest add drawer" } } }