{"name":"drawer","type":"registry:ui","files":[{"path":"drawer.tsx","type":"registry:ui","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { Drawer as DrawerPrimitive } from \"@base-ui/react/drawer\"\nimport { X as XIcon } from \"honestui/icons\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype DrawerSide = \"top\" | \"right\" | \"bottom\" | \"left\"\n\n// The side the drawer enters from, and the swipe that dismisses it.\nconst SWIPE_DIRECTION = {\n  top: \"up\",\n  right: \"right\",\n  bottom: \"down\",\n  left: \"left\",\n} as const satisfies Record<DrawerSide, DrawerPrimitive.Root.Props[\"swipeDirection\"]>\n\nconst DrawerSideContext = React.createContext<DrawerSide>(\"bottom\")\n\nfunction Drawer({\n  side = \"bottom\",\n  ...props\n}: DrawerPrimitive.Root.Props & {\n  side?: DrawerSide\n}) {\n  return (\n    <DrawerSideContext.Provider value={side}>\n      <DrawerPrimitive.Root\n        data-slot=\"drawer\"\n        swipeDirection={SWIPE_DIRECTION[side]}\n        {...props}\n      />\n    </DrawerSideContext.Provider>\n  )\n}\n\nfunction DrawerTrigger(props: DrawerPrimitive.Trigger.Props) {\n  return <DrawerPrimitive.Trigger data-slot=\"drawer-trigger\" {...props} />\n}\n\nfunction DrawerPortal(props: DrawerPrimitive.Portal.Props) {\n  return <DrawerPrimitive.Portal {...props} />\n}\n\nfunction DrawerClose(props: DrawerPrimitive.Close.Props) {\n  return <DrawerPrimitive.Close data-slot=\"drawer-close\" {...props} />\n}\n\nfunction DrawerBackdrop({ className, ...props }: DrawerPrimitive.Backdrop.Props) {\n  return (\n    <DrawerPrimitive.Backdrop\n      data-slot=\"drawer-backdrop\"\n      className={cn(\n        // The Sheet backdrop, faded by swipe progress so it lightens as the\n        // drawer is dragged away. Release timing follows the swipe velocity.\n        \"fixed inset-0 z-[var(--hui-z-index-portal)] min-h-dvh bg-[var(--hui-color-overlay-black-a5)] [backdrop-filter:var(--hui-blur-lg)] opacity-[calc(1-var(--drawer-swipe-progress,0))] [transition:opacity_var(--hui-duration-drawer)_var(--hui-ease-drawer)] data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:[transition-duration:calc(var(--drawer-swipe-strength,1)*var(--hui-duration-drawer))] data-swiping:[transition-duration:0ms] [@media(prefers-reduced-transparency:reduce)]:bg-[var(--hui-color-overlay-black-a9)] [@media(prefers-reduced-transparency:reduce)]:[backdrop-filter:none]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nconst viewportClasses: Record<DrawerSide, string> = {\n  bottom: \"items-end justify-center\",\n  top: \"items-start justify-center\",\n  right: \"items-stretch justify-end\",\n  left: \"items-stretch justify-start\",\n}\n\nconst popupClasses: Record<DrawerSide, string> = {\n  // Snap points push a bottom drawer down by --drawer-snap-point-offset.\n  // Matching bottom padding keeps the end of the content reachable, and the\n  // ::after bleed fills the gap if the drawer is pulled past its height.\n  bottom: cn(\n    \"w-full max-h-[calc(100dvh-var(--hui-space-12))] rounded-t-[var(--hui-radius-4)] border-t-[0.5px]\",\n    \"[transform:translateY(calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px)))]\",\n    \"[padding-bottom:max(env(safe-area-inset-bottom,0px),calc(var(--drawer-snap-point-offset,0px)+var(--drawer-swipe-movement-y,0px)))] data-starting-style:[padding-bottom:0] data-ending-style:[padding-bottom:0]\",\n    \"after:pointer-events-none after:absolute after:inset-x-0 after:top-full after:h-[var(--hui-space-12)] after:bg-inherit after:content-['']\",\n    \"motion-safe:data-starting-style:[transform:translateY(100%)] motion-safe:data-ending-style:[transform:translateY(100%)]\"\n  ),\n  top: cn(\n    \"w-full max-h-[calc(100dvh-var(--hui-space-12))] rounded-b-[var(--hui-radius-4)] border-b-[0.5px] pt-[env(safe-area-inset-top,0px)]\",\n    \"[transform:translateY(var(--drawer-swipe-movement-y,0px))]\",\n    \"after:pointer-events-none after:absolute after:inset-x-0 after:bottom-full after:h-[var(--hui-space-12)] after:bg-inherit after:content-['']\",\n    \"motion-safe:data-starting-style:[transform:translateY(-100%)] motion-safe:data-ending-style:[transform:translateY(-100%)]\"\n  ),\n  right: cn(\n    \"h-full w-[calc(100%-(--spacing(12)))] max-w-sm border-s-[0.5px]\",\n    \"[transform:translateX(var(--drawer-swipe-movement-x,0px))]\",\n    \"motion-safe:data-starting-style:[transform:translateX(100%)] motion-safe:data-ending-style:[transform:translateX(100%)]\"\n  ),\n  left: cn(\n    \"h-full w-[calc(100%-(--spacing(12)))] max-w-sm border-e-[0.5px]\",\n    \"[transform:translateX(var(--drawer-swipe-movement-x,0px))]\",\n    \"motion-safe:data-starting-style:[transform:translateX(-100%)] motion-safe:data-ending-style:[transform:translateX(-100%)]\"\n  ),\n}\n\nfunction DrawerHandle({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      aria-hidden=\"true\"\n      data-slot=\"drawer-handle\"\n      className={cn(\n        \"mx-auto my-[var(--hui-space-3)] h-1 w-10 shrink-0 rounded-[var(--hui-radius-full)] bg-[var(--hui-color-border-base-secondary)] forced-colors:bg-[CanvasText]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction DrawerPopup({\n  className,\n  children,\n  showBackdrop = true,\n  showHandle,\n  showCloseButton,\n  ...props\n}: DrawerPrimitive.Popup.Props & {\n  showBackdrop?: boolean\n  /** Defaults to true for top and bottom drawers. */\n  showHandle?: boolean\n  /** Defaults to true for left and right drawers. */\n  showCloseButton?: boolean\n}) {\n  const side = React.useContext(DrawerSideContext)\n  const vertical = side === \"top\" || side === \"bottom\"\n  const handle = showHandle ?? vertical\n  const closeButton = showCloseButton ?? !vertical\n\n  return (\n    <DrawerPortal>\n      {showBackdrop && <DrawerBackdrop />}\n      <DrawerPrimitive.Viewport\n        data-slot=\"drawer-viewport\"\n        className={cn(\n          \"fixed inset-0 z-[var(--hui-z-index-portal)] flex\",\n          viewportClasses[side]\n        )}\n      >\n        <DrawerPrimitive.Popup\n          data-slot=\"drawer-popup\"\n          data-side={side}\n          data-close-button={closeButton ? \"\" : undefined}\n          className={cn(\n            \"relative flex min-h-0 flex-col border-[var(--hui-color-border-overlay)] bg-[var(--hui-color-background-overlay)] text-[var(--hui-color-foreground-base-primary)] shadow-[var(--hui-shadow-floating)] outline-none\",\n            // Drags follow the pointer with no easing; the release settles\n            // with the drawer curve, faster after a quick flick.\n            \"[transition:transform_var(--hui-duration-drawer)_var(--hui-ease-drawer),padding-bottom_var(--hui-duration-drawer)_var(--hui-ease-drawer),opacity_var(--hui-duration-drawer)_var(--hui-ease-drawer)] motion-safe:will-change-transform data-swiping:select-none data-swiping:[transition-duration:0ms] data-ending-style:[transition-duration:calc(var(--drawer-swipe-strength,1)*var(--hui-duration-drawer))]\",\n            // Reduced motion: no slide on open or close, only a short fade.\n            \"motion-reduce:[transition-duration:var(--hui-duration-fast)] motion-reduce:data-starting-style:opacity-0 motion-reduce:data-ending-style:opacity-0\",\n            \"forced-colors:border-[CanvasText]\",\n            popupClasses[side],\n            className\n          )}\n          {...props}\n        >\n          {handle && side === \"bottom\" && <DrawerHandle />}\n          {/* Content scrolls here. Text inside stays selectable with a mouse. */}\n          <DrawerPrimitive.Content\n            data-slot=\"drawer-content\"\n            className=\"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain touch-auto\"\n          >\n            {children}\n          </DrawerPrimitive.Content>\n          {handle && side === \"top\" && <DrawerHandle />}\n          {closeButton && (\n            <DrawerPrimitive.Close className=\"absolute end-[10px] top-[14px] z-2 inline-flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-[var(--hui-radius-2)] border border-transparent text-[var(--hui-color-foreground-base-secondary)] outline-none motion-safe:[transition:var(--hui-transition-interactive)] hover:bg-[var(--hui-color-background-overlay-hover)] hover:text-[var(--hui-color-foreground-base-primary)] focus-visible:[outline:var(--hui-focus-ring)] focus-visible:outline-offset-[var(--hui-focus-ring-offset-accent)] pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\">\n              <XIcon />\n              <span className=\"sr-only\">Close</span>\n            </DrawerPrimitive.Close>\n          )}\n        </DrawerPrimitive.Popup>\n      </DrawerPrimitive.Viewport>\n    </DrawerPortal>\n  )\n}\n\nfunction DrawerHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"drawer-header\"\n      className={cn(\n        \"flex flex-col gap-[var(--hui-space-2)] p-4 in-data-[side=bottom]:pt-1 in-data-[side=bottom]:text-center in-data-close-button:pe-11\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction DrawerFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"drawer-footer\"\n      className={cn(\n        \"sticky bottom-0 z-1 mt-auto flex flex-col gap-2 bg-[var(--hui-color-background-overlay)] p-4 *:w-full sm:flex-row sm:justify-end sm:*:w-auto in-data-[side=bottom]:sm:flex-col in-data-[side=bottom]:sm:*:w-full\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction DrawerTitle({ className, ...props }: DrawerPrimitive.Title.Props) {\n  return (\n    <DrawerPrimitive.Title\n      data-slot=\"drawer-title\"\n      className={cn(\n        \"m-0 text-[var(--hui-color-foreground-base-primary)] [font-size:var(--hui-font-size-large)] [font-weight:var(--hui-font-weight-medium)] [letter-spacing:var(--hui-letter-spacing-large)] [line-height:var(--hui-line-height-large)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction DrawerDescription({\n  className,\n  ...props\n}: DrawerPrimitive.Description.Props) {\n  return (\n    <DrawerPrimitive.Description\n      data-slot=\"drawer-description\"\n      className={cn(\n        \"[font-size:var(--hui-font-size-control,13px)] [line-height:var(--hui-line-height-regular)] text-[var(--hui-color-foreground-base-secondary)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nexport {\n  Drawer,\n  DrawerTrigger,\n  DrawerPortal,\n  DrawerClose,\n  DrawerBackdrop,\n  DrawerBackdrop as DrawerOverlay,\n  DrawerPopup,\n  DrawerPopup as DrawerContent,\n  DrawerHandle,\n  DrawerHeader,\n  DrawerFooter,\n  DrawerTitle,\n  DrawerDescription,\n}\nexport type { DrawerSide }\n","target":"components/ui/drawer.tsx"}],"dependencies":["@base-ui/react","honestui"]}