{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-sidebar",
  "title": "App sidebar",
  "description": "A frosted app rail: logo and name, labelled sections of nav rows with count pills, a slot for a checklist, a footer with a theme switch, and the account menu. It collapses to icons with tooltips on desktop and becomes a focus-trapping drawer on a phone.",
  "dependencies": [
    "radix-ui",
    "motion",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://bash-ui-registry.vercel.app/r/account-menu.json"
  ],
  "files": [
    {
      "path": "registry/items/app-sidebar/app-sidebar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Tooltip as TooltipPrimitive } from \"radix-ui\";\nimport { AnimatePresence, motion, useReducedMotionConfig } from \"motion/react\";\nimport { Menu, Moon, PanelLeftClose, PanelLeftOpen, Sun, X } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n  AccountMenu,\n  GestureGlyph,\n  type AccountMenuProps,\n  type GlyphComponent,\n  readThemeScope,\n  type IconGesture,\n  type ThemeScope,\n} from \"@/components/account-menu\";\n\n/* ─── Types ────────────────────────────────────────────────────────────── */\n\nexport type SidebarNavItem = {\n  href: string;\n  label: string;\n  /** Any lucide-react icon, or a component with the same props. */\n  icon: GlyphComponent;\n  /** How the icon moves when the row is hovered. Defaults to \"pop\". */\n  gesture?: IconGesture;\n  /**\n   * Outstanding-work count, as a pill beside the label (a dot on the icon when\n   * collapsed). Zero or less shows nothing: an empty pill is noise.\n   */\n  count?: number;\n  /** Read aloud with the count. Defaults to \"<n> outstanding\". */\n  countLabel?: string;\n  /** Selects the row. Without it, the row is selected when `currentPath` is its href or one of `matches`. */\n  active?: boolean;\n  /** Other paths that select this row: a grouped entry's sibling tabs. */\n  matches?: readonly string[];\n};\n\nexport type SidebarSection = {\n  /** A small capitals heading. Hidden while collapsed. */\n  label?: string;\n  items: SidebarNavItem[];\n};\n\n/** What a nav row hands its link: spread it onto `<a>` or a router's link. */\nexport type SidebarLinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {\n  href: string;\n  ref?: React.Ref<HTMLAnchorElement>;\n};\n\n/** The sidebar's state, for slots that need to fit themselves to it. */\nexport type SidebarSlotState = { collapsed: boolean; mobileOpen: boolean };\n\ntype Slot = React.ReactNode | ((state: SidebarSlotState) => React.ReactNode);\n\nexport interface AppSidebarProps {\n  sections: SidebarSection[];\n  /** The path on screen, for working out which row is selected. Ignored by rows that set `active`. */\n  currentPath?: string;\n  /** The 32px mark at the top. When collapsed it doubles as the expand button. */\n  logo?: React.ReactNode;\n  /** The product name beside the logo. Hidden while collapsed. */\n  title?: React.ReactNode;\n  /** The account block at the foot. Omit for no account menu. */\n  account?: Omit<AccountMenuProps, \"collapsed\">;\n  /** Rows above the account menu: a theme switch, a notification bell. */\n  footer?: Slot;\n  /** Between the nav and the footer: an onboarding checklist, a promo card. */\n  children?: Slot;\n  /** Icon-only rail, at `md` and up. Controlled when set. */\n  collapsed?: boolean;\n  /** Starting state when uncontrolled. */\n  defaultCollapsed?: boolean;\n  /** Called with the new state; persist it here (localStorage, a cookie). */\n  onCollapsedChange?: (collapsed: boolean) => void;\n  /** Below `md` the rail is a drawer. Pair with `useSidebarDrawer`. */\n  mobileOpen?: boolean;\n  onMobileClose?: () => void;\n  /** Called when a nav row is followed. The drawer closes on its own. */\n  onNavigate?: (item: SidebarNavItem) => void;\n  /**\n   * Renders each nav link. Defaults to `<a>`. Pass a router's link to keep\n   * navigation client-side: `renderLink={(props) => <Link {...props} />}`.\n   */\n  renderLink?: (props: SidebarLinkProps) => React.ReactNode;\n  /** The drawer's element id; `useSidebarDrawer().drawerId` when paired with it. */\n  id?: string;\n  /**\n   * The brand-green wash the frosted rail blurs. \"fixed\" (default) pins it to\n   * the viewport's left edge, as in an app shell; \"absolute\" pins it to the\n   * nearest positioned ancestor, for a sidebar inside a frame; false for none.\n   * Either way it sits at z -10, so the container needs `isolate` (or another\n   * stacking context) for the page's content to paint above it.\n   */\n  wash?: \"fixed\" | \"absolute\" | false;\n  className?: string;\n}\n\n/**\n * What the sidebar's frosted glass actually blurs: brand green, pooled at the\n * top-left where the navigation sits and lifted again along the bottom under\n * the account block, so the rail is brightest exactly where it is busiest.\n *\n * The lower layer is linear, not a second ellipse: an ellipse's edge stays\n * legible through a 40px blur at this scale. The mask retires the wash's own\n * right edge, so no boundary shows however wide the rail is collapsed to.\n */\nexport function SidebarWash({ position = \"fixed\", className }: { position?: \"fixed\" | \"absolute\"; className?: string }) {\n  // A mask, not paint: alpha stops that name no colour.\n  const fadeOutRight = \"linear-gradient(to right, black 55%, transparent 100%)\";\n  return (\n    <div\n      aria-hidden=\"true\"\n      className={cn(\"pointer-events-none inset-y-0 left-0 -z-10 w-[420px] max-w-full\", position, className)}\n      style={{\n        background: [\n          \"radial-gradient(85% 55% at 0% 0%, color-mix(in srgb, var(--brand) 45%, transparent), transparent 72%)\",\n          \"linear-gradient(to bottom, transparent 22%, color-mix(in srgb, var(--brand) 26%, transparent) 100%)\",\n        ].join(\", \"),\n        WebkitMaskImage: fadeOutRight,\n        maskImage: fadeOutRight,\n      }}\n    />\n  );\n}\n\n/* ─── Sidebar ──────────────────────────────────────────────────────────── */\n\nconst DEFAULT_LINK = (props: SidebarLinkProps) => <a {...props} />;\n\n/**\n * A frosted app rail: logo and name, sections of nav rows with counts, an\n * optional slot, a footer, and the account menu. It collapses to icons at\n * `md` and up (tooltips name each row), and below `md` it leaves the flow and\n * slides in as a drawer.\n *\n * The consumer decides what each person sees: pass only the rows they can\n * open. Hovering anywhere on a row plays its icon's gesture, so the whole\n * target responds, not just the 20px glyph.\n */\nexport function AppSidebar({\n  sections,\n  currentPath,\n  logo,\n  title,\n  account,\n  footer,\n  children,\n  collapsed: collapsedProp,\n  defaultCollapsed = false,\n  onCollapsedChange,\n  mobileOpen = false,\n  onMobileClose,\n  onNavigate,\n  renderLink = DEFAULT_LINK,\n  id,\n  wash = \"fixed\",\n  className,\n}: AppSidebarProps) {\n  const [uncontrolled, setUncontrolled] = React.useState(defaultCollapsed);\n  const collapsed = collapsedProp ?? uncontrolled;\n  const [logoHover, setLogoHover] = React.useState(false);\n  const [closeHover, setCloseHover] = React.useState(false);\n  const asideRef = React.useRef<HTMLElement>(null);\n\n  function setCollapsed(next: boolean) {\n    if (collapsedProp === undefined) setUncontrolled(next);\n    onCollapsedChange?.(next);\n  }\n\n  const state: SidebarSlotState = { collapsed, mobileOpen };\n  const fill = (slot: Slot) => (typeof slot === \"function\" ? slot(state) : slot);\n  const slot = fill(children);\n  const footerSlot = fill(footer);\n\n  return (\n    <>\n    {wash ? <SidebarWash position={wash} /> : null}\n    <aside\n      ref={asideRef}\n      id={id}\n      className={cn(\n        // Below `md`: a drawer. Closed, it is `invisible` as well as\n        // off-screen, so its links leave the tab order and the reading order;\n        // `visibility` flips at the end of the slide, so the slide still shows.\n        \"fixed inset-y-0 left-0 z-50 transition-[translate,visibility] duration-200\",\n        mobileOpen ? \"visible translate-x-0\" : \"invisible -translate-x-full\",\n        \"md:visible md:sticky md:top-0 md:translate-x-0 md:transition-[width]\",\n        \"flex h-dvh w-64 shrink-0 flex-col bg-card/55 font-body backdrop-blur-2xl backdrop-saturate-150\",\n        \"pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] pl-[env(safe-area-inset-left)] md:pt-0 md:pb-0\",\n        // The right edge: a hairline that fades in from the card at each end.\n        \"after:pointer-events-none after:absolute after:inset-y-0 after:right-0 after:w-px after:bg-linear-to-b after:from-card/90 after:via-ink/12 after:to-card/50\",\n        collapsed ? \"md:w-16\" : \"md:w-64\",\n        className,\n      )}\n    >\n      {/*\n       * One logo button, the same size and node whether collapsed or not, so\n       * it reads as one mark rather than two crossfading. The row is pinned\n       * to its 36px, so the nav below does not shift when the collapse button\n       * on its right comes and goes.\n       */}\n      <div className=\"flex h-[68px] shrink-0 items-center justify-between gap-2.5 px-3.5 py-4\">\n        <button\n          type=\"button\"\n          onClick={() => collapsed && setCollapsed(false)}\n          onPointerEnter={() => setLogoHover(true)}\n          onPointerLeave={() => setLogoHover(false)}\n          aria-label={collapsed ? \"Expand sidebar\" : undefined}\n          aria-hidden={collapsed ? undefined : true}\n          tabIndex={collapsed ? 0 : -1}\n          className={cn(\n            \"group relative flex size-9 shrink-0 items-center justify-center rounded-xl transition-all focus-visible:ring-2 focus-visible:ring-lead/30 focus-visible:outline-none\",\n            collapsed ? \"hover:bg-ink/10\" : \"cursor-default\",\n          )}\n        >\n          <span\n            className={cn(\n              \"flex size-8 items-center justify-center transition-opacity duration-200 [&>img]:size-8 [&>img]:object-contain [&>svg]:size-8\",\n              collapsed && \"md:group-hover:opacity-0\",\n            )}\n          >\n            {logo}\n          </span>\n          {collapsed && (\n            <span className=\"absolute inset-0 hidden items-center justify-center text-ink opacity-0 transition-opacity duration-200 group-hover:opacity-100 md:flex\">\n              <GestureGlyph\n                icon={PanelLeftOpen}\n                gesture=\"nudge\"\n                active={logoHover}\n                className=\"size-5\"\n                strokeWidth={1.8}\n              />\n            </span>\n          )}\n        </button>\n\n        <span\n          className={cn(\n            \"min-w-0 flex-1 truncate font-heading text-base font-extrabold tracking-tight text-ink transition-opacity duration-150\",\n            collapsed && \"md:hidden\",\n          )}\n        >\n          {title}\n        </span>\n\n        {!collapsed && (\n          <button\n            type=\"button\"\n            onClick={() => setCollapsed(true)}\n            onPointerEnter={() => setCloseHover(true)}\n            onPointerLeave={() => setCloseHover(false)}\n            aria-label=\"Collapse sidebar\"\n            className=\"ml-auto hidden shrink-0 rounded-xl p-1.5 text-dim transition-all hover:bg-ink/10 hover:text-ink focus-visible:ring-2 focus-visible:ring-lead/30 focus-visible:outline-none md:inline-flex\"\n          >\n            <GestureGlyph\n              icon={PanelLeftClose}\n              gesture=\"nudge-back\"\n              active={closeHover}\n              className=\"size-5\"\n              strokeWidth={1.8}\n            />\n          </button>\n        )}\n\n        <button\n          type=\"button\"\n          onClick={onMobileClose}\n          aria-label=\"Close navigation\"\n          className=\"relative ml-auto shrink-0 rounded-xl p-1.5 text-dim transition-all after:absolute after:top-1/2 after:left-1/2 after:size-11 after:-translate-x-1/2 after:-translate-y-1/2 after:content-[''] hover:bg-ink/10 hover:text-ink focus-visible:ring-2 focus-visible:ring-lead/30 focus-visible:outline-none md:hidden\"\n        >\n          <X className=\"size-5\" strokeWidth={1.8} aria-hidden=\"true\" />\n        </button>\n      </div>\n\n      <TooltipPrimitive.Provider delayDuration={400}>\n        <nav\n          aria-label=\"Primary\"\n          className=\"flex-1 space-y-6 overflow-x-hidden overflow-y-auto px-2 py-2\"\n        >\n          {sections.map((section, index) => (\n            <div key={section.label ?? index}>\n              {section.label && (\n                <p\n                  className={cn(\n                    \"px-3 pb-1 text-xs font-bold tracking-wide text-faint uppercase\",\n                    collapsed && \"md:hidden\",\n                  )}\n                >\n                  {section.label}\n                </p>\n              )}\n              <ul className=\"space-y-1\">\n                {section.items.map((item) => (\n                  <li key={item.href}>\n                    <NavRow\n                      item={item}\n                      active={\n                        item.active ??\n                        (currentPath !== undefined &&\n                          (currentPath === item.href ||\n                            Boolean(item.matches?.includes(currentPath))))\n                      }\n                      collapsed={collapsed}\n                      renderLink={renderLink}\n                      themeFrom={asideRef}\n                      onFollow={() => {\n                        onNavigate?.(item);\n                        onMobileClose?.();\n                      }}\n                    />\n                  </li>\n                ))}\n              </ul>\n            </div>\n          ))}\n        </nav>\n      </TooltipPrimitive.Provider>\n\n      {slot != null && slot !== false && <div className=\"px-2 pb-2\">{slot}</div>}\n\n      {(footerSlot != null && footerSlot !== false) || account ? (\n        <div className=\"space-y-1 border-t border-card/70 p-2\">\n          {footerSlot}\n          {account && <AccountMenu {...account} collapsed={collapsed} />}\n        </div>\n      ) : null}\n    </aside>\n    </>\n  );\n}\n\n/* ─── A nav row ────────────────────────────────────────────────────────── */\n\nfunction NavRow({\n  item,\n  active,\n  collapsed,\n  renderLink,\n  themeFrom,\n  onFollow,\n}: {\n  item: SidebarNavItem;\n  active: boolean;\n  collapsed: boolean;\n  renderLink: (props: SidebarLinkProps) => React.ReactNode;\n  themeFrom: React.RefObject<HTMLElement | null>;\n  onFollow: () => void;\n}) {\n  const reduceMotion = useReducedMotionConfig();\n  const [hovered, setHovered] = React.useState(false);\n  const [tooltipOpen, setTooltipOpen] = React.useState(false);\n  // The tooltip is portalled to <body>; carry the trigger's theme scope.\n  const [scope, setScope] = React.useState<ThemeScope>({ dark: false });\n\n  const count = item.count ?? 0;\n  const showCount = count > 0;\n  const countText = count > 99 ? \"99+\" : String(count);\n  const countLabel = item.countLabel ?? `${count} outstanding`;\n\n  const link = renderLink({\n    href: item.href,\n    \"aria-current\": active ? \"page\" : undefined,\n    onPointerEnter: () => setHovered(true),\n    onPointerLeave: () => setHovered(false),\n    onClick: onFollow,\n    className: cn(\n      \"relative flex items-center gap-3 rounded-xl px-3.5 py-2.5 text-sm text-ink transition-all hover:bg-ink/10 focus-visible:ring-2 focus-visible:ring-lead/30 focus-visible:outline-none\",\n      active ? \"bg-ink/12 font-bold text-ink\" : \"font-semibold text-ink/85 hover:text-ink\",\n    ),\n    children: (\n      <>\n        <GestureGlyph\n          icon={item.icon}\n          gesture={item.gesture ?? \"pop\"}\n          active={hovered}\n          className=\"size-5\"\n          strokeWidth={1.75}\n        />\n        <span className={cn(\"min-w-0 flex-1 truncate\", collapsed && \"md:hidden\")}>\n          {item.label}\n        </span>\n        {showCount && (\n          <span\n            aria-label={countLabel}\n            className={cn(\n              \"shrink-0 rounded-full bg-lead px-2 py-0.5 text-[12px] font-bold text-on-solid tabular-nums\",\n              collapsed && \"md:hidden\",\n            )}\n          >\n            {countText}\n          </span>\n        )}\n        {showCount && collapsed && (\n          <span\n            aria-label={countLabel}\n            className=\"absolute top-1 right-1 hidden h-4 min-w-4 items-center justify-center rounded-full bg-lead px-1 text-[10px] font-bold text-on-solid tabular-nums md:flex\"\n          >\n            {countText}\n          </span>\n        )}\n      </>\n    ),\n  });\n\n  if (!collapsed) return link;\n\n  return (\n    <TooltipPrimitive.Root\n      open={tooltipOpen}\n      onOpenChange={(next) => {\n        if (next) {\n          setScope(readThemeScope(themeFrom.current));\n        }\n        setTooltipOpen(next);\n      }}\n    >\n      <TooltipPrimitive.Trigger {...{ asChild: true }}>{link}</TooltipPrimitive.Trigger>\n      <AnimatePresence>\n        {tooltipOpen && (\n          <TooltipPrimitive.Portal forceMount>\n            <TooltipPrimitive.Content {...{ asChild: true }} forceMount side=\"right\" sideOffset={10} collisionPadding={12}>\n              <motion.div\n                data-theme={scope.theme}\n                initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n                animate={{ opacity: 1, scale: 1 }}\n                exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.5 }}\n                transition={\n                  reduceMotion ? { duration: 0.1 } : { type: \"spring\", stiffness: 300, damping: 25 }\n                }\n                className={cn(\n                  scope.dark && \"dark\",\n                  \"z-50 origin-(--radix-tooltip-content-transform-origin) rounded-xl bg-ink px-3.5 py-2 font-body text-sm font-semibold text-on-solid shadow-lg\",\n                )}\n              >\n                {item.label}\n              </motion.div>\n            </TooltipPrimitive.Content>\n          </TooltipPrimitive.Portal>\n        )}\n      </AnimatePresence>\n    </TooltipPrimitive.Root>\n  );\n}\n\n/* ─── Theme switch ─────────────────────────────────────────────────────── */\n\nconst TAP_TARGET =\n  \"pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:top-1/2 pointer-coarse:after:left-1/2 pointer-coarse:after:size-[max(100%,44px)] pointer-coarse:after:-translate-x-1/2 pointer-coarse:after:-translate-y-1/2 pointer-coarse:after:content-['']\";\n\n/**\n * Light or dark, for the sidebar's footer: a bare word and a two-button pill,\n * or a single sun/moon button when the rail is collapsed. It shows and sets a\n * value; the consumer owns where the theme lives (next-themes, a cookie).\n */\nexport function SidebarThemeSwitch({\n  dark,\n  onDarkChange,\n  collapsed = false,\n  showLabel = true,\n  className,\n}: {\n  dark: boolean;\n  onDarkChange: (dark: boolean) => void;\n  /** Pass the sidebar's `collapsed` (from a slot function) to shrink to one button. */\n  collapsed?: boolean;\n  /** The \"Light\" / \"Dark\" word beside the pill. */\n  showLabel?: boolean;\n  className?: string;\n}) {\n  const label = dark ? \"Switch to light\" : \"Switch to dark\";\n\n  return (\n    <>\n      {collapsed && (\n        <button\n          type=\"button\"\n          onClick={() => onDarkChange(!dark)}\n          title={label}\n          aria-label={label}\n          className={cn(\n            \"mx-auto hidden size-9 items-center justify-center rounded-xl text-dim transition-all hover:bg-ink/10 hover:text-ink focus-visible:ring-2 focus-visible:ring-lead/30 focus-visible:outline-none md:flex\",\n            className,\n          )}\n        >\n          {dark ? (\n            <Sun className=\"size-4\" strokeWidth={1.8} aria-hidden=\"true\" />\n          ) : (\n            <Moon className=\"size-4\" strokeWidth={1.8} aria-hidden=\"true\" />\n          )}\n        </button>\n      )}\n      {/* Collapsed is a desktop-only state: below `md` the full switch shows. */}\n      <div\n        className={cn(\n          \"flex items-center gap-2 rounded-xl\",\n          showLabel && \"px-2.5 py-1.5\",\n          collapsed && \"md:hidden\",\n          className,\n        )}\n      >\n        {showLabel && (\n          <span className=\"min-w-0 flex-1 truncate text-[12.5px] font-semibold text-dim\">\n            {dark ? \"Dark\" : \"Light\"}\n          </span>\n        )}\n        <div\n          role=\"group\"\n          aria-label=\"Theme\"\n          className=\"flex shrink-0 items-center gap-0.5 rounded-full border border-rule bg-card/60 p-0.5\"\n        >\n          <button\n            type=\"button\"\n            onClick={() => onDarkChange(false)}\n            aria-pressed={!dark}\n            title=\"Light\"\n            className={cn(\n              \"flex size-6 items-center justify-center rounded-full transition-colors\",\n              TAP_TARGET,\n              dark ? \"text-faint hover:text-ink\" : \"bg-ink text-on-solid\",\n            )}\n          >\n            <Sun className=\"size-3.5\" strokeWidth={2} aria-hidden=\"true\" />\n            <span className=\"sr-only\">Light</span>\n          </button>\n          <button\n            type=\"button\"\n            onClick={() => onDarkChange(true)}\n            aria-pressed={dark}\n            title=\"Dark\"\n            className={cn(\n              \"flex size-6 items-center justify-center rounded-full transition-colors\",\n              TAP_TARGET,\n              dark ? \"bg-ink text-on-solid\" : \"text-faint hover:text-ink\",\n            )}\n          >\n            <Moon className=\"size-3.5\" strokeWidth={2} aria-hidden=\"true\" />\n            <span className=\"sr-only\">Dark</span>\n          </button>\n        </div>\n      </div>\n    </>\n  );\n}\n\n/* ─── The phone half ───────────────────────────────────────────────────── */\n\nconst FOCUSABLE =\n  'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nconst SCRIM_ATTRIBUTE = \"data-sidebar-scrim\";\n\n/**\n * Open and close for the drawer, with the modal manners a keyboard needs:\n * focus moves to the drawer's first control, everything else on the page goes\n * `inert` so Tab cannot wander under the scrim, Escape closes, the page stops\n * scrolling behind it, and closing hands focus back to the burger. Widening\n * past `md` closes it, so nothing is left inert behind a drawer nobody sees.\n *\n * Close it on navigation too: call `setOpen(false)` when your route changes\n * (the sidebar already closes it when one of its own rows is followed).\n */\nexport function useSidebarDrawer() {\n  const [open, setOpen] = React.useState(false);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const drawerId = React.useId();\n\n  React.useEffect(() => {\n    if (!open) return;\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (event.key === \"Escape\") setOpen(false);\n    };\n    document.addEventListener(\"keydown\", onKeyDown);\n    const previousOverflow = document.body.style.overflow;\n    document.body.style.overflow = \"hidden\";\n\n    const desktop = window.matchMedia(\"(min-width: 768px)\");\n    const onWiden = () => {\n      if (desktop.matches) setOpen(false);\n    };\n    desktop.addEventListener(\"change\", onWiden);\n\n    const trigger = triggerRef.current;\n    const drawer = document.getElementById(drawerId);\n    const release = drawer ? inertOutside(drawer) : () => {};\n    drawer?.querySelector<HTMLElement>(FOCUSABLE)?.focus();\n\n    return () => {\n      document.removeEventListener(\"keydown\", onKeyDown);\n      desktop.removeEventListener(\"change\", onWiden);\n      document.body.style.overflow = previousOverflow;\n      release();\n      const active = document.activeElement;\n      const focusWasInDrawer =\n        active === document.body || (drawer !== null && drawer.contains(active));\n      if (focusWasInDrawer) trigger?.focus();\n    };\n  }, [open, drawerId]);\n\n  return { open, setOpen, triggerRef, drawerId };\n}\n\n/**\n * Marks everything except `drawer` (and the scrim) inert, walking from the\n * drawer up to `<body>` so skip links, notices and portals beside the shell\n * are caught too, and keeps marking anything added while it is open. Returns a\n * function that undoes exactly what it did.\n */\nfunction inertOutside(drawer: HTMLElement): () => void {\n  const changed: HTMLElement[] = [];\n  const path = new Set<Element>();\n  const levels: HTMLElement[] = [];\n  for (\n    let node: HTMLElement = drawer;\n    node.parentElement && node !== document.body;\n    node = node.parentElement\n  ) {\n    path.add(node);\n    levels.push(node.parentElement);\n  }\n\n  const mark = (element: Element) => {\n    if (path.has(element) || !(element instanceof HTMLElement)) return;\n    if (element.hasAttribute(SCRIM_ATTRIBUTE) || element.hasAttribute(\"inert\")) return;\n    element.setAttribute(\"inert\", \"\");\n    changed.push(element);\n  };\n\n  for (const level of levels) for (const child of Array.from(level.children)) mark(child);\n\n  const observer = new MutationObserver((records) => {\n    for (const record of records)\n      for (const node of Array.from(record.addedNodes)) {\n        if (node instanceof Element) mark(node);\n      }\n  });\n  for (const level of levels) observer.observe(level, { childList: true });\n\n  return () => {\n    observer.disconnect();\n    for (const element of changed) element.removeAttribute(\"inert\");\n  };\n}\n\n/** The dimmed page behind the open drawer. Tapping it closes the drawer. Phones only. */\nexport function SidebarScrim({\n  open,\n  onClose,\n  className,\n}: {\n  open: boolean;\n  onClose: () => void;\n  className?: string;\n}) {\n  if (!open) return null;\n  return (\n    <div\n      aria-hidden=\"true\"\n      {...{ [SCRIM_ATTRIBUTE]: \"\" }}\n      onClick={onClose}\n      // Between the page's own top layer and the drawer's z-50.\n      className={cn(\"fixed inset-0 z-[45] bg-ground/70 backdrop-blur-[2px] md:hidden\", className)}\n    />\n  );\n}\n\n/**\n * The bar that stands in for the rail on a phone: a burger, and room for a\n * title. It clears the notch in portrait and the rounded corners in landscape.\n */\nexport function SidebarMobileBar({\n  open,\n  onOpen,\n  triggerRef,\n  drawerId,\n  label = \"Open navigation\",\n  children,\n  className,\n}: {\n  open: boolean;\n  onOpen: () => void;\n  /** `useSidebarDrawer().triggerRef`, so closing the drawer hands focus back here. */\n  triggerRef?: React.Ref<HTMLButtonElement>;\n  /** `useSidebarDrawer().drawerId`: the element the burger controls. */\n  drawerId?: string;\n  label?: string;\n  children?: React.ReactNode;\n  className?: string;\n}) {\n  return (\n    <div\n      className={cn(\n        \"sticky top-0 z-[44] flex shrink-0 items-center gap-2 border-b border-rule bg-card/80 pt-[env(safe-area-inset-top)] pr-[max(1rem,env(safe-area-inset-right))] pl-[max(0.5rem,env(safe-area-inset-left))] font-body backdrop-blur-xl md:hidden\",\n        className,\n      )}\n    >\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        onClick={onOpen}\n        aria-label={label}\n        aria-expanded={open}\n        aria-controls={drawerId}\n        className=\"flex size-11 shrink-0 items-center justify-center rounded-xl text-dim transition-all hover:bg-paper hover:text-ink focus-visible:ring-2 focus-visible:ring-lead/30 focus-visible:outline-none\"\n      >\n        <Menu className=\"size-5\" strokeWidth={1.8} aria-hidden=\"true\" />\n      </button>\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:block"
    }
  ],
  "meta": {
    "kind": "pattern",
    "whenToUse": "Use as the persistent primary navigation of a signed-in app with five to fifteen destinations. Do not use for a marketing site's header, for in-page section tabs, or for settings sub-navigation inside a page.",
    "origin": {
      "project": "180Connect",
      "path": "src/components/sidebar.tsx"
    },
    "credits": [
      {
        "name": "Animate UI (Radix Tooltip, animated icons)",
        "url": "https://animate-ui.com",
        "license": "MIT"
      },
      {
        "name": "AnimateIcons (row-hover icon animation)",
        "url": "https://animateicons.in",
        "license": "MIT"
      }
    ]
  },
  "type": "registry:block"
}
