{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar",
  "title": "Sidebar",
  "description": "An app's navigation beside its page, built from the Tree's rows: one highlight glides with the pointer and focus, and the current page's tint glides to the next. Collapsed, it narrows to its icons, named by tooltips, or slides out of sight and peeks back from the screen's edge. On a phone it is a Drawer.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/cut.json",
    "https://kinoui.com/r/swap.json",
    "https://kinoui.com/r/badge.json",
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/collapsible.json",
    "https://kinoui.com/r/kbd.json",
    "https://kinoui.com/r/scroll-area.json",
    "https://kinoui.com/r/drawer.json",
    "https://kinoui.com/r/tooltip.json",
    "https://kinoui.com/r/dock.json",
    "https://kinoui.com/r/controllable.json",
    "https://kinoui.com/r/glide.json",
    "https://kinoui.com/r/highlight.json",
    "https://kinoui.com/r/popup.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/sidebar.tsx",
      "content": "'use client'\n\nimport { Badge } from '@/registry/components/kino/badge'\nimport { Button } from '@/registry/components/kino/button'\nimport {\n  CollapsibleIndicator,\n  collapsibleNestedClassName,\n  collapsibleRowClassName,\n} from '@/registry/components/kino/collapsible'\nimport { Drawer, DrawerContent, DrawerTitle } from '@/registry/components/kino/drawer'\nimport { KbdGroup } from '@/registry/components/kino/kbd'\nimport { ScrollArea } from '@/registry/components/kino/scroll-area'\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipGroup,\n  TooltipShortcut,\n  TooltipTrigger,\n} from '@/registry/components/kino/tooltip'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { useControllable } from '@/registry/lib/controllable'\nimport { CutLines, CutTooltip, undescribed, useCut } from '@/registry/lib/cut'\nimport {\n  type Dock,\n  dockBoxClassName,\n  dockGapClassName,\n  dockPanelClassName,\n  type DockSide,\n  dockTrigger,\n  useDock,\n  useDockTrigger,\n} from '@/registry/lib/dock'\nimport { GLIDE_GROUP_CLOSE_DELAY } from '@/registry/lib/glide'\nimport {\n  followPick,\n  followPointer,\n  itemMatching,\n  pickClassName,\n  rowHighlightClassName,\n  rowTintClassName,\n} from '@/registry/lib/highlight'\nimport { HOVER_DELAY } from '@/registry/lib/popup'\nimport { mergeRefs } from '@/registry/lib/refs'\nimport { collapseClassName, transitionsSettled } from '@/registry/lib/resize'\nimport { SwapTextTitleContext } from '@/registry/lib/swap'\nimport { shortcuts } from '@ui-sdk/core/shortcuts'\nimport { Button as ButtonPrimitive } from '@ui-sdk/react/button'\nimport {\n  CollapsiblePanel as CollapsiblePanelPrimitive,\n  Collapsible as CollapsiblePrimitive,\n  CollapsibleTrigger as CollapsibleTriggerPrimitive,\n} from '@ui-sdk/react/collapsible'\nimport { mergeProps, type PartProps, renderElement } from '@ui-sdk/react/primitive'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport {\n  type ComponentProps,\n  createContext,\n  type MouseEvent,\n  type PointerEvent as ReactPointerEvent,\n  type ReactElement,\n  type ReactNode,\n  type RefObject,\n  use,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A sidebar beside the page. Its rows are the Tree's, under one highlight\n * that glides with the pointer and focus, and the current page is a tint\n * that glides to the next page as you go there. Each row keeps the\n * sidebar's whole width inside it, so a sidebar that narrows covers its\n * labels in place and nothing in a row moves. On a phone, it is a Drawer.\n */\n\ntype SidebarSide = DockSide\n\n/** Toggles the sidebar from anywhere on the page. */\nconst SIDEBAR_SHORTCUT = 'mod+b'\n\nconst SidebarContext = createContext<Dock | null>(null)\n\nfunction useSidebar() {\n  const context = use(SidebarContext)\n  if (!context) throw new Error('useSidebar goes inside a SidebarProvider.')\n  return context\n}\n\n/**\n * How the panel that holds the parts shows them: `collapsed` as an icon\n * rail, and `rail` once its edge has reached the rail's width.\n */\nconst SurfaceContext = createContext({ collapsed: false, rail: false })\n\n/**\n * Holds whether the sidebar is open, and lays it out beside the page:\n * `SidebarInset` holds the page and scrolls. It is as tall as the screen\n * unless `className` says otherwise. Under 48rem wide, the sidebar is a Drawer.\n */\nfunction SidebarProvider({\n  open: openProp,\n  defaultOpen = true,\n  onOpenChange,\n  shortcut = SIDEBAR_SHORTCUT,\n  className,\n  children,\n  ref,\n  ...props\n}: ComponentProps<'div'> & {\n  /** Whether the sidebar is docked open, when you hold the state. */\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** The keys that toggle it from anywhere on the page, as ui-sdk writes them (`'mod+b'`), or null for none. */\n  shortcut?: string | null\n}) {\n  const [box, setBox] = useState<HTMLDivElement | null>(null)\n  const dock = useDock({ open: openProp, defaultOpen, onOpenChange, shortcut, box })\n  const boxRef = useMemo(() => mergeRefs(setBox, ref), [ref])\n\n  return (\n    <SidebarContext value={dock}>\n      <div\n        ref={boxRef}\n        data-slot='sidebar-provider'\n        data-state={dock.open ? 'expanded' : 'collapsed'}\n        className={cn(\n          dockBoxClassName,\n          // Named for the parts a page lays out beside the sidebar too.\n          'h-dvh w-full [container-name:dock_sidebar-provider]',\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </div>\n    </SidebarContext>\n  )\n}\n\n/**\n * The page beside the sidebar, the page's `main` landmark unless `render`\n * gives another element. It scrolls on its own, so the sidebar stays put.\n */\nfunction SidebarInset({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'main'>, 'className'> & {\n  className?: string\n}) {\n  return renderElement(\n    'main',\n    mergeProps(\n      {\n        'data-slot': 'sidebar-inset',\n        className: cn(\n          'bg-background scrollbar-thin relative flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto',\n          className,\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\n/** A row's inline padding, which centres a 1rem icon in a square as tall as the row. */\nconst rowPadding = 'px-[calc((var(--control-height)-1rem)/2)]'\n\n/**\n * The sidebar's rows, header and footer leave this much room at its edges;\n * an icon rail is a row's height and this either side.\n */\nconst sidebarGutter = 'px-(--control-padding)'\n\n/**\n * The panel that holds the parts: the sidebar's landmark, named by its\n * `aria-label`. `collapsed` shows it as an icon rail, its rows named by\n * their tooltips.\n */\nfunction SidebarSurface({\n  collapsed,\n  rail = false,\n  className,\n  children,\n  ref,\n  ...props\n}: ComponentProps<'nav'> & { collapsed: boolean; rail?: boolean }) {\n  const navRef = useRef<HTMLElement>(null)\n  const surfaceRef = useMemo(() => mergeRefs(navRef, ref), [ref])\n\n  // What hides in the rail can't keep focus: it goes to the row it belongs to.\n  useEffect(() => {\n    const nav = navRef.current\n    const active = document.activeElement\n    if (!collapsed || !nav || !(active instanceof HTMLElement) || !nav.contains(active))\n      return\n    const row = railHome(active)\n    if (row && row !== active) row.focus({ preventScroll: true })\n  }, [collapsed])\n\n  return (\n    <SurfaceContext value={{ collapsed, rail }}>\n      <nav\n        ref={surfaceRef}\n        data-slot='sidebar-surface'\n        data-state={collapsed ? 'collapsed' : 'expanded'}\n        className={cn(\n          'group/sidebar text-sidebar-foreground flex h-full min-h-0 w-full min-w-0 flex-col',\n          className,\n        )}\n        {...props}\n      >\n        {/* The rail's tooltips are one, which slides from row to row. */}\n        <TooltipGroup>{children}</TooltipGroup>\n      </nav>\n    </SurfaceContext>\n  )\n}\n\n/** Where focus on `element` goes once the sidebar is a rail: the row that stays, or itself. */\nfunction railHome(element: HTMLElement): HTMLElement | null {\n  const sub = element.closest('[data-sidebar-menu-sub]')\n  if (sub) {\n    return (\n      sub.parentElement?.querySelector<HTMLElement>(\n        ':scope > [data-sidebar-menu-section-trigger]',\n      ) ?? null\n    )\n  }\n  if (element.matches('[data-sidebar-menu-action]')) {\n    return (\n      element.parentElement?.querySelector<HTMLElement>(\n        ':scope > [data-sidebar-menu-button]',\n      ) ?? null\n    )\n  }\n  if (element.matches('[data-sidebar-group-action]')) {\n    return (\n      element\n        .closest('[data-slot=sidebar-group]')\n        ?.querySelector<HTMLElement>('[data-sidebar-menu-button]') ?? null\n    )\n  }\n  return element\n}\n\n/**\n * The sidebar on a phone: the same parts, whole, in a Drawer from its side.\n * A link pressed inside closes it.\n */\nfunction SidebarSheet({\n  side,\n  label,\n  children,\n}: {\n  side: SidebarSide\n  label: string\n  children: ReactNode\n}) {\n  const { sheet, sheetOpen, setSheetOpen, id } = useSidebar()\n  if (!sheet) return null\n  return (\n    <Drawer side={side} open={sheetOpen} onOpenChange={setSheetOpen}>\n      <DrawerContent\n        id={id}\n        className='bg-sidebar w-(--sidebar-width-mobile,18rem) [--sidebar-width:var(--sidebar-width-mobile,18rem)]'\n      >\n        <DrawerTitle className='sr-only'>{label}</DrawerTitle>\n        <SidebarSurface\n          collapsed={false}\n          aria-label={label}\n          // Without a header to end short of it, the rows start below the close button, less the content's own gutter.\n          className='group-data-close-button/panel-surface:[&:not(:has(>[data-slot=sidebar-header]:first-child))]:pt-[calc(var(--surface-padding-lg)-6px+var(--control-height-sm)-var(--control-padding))]'\n        >\n          {children}\n        </SidebarSurface>\n      </DrawerContent>\n    </Drawer>\n  )\n}\n\nconst rowSelector = '[data-sidebar-menu-button], [data-sidebar-menu-section-trigger]'\n\n/**\n * The row that shows the current page: its own, or, while a section hides\n * it (closed, or folded into the rail), the section's.\n */\nfunction currentRow(area: HTMLElement): HTMLElement | null {\n  // Never a copy of a row that is leaving (the `flow` lib's), which keeps its marks while it fades.\n  const current = area.querySelector<HTMLElement>(\n    '[data-sidebar-menu-button][aria-current=page]:not([data-leaving] *)',\n  )\n  if (!current) return null\n  const sub = current.closest('[data-sidebar-menu-sub]')\n  const trigger = sub?.parentElement?.querySelector<HTMLElement>(\n    ':scope > [data-sidebar-menu-section-trigger]',\n  )\n  if (\n    trigger &&\n    (!trigger.hasAttribute('data-open') || area.dataset.state === 'collapsed')\n  ) {\n    return trigger\n  }\n  return current\n}\n\n/**\n * The current page's tint, under the rows, as strong as the highlight's, since\n * the sidebar's own colour washes out the muted one: it moves on `morph`, as\n * the Tabs' pill does, so it travels to the page you go to. Forced colours\n * mark the row itself instead.\n */\nconst currentClassName = `${pickClassName} ${rowTintClassName} forced-colors:hidden`\n\n/**\n * Rows that share one highlight, which glides between them under the\n * pointer and with focus; with `current`, the current page's tint too.\n */\nfunction RowArea({\n  current = false,\n  className,\n  children,\n}: {\n  current?: boolean\n  className?: string\n  children: ReactNode\n}) {\n  const { collapsed } = use(SurfaceContext)\n  const areaRef = useRef<HTMLDivElement>(null)\n  const highlightRef = useRef<HTMLSpanElement>(null)\n  const currentRef = useRef<HTMLSpanElement>(null)\n\n  useEffect(() => {\n    const area = areaRef.current\n    const highlight = highlightRef.current\n    if (!area || !highlight) return\n    const stops = [\n      followPointer(area, highlight, {\n        // A heading that opens and closes its group is a control of its own: over it, the highlight goes.\n        itemOf: itemMatching(area, rowSelector, {\n          rows: '[data-sidebar-group-toggle]',\n        }),\n        focus: true,\n      }),\n    ]\n    const tint = currentRef.current\n    if (tint) {\n      stops.push(\n        followPick(area, tint, {\n          picked: () => currentRow(area),\n          attributes: ['aria-current', 'data-open', 'data-state'],\n        }),\n      )\n    }\n    return () => {\n      for (const stop of stops) stop()\n    }\n  }, [])\n\n  return (\n    <div\n      ref={areaRef}\n      data-state={collapsed ? 'collapsed' : 'expanded'}\n      className={cn(\n        'relative isolate min-w-0 overflow-x-clip contain-inline-size',\n        className,\n      )}\n    >\n      {current ? (\n        <span\n          ref={currentRef}\n          aria-hidden\n          data-slot='sidebar-current'\n          className={currentClassName}\n        />\n      ) : null}\n      {children}\n      <span\n        ref={highlightRef}\n        aria-hidden\n        data-slot='sidebar-highlight'\n        className={rowHighlightClassName}\n      />\n    </div>\n  )\n}\n\n/** What sits above the rows, such as the workspace you are in. */\nfunction SidebarHeader({ className, children, ...props }: ComponentProps<'div'>) {\n  return (\n    <div\n      data-slot='sidebar-header'\n      className={cn(\n        // In a Drawer, it ends short of the close button, as a panel's header does.\n        'flex shrink-0 flex-col py-(--control-padding) group-data-close-button/panel-surface:pe-[calc(var(--surface-padding-lg)+var(--control-height-sm)-4px)]',\n        sidebarGutter,\n        className,\n      )}\n      {...props}\n    >\n      <RowArea className='flex flex-col gap-px'>{children}</RowArea>\n    </div>\n  )\n}\n\n/** What sits below the rows, such as the person signed in. */\nfunction SidebarFooter({ className, children, ...props }: ComponentProps<'div'>) {\n  return (\n    <div\n      data-slot='sidebar-footer'\n      className={cn(\n        'flex shrink-0 flex-col py-(--control-padding)',\n        sidebarGutter,\n        className,\n      )}\n      {...props}\n    >\n      <RowArea className='flex flex-col gap-px'>{children}</RowArea>\n    </div>\n  )\n}\n\n/**\n * The groups of rows, between the header and the footer. It scrolls when\n * they don't fit, with thin scrollbars and fading edges. With no header or\n * footer, its rows keep the gutter from the sidebar's top or bottom.\n */\nfunction SidebarContent({\n  className,\n  children,\n  'aria-label': label = 'Pages',\n  ...props\n}: Omit<ComponentProps<typeof ScrollArea>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <ScrollArea\n      data-sidebar-content=''\n      aria-label={label}\n      className='group/sidebar-content min-h-0 flex-1'\n      {...props}\n    >\n      <RowArea\n        current\n        className={cn(\n          'flex flex-col gap-(--surface-gap) py-1 group-first/sidebar-content:pt-(--control-padding) group-last/sidebar-content:pb-(--control-padding)',\n          sidebarGutter,\n          className,\n        )}\n      >\n        {children}\n      </RowArea>\n    </ScrollArea>\n  )\n}\n\nconst GroupContext = createContext<{\n  id: string\n  labelled: (has: boolean) => void\n} | null>(null)\n\n/** A group of rows, named by its heading, `SidebarGroupLabel`, when it has one. */\nfunction SidebarGroup({ className, children, ...props }: ComponentProps<'div'>) {\n  const id = useId()\n  const [labelled, setLabelled] = useState(false)\n  return (\n    <GroupContext value={{ id, labelled: setLabelled }}>\n      <div\n        role='group'\n        aria-labelledby={labelled ? id : undefined}\n        data-slot='sidebar-group'\n        className={cn('relative flex min-w-0 flex-col', className)}\n        {...props}\n      >\n        {children}\n      </div>\n    </GroupContext>\n  )\n}\n\n/**\n * The width a row's content keeps in a docked sidebar whatever the sidebar's\n * own width, so nothing is laid out again as it folds to its rail: the\n * sidebar's, inside its gutters and the row's padding. Anywhere else (its\n * Drawer, or a list drawn with its rows in a popover or a window) nothing\n * folds, so the content fits its row.\n */\nconst contentWidth =\n  'w-full in-data-[slot=sidebar]:w-[calc(var(--sidebar-width,16rem)-1px-2*var(--control-padding)-(var(--control-height)-1rem))]'\n\n/**\n * A group's heading. In the rail its words fade and a short line takes its\n * place, so the rows below stay where they are. Given `open`, it is a\n * disclosure button that shows and hides the group's rows, its chevron\n * turning down while they show.\n */\nfunction SidebarGroupLabel({\n  className,\n  children,\n  open,\n  onOpenChange,\n  ...props\n}: Omit<ComponentProps<'div'>, 'className'> & {\n  className?: string\n  /** Whether the group's rows show; the heading only says so, and the rows are yours to hide. */\n  open?: boolean\n  onOpenChange?: ComponentProps<typeof CollapsiblePrimitive>['onOpenChange']\n}) {\n  const group = use(GroupContext)\n  const { rail } = use(SurfaceContext)\n  useLayoutEffect(() => {\n    if (!group) return\n    group.labelled(true)\n    return () => group.labelled(false)\n  }, [group])\n  const toggles = open !== undefined\n  // In the rail its words fade, and its chevron with them.\n  const fadesInRail =\n    'transition-opacity duration-(--motion-enter-duration) ease-(--motion-enter-easing) group-data-[state=collapsed]/sidebar:opacity-0 group-data-[state=collapsed]/sidebar:duration-(--motion-exit-duration) group-data-[state=collapsed]/sidebar:ease-(--motion-exit-easing)'\n  const words = (\n    <span\n      data-cut\n      className={cn(\n        'truncate',\n        toggles ? 'min-w-0' : cn('shrink-0', fadesInRail, contentWidth),\n      )}\n    >\n      {children}\n    </span>\n  )\n  const label = (\n    <div\n      id={group?.id}\n      data-sidebar-group-label=''\n      className={cn(\n        'text-muted-foreground relative flex h-(--control-height-sm) shrink-0 items-center overflow-hidden text-xs font-medium',\n        !toggles && rowPadding,\n        // The line drawn in the rail, as wide as an icon, under where the words were.\n        'after:bg-border after:pointer-events-none after:absolute after:start-[calc((var(--control-height)-1rem)/2)] after:w-4 after:top-1/2 after:h-px after:opacity-0 after:transition-opacity after:duration-(--motion-exit-duration) after:ease-(--motion-exit-easing) forced-colors:after:bg-[CanvasText] group-data-[state=collapsed]/sidebar:after:opacity-100 group-data-[state=collapsed]/sidebar:after:duration-(--motion-enter-duration) group-data-[state=collapsed]/sidebar:after:ease-(--motion-enter-easing)',\n        className,\n      )}\n      {...props}\n    >\n      {/* A long heading truncates, and shows whole under the pointer; in the rail it is hidden. */}\n      {toggles ? (\n        <CutTooltip\n          disabled={rail}\n          render={\n            <CollapsibleTriggerPrimitive\n              // In the rail its words are gone, so it leaves the tab order.\n              tabIndex={rail ? -1 : undefined}\n              data-sidebar-group-toggle=''\n              className={cn(\n                'group/collapsible-trigger hover:text-sidebar-foreground flex h-full shrink-0 items-center gap-1 rounded-(--control-radius-capped) text-start',\n                rowPadding,\n                // As wide as a row whatever the sidebar's own width, so its words don't reflow as the rail closes.\n                'w-[calc(var(--sidebar-width,16rem)-1px-2*var(--control-padding))]',\n                'transition-[color,box-shadow] duration-(--motion-press-duration) ease-(--motion-press-fade-easing)',\n                // Inset, since the list scrolls and would clip a ring past its edge.\n                'focus-visible:ring-ring/50 focus-visible:ring-3 focus-visible:ring-inset focus-visible:outline-hidden',\n                // Forced colours' outline, inside, since the heading clips what passes its edge.\n                'focus-visible:-outline-offset-2',\n              )}\n            >\n              <span className={cn('flex min-w-0 items-center gap-1', fadesInRail)}>\n                {words}\n                <CollapsibleIndicator className='size-3' />\n              </span>\n            </CollapsibleTriggerPrimitive>\n          }\n        />\n      ) : (\n        <CutTooltip\n          // In the rail the heading is hidden.\n          disabled={rail}\n          render={words}\n        />\n      )}\n    </div>\n  )\n  // A disclosure with no panel of its own: the rows it shows and hides are yours.\n  return toggles ? (\n    <CollapsiblePrimitive open={open} onOpenChange={onOpenChange} render={label} />\n  ) : (\n    label\n  )\n}\n\n/**\n * What hides in the rail, such as a row's menu: it fades, then leaves the\n * tab order, and comes back the other way.\n */\nconst hiddenInRail =\n  'transition-[opacity,visibility] duration-(--motion-enter-duration) ease-(--motion-enter-easing) group-data-[state=collapsed]/sidebar:invisible group-data-[state=collapsed]/sidebar:opacity-0 group-data-[state=collapsed]/sidebar:duration-(--motion-exit-duration) group-data-[state=collapsed]/sidebar:ease-(--motion-exit-easing)'\n\n/**\n * A small button at the end of a group's heading, such as one that adds a\n * project. Give it an `aria-label`. It stays put as the sidebar narrows.\n */\nfunction SidebarGroupAction({ className, ...props }: ComponentProps<typeof Button>) {\n  return (\n    <Button\n      variant='ghost'\n      size='icon-xs'\n      className={cn(\n        'text-muted-foreground absolute top-[calc((var(--control-height-sm)-var(--control-height-xs))/2)] start-[calc(var(--sidebar-width,16rem)-1px-2*var(--control-padding)-var(--control-height-xs)-(var(--control-height-sm)-var(--control-height-xs))/2)]',\n        hiddenInRail,\n        className,\n      )}\n      {...props}\n      data-sidebar-group-action=''\n    />\n  )\n}\n\nfunction SidebarMenu({ className, ...props }: ComponentProps<'ul'>) {\n  return (\n    <ul\n      data-slot='sidebar-menu'\n      className={cn('flex min-w-0 flex-col gap-px', className)}\n      {...props}\n    />\n  )\n}\n\nfunction SidebarMenuItem({ className, ...props }: ComponentProps<'li'>) {\n  return (\n    <li\n      data-slot='sidebar-menu-item'\n      className={cn('group/sidebar-item relative min-w-0', className)}\n      {...props}\n    />\n  )\n}\n\n/*\n * A row is the Collapsible's and the Tree's, as tall as a control. Its content\n * keeps the sidebar's whole width and the row clips it, so the rail covers it\n * in place; a label too long is cut short, and its tooltip shows it whole.\n */\nconst sidebarRowVariants = cva(\n  [\n    collapsibleRowClassName,\n    'group/sidebar-row relative shrink-0 overflow-clip text-sidebar-foreground select-none',\n    rowPadding,\n    // In the rail it is its icon's square from the start, so the highlight and the current page's tint take the rail's shape as the edge moves; the edge covers the rest.\n    'group-data-[state=collapsed]/sidebar:w-(--control-height) group-data-[state=collapsed]/sidebar:overflow-visible',\n    'transition-[color,background-color,box-shadow] duration-(--motion-press-duration) ease-(--motion-press-fade-easing)',\n    // Inset, since the list scrolls and would clip a ring past its edge.\n    'focus-visible:ring-ring/50 focus-visible:ring-3 focus-visible:ring-inset focus-visible:outline-hidden',\n    'disabled:text-sidebar-foreground/40 disabled:pointer-events-none data-disabled:text-sidebar-foreground/40 data-disabled:pointer-events-none aria-disabled:text-sidebar-foreground/40 aria-disabled:pointer-events-none',\n    // Under forced colours, the current page is the system's own highlight.\n    'forced-colors:aria-[current=page]:bg-[Highlight] forced-colors:aria-[current=page]:text-[HighlightText] forced-colors:aria-[current=page]:forced-color-adjust-none forced-colors:aria-[current=page]:*:text-[HighlightText]',\n  ],\n  {\n    variants: {\n      size: {\n        default: 'py-[calc((var(--control-height)-1lh)/2)]',\n        // Room for a picture as tall as a small control, such as a person's or a workspace's, the same all round.\n        lg: 'p-[calc((var(--control-height-lg)-var(--control-height-sm))/2)]',\n      },\n    },\n    defaultVariants: { size: 'default' },\n  },\n)\n\n/** The row's content, which keeps a docked sidebar's whole width (`contentWidth`). Its icons sit muted, and full strength on the current page. */\nconst rowContentClassName = cn(\n  'flex shrink-0 items-start gap-2 [&>svg]:mt-0.5 [&>svg]:text-muted-foreground group-aria-[current=page]/sidebar-row:[&>svg]:text-sidebar-foreground',\n  // A label too long for the row is cut short; its tooltip shows it whole.\n  // A span leading another, such as a workspace's logo before its name, is a picture: it keeps its size.\n  '[&>span:not([data-slot]):not(:first-child:has(+span:not([data-slot])))]:min-w-0 [&>span:not([data-slot]):not(:first-child:has(+span:not([data-slot])))]:flex-1 [&>span:not([data-slot]):not(:first-child:has(+span:not([data-slot])))]:truncate',\n  // In the rail, all but the icon fade as the edge covers them, so no letter shows beside it.\n  '[&>*:not(:first-child)]:transition-opacity [&>*:not(:first-child)]:duration-(--motion-enter-duration) [&>*:not(:first-child)]:ease-(--motion-enter-easing) group-data-[state=collapsed]/sidebar:[&>*:not(:first-child)]:opacity-0 group-data-[state=collapsed]/sidebar:[&>*:not(:first-child)]:duration-(--motion-exit-duration) group-data-[state=collapsed]/sidebar:[&>*:not(:first-child)]:ease-(--motion-exit-easing)',\n  // Room for the row's menu, when it has one.\n  'group-has-data-sidebar-menu-action/sidebar-item:pe-[calc(var(--control-height-xs)+--spacing(1))]',\n)\n\n/**\n * Closes the Drawer the sidebar shows in a narrow container, when it is one.\n * Outside a SidebarProvider there is no Drawer, so it does nothing: a list\n * drawn with the sidebar's rows works in a popover or a panel too.\n */\nfunction useCloseSheet() {\n  const context = use(SidebarContext)\n  return () => {\n    if (context?.sheet) context.setSheetOpen(false)\n  }\n}\n\n/** Closes the Drawer when a link inside it is pressed, since the page it opens is under it. */\nfunction useCloseOnNavigate() {\n  const closeSheet = useCloseSheet()\n  return (event: MouseEvent<HTMLElement>) => {\n    if (event.currentTarget.closest('a[href]')) closeSheet()\n  }\n}\n\n/**\n * The row's tooltip names it where its label doesn't show whole: in the\n * icon rail, where the label is covered, with `tooltip`, and while a long\n * label is cut short, with the cut text, such as a name over an email.\n * Elsewhere it doesn't open.\n */\nfunction RowTooltip({ tooltip, row }: { tooltip?: ReactNode; row: ReactElement }) {\n  // From where the rail's edge stops, so it opens beside the icon.\n  const { rail } = use(SurfaceContext)\n  const [element, setElement] = useState<HTMLElement | null>(null)\n  const cut = useCut(element, rowLabels)\n  const shown = rail ? Boolean(tooltip) : cut.length > 0\n  return (\n    <SwapTextTitleContext value={false}>\n      <Tooltip disabled={!shown}>\n        {/* Its name holds the whole label already, covered or cut. */}\n        <TooltipTrigger ref={setElement} render={undescribed(row)} />\n        <TooltipContent side='end'>\n          {rail ? tooltip : <CutLines lines={cut} />}\n        </TooltipContent>\n      </Tooltip>\n    </SwapTextTitleContext>\n  )\n}\n\n/** A row's label, or the lines stacked inside it, such as a name over an email. */\nconst rowLabels =\n  ':scope > span > span:not([data-slot]):not(:has(> span)), :scope > span > span:not([data-slot]) > span:not(.sr-only), [data-cut]'\n\n/**\n * A row: a link to a page (`render={<a href='…' />}`) or a button. `isActive`\n * marks the current page, read out as such. `tooltip` names it in the rail.\n */\nfunction SidebarMenuButton({\n  isActive = false,\n  tooltip,\n  size,\n  className,\n  children,\n  onClick,\n  ...props\n}: Omit<ComponentProps<typeof ButtonPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n  /** Whether this row is the page you are on. */\n  isActive?: boolean\n  /** Its name in the rail, usually its label. */\n  tooltip?: ReactNode\n} & VariantProps<typeof sidebarRowVariants>) {\n  const closeOnNavigate = useCloseOnNavigate()\n  const row = (\n    <ButtonPrimitive\n      // A disabled row still takes focus, so it can be read.\n      focusableWhenDisabled\n      data-sidebar-menu-button=''\n      data-size={size ?? 'default'}\n      aria-current={isActive ? 'page' : undefined}\n      className={cn(sidebarRowVariants({ size }), className)}\n      onClick={(event, details) => {\n        closeOnNavigate(event)\n        return onClick?.(event, details)\n      }}\n      {...props}\n    >\n      <span\n        className={cn(\n          rowContentClassName,\n          contentWidth,\n          size === 'lg' && [\n            'in-data-[slot=sidebar]:w-[calc(var(--sidebar-width,16rem)-1px-2*var(--control-padding)-(var(--control-height-lg)-var(--control-height-sm)))] items-center',\n            // In the rail the row is as wide as an icon's: the picture glides back to its middle, where the icons above sit.\n            '[&>:first-child]:transition-transform [&>:first-child]:duration-(--motion-layout-duration) [&>:first-child]:ease-(--motion-layout-easing) motion-reduce:[&>:first-child]:transition-none',\n            'group-data-[state=collapsed]/sidebar:[&>:first-child]:-translate-x-[calc((var(--control-height-lg)-var(--control-height))/2)] rtl:group-data-[state=collapsed]/sidebar:[&>:first-child]:translate-x-[calc((var(--control-height-lg)-var(--control-height))/2)]',\n          ],\n        )}\n      >\n        {children}\n      </span>\n    </ButtonPrimitive>\n  )\n  return <RowTooltip tooltip={tooltip} row={row} />\n}\n\n/** A count after a row's label, such as unread items: a Badge, covered in the rail. */\nfunction SidebarMenuBadge({\n  className,\n  variant = 'secondary',\n  ...props\n}: ComponentProps<typeof Badge>) {\n  return <Badge variant={variant} className={cn('ms-auto', className)} {...props} />\n}\n\n/**\n * A small button at a row's end, such as one that opens its menu. Give it an\n * `aria-label`. It shows while the pointer is over the row, focus is on it or\n * its menu is open, and always on a touch screen.\n */\nfunction SidebarMenuAction({ className, ...props }: ComponentProps<typeof Button>) {\n  return (\n    <Button\n      variant='ghost'\n      size='icon-xs'\n      className={cn(\n        'text-muted-foreground absolute top-[calc((var(--control-height)-var(--control-height-xs))/2)] z-30 start-[calc(var(--sidebar-width,16rem)-1px-2*var(--control-padding)-var(--control-height-xs)-(var(--control-height)-var(--control-height-xs))/2)]',\n        'opacity-0 group-hover/sidebar-item:opacity-100 group-focus-within/sidebar-item:opacity-100 aria-expanded:opacity-100 pointer-coarse:opacity-100',\n        hiddenInRail,\n        className,\n      )}\n      {...props}\n      data-sidebar-menu-action=''\n    />\n  )\n}\n\n/**\n * A row that opens to show more rows, by the disclosure pattern: its\n * chevron turns down as they open on the Collapsible's height. In the rail\n * its rows fold away, and pressing it opens the sidebar and the section.\n */\nfunction SidebarMenuSection({\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  className,\n  ...props\n}: Omit<ComponentProps<typeof CollapsiblePrimitive>, 'className' | 'render'> & {\n  className?: string\n}) {\n  const { collapsed } = use(SurfaceContext)\n  const sidebar = use(SidebarContext)\n  const [open, setOpen] = useControllable(openProp, defaultOpen, onOpenChange)\n  return (\n    <CollapsiblePrimitive\n      render={<SidebarMenuItem className={className} />}\n      // In the rail its rows are folded away, so it reads as closed, and\n      // opens again as it was when the sidebar does.\n      open={collapsed ? false : open}\n      onOpenChange={(next, details) => {\n        // In the rail, it shows what's inside: the sidebar opens, and the\n        // section with it, never closing what the rail only folded away.\n        if (collapsed) {\n          sidebar?.setOpen(true)\n          if (!next) {\n            details.cancel()\n            return\n          }\n        }\n        setOpen(next, details)\n      }}\n      {...props}\n    />\n  )\n}\n\nfunction SidebarMenuSectionTrigger({\n  tooltip,\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof CollapsibleTriggerPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n  /** Its name in the rail, usually its label. */\n  tooltip?: ReactNode\n}) {\n  const row = (\n    <CollapsibleTriggerPrimitive\n      data-sidebar-menu-section-trigger=''\n      className={cn(\n        sidebarRowVariants(),\n        'group/collapsible-trigger',\n        // Under forced colours, it takes the current page's highlight while it hides that page, closed or in the rail.\n        'forced-colors:not-data-open:group-has-[[aria-current=page]]/sidebar-item:bg-[Highlight] forced-colors:not-data-open:group-has-[[aria-current=page]]/sidebar-item:text-[HighlightText] forced-colors:not-data-open:group-has-[[aria-current=page]]/sidebar-item:forced-color-adjust-none forced-colors:not-data-open:group-has-[[aria-current=page]]/sidebar-item:*:text-[HighlightText]',\n        className,\n      )}\n      {...props}\n    >\n      <span className={cn(rowContentClassName, contentWidth)}>\n        {children}\n        <CollapsibleIndicator className='ms-auto' />\n      </span>\n    </CollapsibleTriggerPrimitive>\n  )\n  return <RowTooltip tooltip={tooltip} row={row} />\n}\n\n/**\n * A section's rows, under a line from its icon, their labels level with\n * its label. They fold away in the rail.\n */\nfunction SidebarMenuSub({ className, children, ...props }: ComponentProps<'ul'>) {\n  const ref = useRef<HTMLUListElement>(null)\n\n  // Its height in px, which the rail can fold from: ui-sdk leaves an open\n  // panel at `auto`, which CSS can't move. Rows that come and go move it too.\n  useEffect(() => {\n    const list = ref.current\n    const panel = list?.parentElement\n    if (!list || !panel) return\n    let last = -1\n    const observer = new ResizeObserver(([entry]) => {\n      const height = entry.borderBoxSize[0].blockSize\n      if (Math.abs(height - last) < 0.5) return\n      last = height\n      panel.style.setProperty('--sidebar-menu-sub-height', `${height}px`)\n    })\n    observer.observe(list)\n    return () => observer.disconnect()\n  }, [])\n\n  return (\n    <CollapsiblePanelPrimitive\n      // Kept while closed, so its section knows when it holds the current page.\n      keepMounted\n      data-sidebar-menu-sub=''\n      // Clipped down the page only, so a focus ring inside keeps its sides.\n      className={cn(\n        collapseClassName,\n        'overflow-y-clip [--collapse-height:var(--sidebar-menu-sub-height,var(--collapsible-panel-height))]',\n        'group-data-[state=collapsed]/sidebar:invisible group-data-[state=collapsed]/sidebar:h-0 group-data-[state=collapsed]/sidebar:transition-[height,visibility] group-data-[state=collapsed]/sidebar:duration-(--motion-layout-duration) group-data-[state=collapsed]/sidebar:ease-(--motion-layout-easing) group-data-[state=collapsed]/sidebar:*:opacity-0 group-data-[state=collapsed]/sidebar:*:duration-(--motion-exit-duration) group-data-[state=collapsed]/sidebar:*:ease-(--motion-exit-easing) motion-reduce:group-data-[state=collapsed]/sidebar:transition-none',\n      )}\n    >\n      <ul\n        ref={ref}\n        className={cn(\n          collapsibleNestedClassName,\n          'before:start-[calc((var(--control-height)-1rem)/2+--spacing(2))]',\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </ul>\n    </CollapsiblePanelPrimitive>\n  )\n}\n\nfunction SidebarMenuSubItem({ className, ...props }: ComponentProps<'li'>) {\n  return (\n    <li\n      data-slot='sidebar-menu-sub-item'\n      className={cn('relative min-w-0', className)}\n      {...props}\n    />\n  )\n}\n\n/** A section's row: a link to a page, usually, with `isActive` on the current one. */\nfunction SidebarMenuSubButton({\n  isActive = false,\n  tooltip,\n  className,\n  children,\n  // A link, which takes the row's content and its `href` from ui-sdk's Button.\n  // oxlint-disable-next-line jsx-a11y/anchor-is-valid, jsx-a11y/anchor-has-content\n  render = <a />,\n  onClick,\n  ...props\n}: Omit<ComponentProps<typeof ButtonPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n  /** Where the row's link goes. */\n  href?: string\n  isActive?: boolean\n  /** Its name, shown while a long label is cut short. */\n  tooltip?: ReactNode\n}) {\n  const closeOnNavigate = useCloseOnNavigate()\n  const row = (\n    <ButtonPrimitive\n      render={render}\n      // A disabled row still takes focus, so it can be read.\n      focusableWhenDisabled\n      // Read with the sidebar's other rows, by the highlight and the current page's tint.\n      data-sidebar-menu-button=''\n      data-sub=''\n      aria-current={isActive ? 'page' : undefined}\n      className={cn(sidebarRowVariants(), className)}\n      onClick={(event, details) => {\n        closeOnNavigate(event)\n        return onClick?.(event, details)\n      }}\n      {...props}\n    >\n      <span\n        className={cn(\n          rowContentClassName,\n          // A sub-row's content: the row's width, less its indent.\n          'w-full in-data-[slot=sidebar]:w-[calc(var(--sidebar-width,16rem)-1px-2*var(--control-padding)-(var(--control-height)-1rem)-1.5rem)]',\n        )}\n      >\n        {children}\n      </span>\n    </ButtonPrimitive>\n  )\n  return <RowTooltip tooltip={tooltip} row={row} />\n}\n\n/** The icon rail's width: a row's height, a gutter either side and the sidebar's border. */\n// A menu's or a popover's trigger while it is open, never a section that has expanded.\nconst OPEN_POPUP = '[aria-haspopup][aria-expanded=true]'\n\nconst railVariable =\n  '[--sidebar-rail:var(--sidebar-width-icon,calc(var(--control-height)+2*var(--control-padding)+1px))]'\n\ntype SidebarCollapsible = 'icon' | 'offcanvas'\n\n/**\n * `sidebar` draws its edge; `inset` leaves it out, for a page that sits\n * beside it as a card, and keeps a gutter for the card when it's out of sight.\n */\ntype SidebarVariant = 'sidebar' | 'inset'\n\ntype Peek = 'off' | 'open' | 'closing'\n\n/**\n * The sidebar beside the page, which docks to `side`. Collapsed, `icon`\n * narrows it to its icons, its rows named by tooltips; `offcanvas` slides it\n * away, and resting the pointer on the screen's edge brings it back over the\n * page for a moment. Either way the page beside it moves on `layout`. On a\n * phone it is a Drawer from the same side.\n */\nfunction Sidebar({\n  side = 'start',\n  collapsible = 'icon',\n  variant = 'sidebar',\n  'aria-label': label = 'Main',\n  className,\n  children,\n  ...props\n}: ComponentProps<'nav'> & {\n  /** The edge it docks to: `start` and `end` follow the text direction. */\n  side?: SidebarSide\n  /** How it collapses: to its icons, or out of sight. */\n  collapsible?: SidebarCollapsible\n  /** Whether it draws its edge, or leaves it out for a page set beside it as a card. */\n  variant?: SidebarVariant\n}) {\n  const { open, id, sheet } = useSidebar()\n  const icon = collapsible === 'icon'\n  const gapRef = useRef<HTMLDivElement>(null)\n  const panelRef = useRef<HTMLDivElement>(null)\n\n  // An icon rail takes its own width only once the edge has reached it, and\n  // the sidebar's whole width as soon as it opens, so nothing inside is laid\n  // out again while the edge moves: the panel is clipped to the edge instead.\n  const [rail, setRail] = useState(!open)\n  const [wasOpen, setWasOpen] = useState(open)\n  // Offcanvas, collapsed: whether it peeks over the page.\n  const [peek, setPeek] = useState<Peek>('off')\n  if (open !== wasOpen) {\n    setWasOpen(open)\n    if (open) {\n      setRail(false)\n      setPeek('off')\n    }\n  }\n  // Never a rail while open, whatever an earlier collapse left behind.\n  const railed = icon && !open && rail\n\n  useEffect(() => {\n    const gap = gapRef.current\n    if (open || !icon || !gap || rail) return\n    let current = true\n    void transitionsSettled(gap, { property: 'width' }).then(() => {\n      if (current) setRail(true)\n    })\n    return () => {\n      current = false\n    }\n  }, [open, icon, rail])\n\n  const peeking = usePeek({\n    enabled: !icon && !open,\n    peek,\n    setPeek,\n    panelRef,\n    id,\n  })\n  // Slid away, or sliding: it still catches the pointer, which turns it back.\n  const away = !icon && !open && peek !== 'open'\n  const hidden = !icon && !open && peek === 'off'\n\n  return (\n    <>\n      {/* The page's room for it, which moves on `layout` as it collapses. */}\n      <div\n        ref={gapRef}\n        aria-hidden\n        data-slot='sidebar-gap'\n        data-state={open ? 'expanded' : 'collapsed'}\n        data-side={side}\n        data-collapsible={collapsible}\n        data-variant={variant}\n        className={cn(\n          dockGapClassName,\n          '[--dock-width:var(--sidebar-width,16rem)] data-[collapsible=icon]:data-[state=collapsed]:w-(--sidebar-rail)',\n          // Inset, out of sight: the page, a card, keeps the sidebar's gutter from the edge.\n          'data-[variant=inset]:data-[collapsible=offcanvas]:data-[state=collapsed]:w-(--control-padding)',\n          // An icon rail's edge is the gap's; an offcanvas panel draws its own.\n          'data-[collapsible=icon]:bg-sidebar data-[variant=sidebar]:data-[collapsible=icon]:data-[side=end]:border-s data-[variant=sidebar]:data-[collapsible=icon]:data-[side=start]:border-e forced-colors:border-[CanvasText]',\n          railVariable,\n        )}\n      />\n      {!icon && !open ? (\n        <div\n          aria-hidden\n          data-slot='sidebar-edge'\n          data-side={side}\n          className='absolute inset-y-0 z-20 hidden w-2 data-[side=end]:end-(--sidebar-edge-inset,0px) data-[side=start]:start-0 @3xl/dock:block'\n          style={{\n            ['--sidebar-edge-inset' as string]: `${peeking.scrollbar}px`,\n          }}\n          {...peeking.edge}\n        />\n      ) : null}\n      <div\n        ref={panelRef}\n        data-slot='sidebar'\n        data-state={open ? 'expanded' : 'collapsed'}\n        data-side={side}\n        data-collapsible={collapsible}\n        data-variant={variant}\n        data-rail={railed ? '' : undefined}\n        data-peek={peek === 'off' ? undefined : peek}\n        data-hidden={away ? '' : undefined}\n        inert={hidden}\n        className={cn(\n          dockPanelClassName,\n          'bg-sidebar [--dock-width:var(--sidebar-width,16rem)]',\n          railVariable,\n          // Icon: as wide as its gap, inside the gap's border, clipped to the moving edge.\n          'data-[collapsible=icon]:w-[calc(var(--sidebar-width,16rem)-1px)] data-[collapsible=icon]:data-rail:w-[calc(var(--sidebar-rail)-1px)]',\n          'data-[collapsible=icon]:[clip-path:inset(0)] data-[collapsible=icon]:transition-[clip-path] data-[collapsible=icon]:duration-(--motion-layout-duration) data-[collapsible=icon]:ease-(--motion-layout-easing) data-[collapsible=icon]:data-rail:transition-none motion-reduce:data-[collapsible=icon]:transition-none',\n          'data-[collapsible=icon]:data-[state=collapsed]:data-[side=start]:[clip-path:inset(0_calc(100%-var(--sidebar-rail)+1px)_0_0)] data-[collapsible=icon]:data-[state=collapsed]:data-[side=end]:[clip-path:inset(0_0_0_calc(100%-var(--sidebar-rail)+1px))]',\n          'rtl:data-[collapsible=icon]:data-[state=collapsed]:data-[side=start]:[clip-path:inset(0_0_0_calc(100%-var(--sidebar-rail)+1px))] rtl:data-[collapsible=icon]:data-[state=collapsed]:data-[side=end]:[clip-path:inset(0_calc(100%-var(--sidebar-rail)+1px)_0_0)]',\n          // Offcanvas: it draws its own edge, and moves with the page on `layout`; it peeks in on `enter` and away on `exit`. Inset, it draws one only while it peeks over the page.\n          'data-[variant=sidebar]:data-[collapsible=offcanvas]:data-[side=end]:border-s data-[variant=sidebar]:data-[collapsible=offcanvas]:data-[side=start]:border-e data-peek:data-[side=end]:border-s data-peek:data-[side=start]:border-e',\n          'data-[collapsible=offcanvas]:transition-[box-shadow,translate] data-[collapsible=offcanvas]:duration-(--motion-layout-duration) data-[collapsible=offcanvas]:ease-[var(--motion-layout-fade-easing),var(--motion-layout-easing)] data-[peek=closing]:duration-(--motion-exit-duration) data-[peek=closing]:ease-[var(--motion-exit-fade-easing),var(--motion-exit-easing)] data-[peek=open]:duration-(--motion-enter-duration) data-[peek=open]:ease-[var(--motion-enter-fade-easing),var(--motion-enter-easing)] data-peek:shadow-xl motion-reduce:data-[collapsible=offcanvas]:transition-[box-shadow]',\n          className,\n        )}\n        {...peeking.panel}\n      >\n        <SidebarSurface\n          id={sheet ? undefined : id}\n          collapsed={icon && !open}\n          rail={railed}\n          aria-label={label}\n          {...props}\n        >\n          {children}\n        </SidebarSurface>\n      </div>\n      <SidebarSheet side={side} label={label}>\n        {children}\n      </SidebarSheet>\n    </>\n  )\n}\n\n/**\n * An offcanvas sidebar's peek: resting the pointer on the screen's edge for\n * 200ms brings it over the page, and it slides away once the pointer leaves\n * it, unless a menu inside is open or the keyboard is working in it. A pointer\n * back before it has gone turns it round at once. Escape sends it away.\n */\nfunction usePeek({\n  enabled,\n  peek,\n  setPeek,\n  panelRef,\n  id,\n}: {\n  enabled: boolean\n  peek: Peek\n  setPeek: (update: Peek | ((now: Peek) => Peek)) => void\n  panelRef: RefObject<HTMLDivElement | null>\n  id: string\n}) {\n  const openTimer = useRef<ReturnType<typeof setTimeout>>(undefined)\n  const closeTimer = useRef<ReturnType<typeof setTimeout>>(undefined)\n  // The pointer is over the panel: it stays.\n  const inside = useRef(false)\n  const [scrollbar, setScrollbar] = useState(0)\n\n  const clearTimers = () => {\n    clearTimeout(openTimer.current)\n    clearTimeout(closeTimer.current)\n  }\n  const trigger = () => dockTrigger(id)\n\n  const close = () => {\n    clearTimers()\n    const panel = panelRef.current\n    if (!panel) return\n    if (panel.querySelector(OPEN_POPUP) || panel.querySelector(':focus-visible')) return\n    // A row pressed inside it holds focus, which would fall to the page once it hides.\n    if (panel.contains(document.activeElement)) trigger()?.focus({ preventScroll: true })\n    setPeek((now) => (now === 'open' ? 'closing' : now))\n  }\n  const scheduleClose = () => {\n    clearTimeout(closeTimer.current)\n    closeTimer.current = setTimeout(close, GLIDE_GROUP_CLOSE_DELAY)\n  }\n\n  // Once it has slid away, it is gone.\n  useEffect(() => {\n    const panel = panelRef.current\n    if (peek !== 'closing' || !panel) return\n    let current = true\n    void transitionsSettled(panel, { property: 'translate' }).then(() => {\n      if (current) setPeek((now) => (now === 'closing' ? 'off' : now))\n    })\n    return () => {\n      current = false\n    }\n  }, [peek, panelRef, setPeek])\n\n  // While it peeks: Escape sends it away, and a menu inside that closes with the pointer elsewhere lets it go.\n  useEffect(() => {\n    const panel = panelRef.current\n    if (peek !== 'open' || !panel) return\n    const menus = new MutationObserver(() => {\n      if (!inside.current && !panel.querySelector(OPEN_POPUP)) scheduleClose()\n    })\n    menus.observe(panel, {\n      subtree: true,\n      attributes: true,\n      attributeFilter: ['aria-expanded'],\n    })\n    // A popup open above it takes Escape first.\n    const unregister = shortcuts.register(\n      'escape',\n      () => {\n        const focused = panel.contains(document.activeElement)\n        setPeek('closing')\n        if (focused) trigger()?.focus()\n      },\n      { layer: panel, allowInInput: true },\n    )\n    return () => {\n      unregister()\n      menus.disconnect()\n    }\n  })\n\n  useEffect(() => clearTimers, [])\n\n  // On the end edge, the strip sits inside the page's scrollbar, which stays in reach.\n  useLayoutEffect(() => {\n    const inset = panelRef.current?.parentElement?.querySelector<HTMLElement>(\n      ':scope > [data-slot=sidebar-inset]',\n    )\n    if (!enabled || !inset) return\n    const measure = () => setScrollbar(inset.offsetWidth - inset.clientWidth)\n    measure()\n    const observer = new ResizeObserver(measure)\n    observer.observe(inset)\n    return () => observer.disconnect()\n  }, [enabled, panelRef])\n\n  return {\n    scrollbar,\n    edge: {\n      onPointerEnter: (event: ReactPointerEvent<HTMLElement>) => {\n        if (!enabled || event.pointerType === 'touch') return\n        clearTimeout(closeTimer.current)\n        if (peek === 'open') return\n        clearTimeout(openTimer.current)\n        if (peek === 'closing') setPeek('open')\n        else openTimer.current = setTimeout(() => setPeek('open'), HOVER_DELAY)\n      },\n      onPointerLeave: () => {\n        clearTimeout(openTimer.current)\n        if (peek === 'open' && !inside.current) scheduleClose()\n      },\n    },\n    panel: {\n      onPointerEnter: (event: ReactPointerEvent<HTMLElement>) => {\n        if (!enabled || event.pointerType === 'touch') return\n        inside.current = true\n        clearTimeout(closeTimer.current)\n        if (peek === 'closing') setPeek('open')\n      },\n      onPointerLeave: (event: ReactPointerEvent<HTMLElement>) => {\n        if (event.pointerType === 'touch') return\n        inside.current = false\n        if (enabled && peek === 'open') scheduleClose()\n      },\n    },\n  }\n}\n\n/**\n * Opens and closes the sidebar, or the Drawer on a phone. Its tooltip names\n * the shortcut.\n */\nfunction SidebarTrigger({\n  className,\n  onClick,\n  ref,\n  ...props\n}: ComponentProps<typeof Button>) {\n  const dock = useSidebar()\n  const { open, sheet } = dock\n  const trigger = useDockTrigger(dock, { onClick, ref })\n  const label = sheet ? 'Open sidebar' : open ? 'Collapse sidebar' : 'Expand sidebar'\n  return (\n    <Tooltip>\n      <TooltipTrigger\n        render={\n          <Button\n            data-sidebar-trigger=''\n            variant='ghost'\n            size='icon-sm'\n            aria-label={label}\n            {...trigger}\n            className={cn(\n              // The page may load as wide as a phone's, which the provider learns only once it is measured: its expanded look lands at once, never fading on load.\n              'text-muted-foreground not-data-mounted:transition-none',\n              className,\n            )}\n            {...props}\n          />\n        }\n      >\n        <IconPlaceholder\n          lucide='PanelLeftIcon'\n          tabler='IconLayoutSidebar'\n          hugeicons='SidebarLeftIcon'\n          phosphor='SidebarIcon'\n          remixicon='RiSideBarLine'\n          aria-hidden\n          className='rtl:-scale-x-100'\n        />\n      </TooltipTrigger>\n      <TooltipContent>\n        {label}\n        {dock.shortcut ? (\n          <TooltipShortcut>\n            <KbdGroup keys={dock.shortcut} />\n          </TooltipShortcut>\n        ) : null}\n      </TooltipContent>\n    </Tooltip>\n  )\n}\n\nexport {\n  Sidebar,\n  SidebarContent,\n  SidebarFooter,\n  SidebarGroup,\n  SidebarGroupAction,\n  SidebarGroupLabel,\n  SidebarHeader,\n  SidebarInset,\n  SidebarMenu,\n  SidebarMenuAction,\n  SidebarMenuBadge,\n  SidebarMenuButton,\n  SidebarMenuItem,\n  SidebarMenuSection,\n  SidebarMenuSectionTrigger,\n  SidebarMenuSub,\n  SidebarMenuSubButton,\n  SidebarMenuSubItem,\n  SidebarProvider,\n  SidebarTrigger,\n  useCloseSheet,\n  useSidebar,\n  type SidebarCollapsible,\n  type SidebarSide,\n  type SidebarVariant,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/sidebar.tsx"
    }
  ],
  "type": "registry:component"
}