{"name":"drawer","dependencies":["@base-ui/react"],"files":[{"path":"drawer.tsx","content":"\"use client\";\n\nimport { Drawer as DrawerPrimitive } from \"@base-ui/react/drawer\";\nimport { cn } from \"cn\";\nimport * as React from \"react\";\n\ntype DrawerContextProps = {\n\thasSnapPoints: boolean;\n\tmodal: DrawerPrimitive.Root.Props[\"modal\"];\n\tshowSwipeHandle: boolean;\n\tswipeDirection: NonNullable<DrawerPrimitive.Root.Props[\"swipeDirection\"]>;\n};\n\nconst DrawerContext = React.createContext<DrawerContextProps | null>(null);\n\nfunction useDrawer() {\n\tconst context = React.useContext(DrawerContext);\n\n\tif (!context) {\n\t\tthrow new Error(\"useDrawer must be used within a Drawer.\");\n\t}\n\n\treturn context;\n}\n\nfunction Drawer({\n\tmodal = true,\n\tshowSwipeHandle = false,\n\tsnapPoints,\n\tswipeDirection = \"down\",\n\t...props\n}: DrawerPrimitive.Root.Props & {\n\tshowSwipeHandle?: boolean;\n}) {\n\tconst hasSnapPoints = snapPoints != null && snapPoints.length > 0;\n\tconst contextValue = React.useMemo(\n\t\t() => ({ hasSnapPoints, modal, showSwipeHandle, swipeDirection }),\n\t\t[hasSnapPoints, modal, showSwipeHandle, swipeDirection],\n\t);\n\n\treturn (\n\t\t<DrawerContext.Provider value={contextValue}>\n\t\t\t<DrawerPrimitive.Root\n\t\t\t\tdata-slot=\"drawer\"\n\t\t\t\tmodal={modal}\n\t\t\t\tsnapPoints={snapPoints}\n\t\t\t\tswipeDirection={swipeDirection}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t</DrawerContext.Provider>\n\t);\n}\n\nfunction DrawerTrigger({ ...props }: DrawerPrimitive.Trigger.Props) {\n\treturn <DrawerPrimitive.Trigger data-slot=\"drawer-trigger\" {...props} />;\n}\n\nfunction DrawerPortal({ ...props }: DrawerPrimitive.Portal.Props) {\n\treturn <DrawerPrimitive.Portal data-slot=\"drawer-portal\" {...props} />;\n}\n\nfunction DrawerClose({ ...props }: DrawerPrimitive.Close.Props) {\n\treturn <DrawerPrimitive.Close data-slot=\"drawer-close\" {...props} />;\n}\n\nfunction DrawerOverlay({\n\tclassName,\n\tvariant = \"opaque\",\n\t...props\n}: DrawerPrimitive.Backdrop.Props & {\n\tvariant?: \"opaque\" | \"blur\" | \"transparent\";\n}) {\n\treturn (\n\t\t<DrawerPrimitive.Backdrop\n\t\t\tdata-slot=\"drawer-overlay\"\n\t\t\tdata-variant={variant}\n\t\t\tclassName={cn(\n\t\t\t\t\"fixed inset-0 z-50 min-h-dvh select-none bg-black/80 opacity-[max(var(--drawer-overlay-min-opacity,0),calc(1-var(--drawer-swipe-progress)))] transition-opacity duration-450 ease-[cubic-bezier(0.32,0.72,0,1)] data-ending-style:pointer-events-none data-[variant=blur]:bg-black/50 data-[variant=opaque]:bg-black/80 data-[variant=transparent]:bg-transparent data-ending-style:opacity-0 data-starting-style:opacity-0 data-[variant=blur]:backdrop-blur-md data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute data-snap-points:[--drawer-overlay-min-opacity:0.5]\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DrawerSwipeHandle({\n\tclassName,\n\t...props\n}: React.ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"drawer-swipe-handle\"\n\t\t\taria-hidden=\"true\"\n\t\t\tclassName={cn(\n\t\t\t\t\"relative z-10 flex shrink-0 cursor-grab transition-opacity duration-200 after:block after:shrink-0 after:rounded-full after:bg-muted active:cursor-grabbing group-data-[swipe-direction=left]/drawer-popup:order-last group-data-[swipe-direction=up]/drawer-popup:order-last group-data-[swipe-axis=x]/drawer-popup:h-full group-data-[swipe-axis=y]/drawer-popup:h-3 group-data-[swipe-axis=x]/drawer-popup:w-3 group-data-[swipe-axis=y]/drawer-popup:w-full group-data-[swipe-direction=up]/drawer-popup:items-start group-data-[swipe-direction=down]/drawer-popup:items-end group-data-[swipe-axis=x]/drawer-popup:items-center group-data-[swipe-direction=left]/drawer-popup:justify-start group-data-[swipe-direction=right]/drawer-popup:justify-end group-data-[swipe-axis=y]/drawer-popup:justify-center group-data-nested-drawer-open/drawer-popup:opacity-0 group-data-nested-drawer-swiping/drawer-popup:opacity-100 group-data-[swipe-axis=x]/drawer-popup:after:h-25 group-data-[swipe-axis=y]/drawer-popup:after:h-1.5 group-data-[swipe-axis=x]/drawer-popup:after:w-1.5 group-data-[swipe-axis=y]/drawer-popup:after:w-[100px]\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DrawerContent({\n\tclassName,\n\tchildren,\n\toverlayVariant = \"opaque\",\n\t...props\n}: DrawerPrimitive.Popup.Props & {\n\toverlayVariant?: \"opaque\" | \"blur\" | \"transparent\";\n}) {\n\tconst { hasSnapPoints, modal, showSwipeHandle, swipeDirection } = useDrawer();\n\tconst swipeAxis =\n\t\tswipeDirection === \"down\" || swipeDirection === \"up\" ? \"y\" : \"x\";\n\n\treturn (\n\t\t<DrawerPortal data-slot=\"drawer-portal\">\n\t\t\t{modal === true && (\n\t\t\t\t<DrawerOverlay\n\t\t\t\t\tvariant={overlayVariant}\n\t\t\t\t\tdata-snap-points={hasSnapPoints ? \"\" : undefined}\n\t\t\t\t/>\n\t\t\t)}\n\t\t\t<DrawerPrimitive.Viewport\n\t\t\t\tdata-slot=\"drawer-viewport\"\n\t\t\t\tdata-modal={modal}\n\t\t\t\tclassName=\"pointer-events-none fixed inset-0 z-50 select-none data-[modal=true]:pointer-events-auto\"\n\t\t\t>\n\t\t\t\t<DrawerPrimitive.Popup\n\t\t\t\t\tdata-slot=\"drawer-popup\"\n\t\t\t\t\tdata-swipe-axis={swipeAxis}\n\t\t\t\t\tdata-snap-points={hasSnapPoints ? \"\" : undefined}\n\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t// Base.\n\t\t\t\t\t\t\"group/drawer-popup transform-[translate3d(var(--translate-x,0px),var(--translate-y,0px),0)_scale(var(--stack-scale))] pointer-events-auto fixed z-50 m-(--drawer-inset,0px) flex h-(--drawer-content-height) max-h-(--drawer-content-max-height,none) min-h-0 w-(--drawer-content-width,auto) select-none flex-col border border-popover bg-popover text-popover-foreground text-sm outline-none transition-[transform,height,opacity,filter] duration-450 ease-[cubic-bezier(0.22,1,0.36,1)] will-change-transform [--drawer-bleed-background:transparent] [--drawer-inset:0px] [interpolate-size:allow-keywords] dark:border-border\",\n\t\t\t\t\t\t// Nested.\n\t\t\t\t\t\t\"data-nested-drawer-open:overflow-hidden data-nested-drawer-open:brightness-95\",\n\t\t\t\t\t\t// Bleed.\n\t\t\t\t\t\t\"after:pointer-events-none after:absolute after:bg-(--drawer-bleed-background,var(--color-popover)) data-[swipe-axis=y]:after:inset-x-0 data-[swipe-axis=x]:after:inset-y-0 data-[swipe-direction=right]:after:start-full data-[swipe-direction=left]:after:end-full data-[swipe-direction=down]:after:top-full data-[swipe-direction=up]:after:bottom-full data-[swipe-axis=y]:after:h-(--bleed) data-[swipe-axis=x]:after:w-(--bleed)\",\n\t\t\t\t\t\t// Sizing.\n\t\t\t\t\t\t\"[--drawer-content-height:var(--drawer-height,auto)] data-[swipe-axis=y]:data-snap-points:[--drawer-content-height:100dvh] data-[swipe-axis=x]:[--drawer-content-width:75%] data-[swipe-axis=y]:[--drawer-content-max-height:80vh] data-[swipe-axis=x]:sm:[--drawer-content-width:24rem]\",\n\t\t\t\t\t\t// Stack.\n\t\t\t\t\t\t\"[--bleed:3rem] [--peek:1rem] [--stack-height:var(--drawer-frontmost-height,var(--drawer-height,0px))] [--stack-peek-offset:max(0px,calc((var(--nested-drawers)-var(--stack-progress))*var(--peek)))] [--stack-progress:clamp(0,var(--drawer-swipe-progress),1)] [--stack-scale-base:max(0,calc(1-(var(--nested-drawers)*var(--stack-step))))] [--stack-scale:clamp(0,calc(var(--stack-scale-base)+(var(--stack-step)*var(--stack-progress))),1)] [--stack-shrink:calc(1-var(--stack-scale))] [--stack-step:0.05]\",\n\t\t\t\t\t\t// Transitions.\n\t\t\t\t\t\t\"data-ending-style:transform-(--closed-transform) data-starting-style:transform-(--closed-transform) data-ending-style:data-nested-drawer-swiping:duration-[calc(var(--drawer-swipe-strength)*400ms)] data-ending-style:data-swiping:duration-[calc(var(--drawer-swipe-strength)*400ms)] data-ending-style:opacity-[0.9999] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] data-nested-drawer-swiping:duration-0 data-swiping:duration-0\",\n\t\t\t\t\t\t// Axis: y.\n\t\t\t\t\t\t\"data-[swipe-axis=y]:data-nested-drawer-open:h-(--stack-height) data-[swipe-axis=y]:inset-x-0\",\n\t\t\t\t\t\t// Axis: x.\n\t\t\t\t\t\t\"data-[swipe-axis=x]:inset-y-0 data-[swipe-axis=x]:flex-row\",\n\t\t\t\t\t\t// Direction: down.\n\t\t\t\t\t\t\"data-[swipe-direction=down]:bottom-0 data-[swipe-direction=down]:origin-bottom data-[swipe-direction=down]:rounded-t-xl data-[swipe-direction=down]:[--closed-transform:translate3d(0,calc(100%+var(--drawer-inset,0px)+2px),0)] data-[swipe-direction=down]:[--translate-y:calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y)-var(--stack-peek-offset)-(var(--stack-shrink)*var(--stack-height)))]\",\n\t\t\t\t\t\t// Direction: up.\n\t\t\t\t\t\t\"data-[swipe-direction=up]:top-0 data-[swipe-direction=up]:origin-top data-[swipe-direction=up]:rounded-b-xl data-[swipe-direction=up]:[--closed-transform:translate3d(0,calc(-100%-var(--drawer-inset,0px)-2px),0)] data-[swipe-direction=up]:[--translate-y:calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y)+var(--stack-peek-offset)+(var(--stack-shrink)*var(--stack-height)))]\",\n\t\t\t\t\t\t// Direction: left.\n\t\t\t\t\t\t\"data-[swipe-direction=left]:left-0 data-[swipe-direction=left]:origin-left data-[swipe-direction=left]:[--closed-transform:translate3d(calc(-100%-var(--drawer-inset,0px)-2px),0,0)] data-[swipe-direction=left]:[--translate-x:calc(var(--drawer-swipe-movement-x)+var(--stack-peek-offset)+(var(--stack-shrink)*100%))]\",\n\t\t\t\t\t\t// Direction: right.\n\t\t\t\t\t\t\"data-[swipe-direction=right]:right-0 data-[swipe-direction=right]:origin-right data-[swipe-direction=right]:[--closed-transform:translate3d(calc(100%+var(--drawer-inset,0px)+2px),0,0)] data-[swipe-direction=right]:[--translate-x:calc(var(--drawer-swipe-movement-x)-var(--stack-peek-offset)-(var(--stack-shrink)*100%))]\",\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t)}\n\t\t\t\t\t{...props}\n\t\t\t\t>\n\t\t\t\t\t{showSwipeHandle && <DrawerSwipeHandle />}\n\t\t\t\t\t<DrawerPrimitive.Content\n\t\t\t\t\t\tdata-slot=\"drawer-content\"\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"flex min-h-0 flex-1 select-text flex-col gap-2 overflow-hidden overscroll-contain rounded-[inherit] transition-opacity duration-300 ease-[cubic-bezier(0.45,1.005,0,1.005)] group-data-swiping/drawer-popup:select-none group-data-nested-drawer-open/drawer-popup:opacity-0 group-data-nested-drawer-swiping/drawer-popup:opacity-100\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</DrawerPrimitive.Content>\n\t\t\t\t</DrawerPrimitive.Popup>\n\t\t\t</DrawerPrimitive.Viewport>\n\t\t</DrawerPortal>\n\t);\n}\n\nfunction DrawerHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"drawer-header\"\n\t\t\tclassName={cn(\n\t\t\t\t\"flex shrink-0 flex-col gap-0.5 p-4 pb-0 group-data-[swipe-axis=y]/drawer-popup:text-center md:gap-1.5 md:text-start\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DrawerFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"drawer-footer\"\n\t\t\tclassName={cn(\"flex shrink-0 flex-row-reverse gap-2 p-4 pt-0\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DrawerTitle({ className, ...props }: DrawerPrimitive.Title.Props) {\n\treturn (\n\t\t<DrawerPrimitive.Title\n\t\t\tdata-slot=\"drawer-title\"\n\t\t\tclassName={cn(\"font-medium text-base text-foreground\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction DrawerDescription({\n\tclassName,\n\t...props\n}: DrawerPrimitive.Description.Props) {\n\treturn (\n\t\t<DrawerPrimitive.Description\n\t\t\tdata-slot=\"drawer-description\"\n\t\t\tclassName={cn(\"text-balance text-muted-foreground text-sm\", className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nexport {\n\tDrawer,\n\tDrawerClose,\n\tDrawerContent,\n\tDrawerDescription,\n\tDrawerFooter,\n\tDrawerHeader,\n\tDrawerOverlay,\n\tDrawerPortal,\n\tDrawerSwipeHandle,\n\tDrawerTitle,\n\tDrawerTrigger,\n};\n","type":"registry:ui"}],"type":"registry:ui"}