{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "navigation-rail",
  "title": "NavigationRail",
  "description": "The vertical bar of the app's top-level pages on the start edge of a wide screen, as in a chat or mail app or an editor's activity bar: each item an icon over a short label, the current one with its `currentIcon`, a bar on the rail's edge and `aria-current=\"page\"`.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-current-path",
    "@ouro/lib-env",
    "@ouro/lib-navigation-key",
    "@ouro/lib-refs",
    "@ouro/lib-router-link",
    "@ouro/lib-use-dev-messages",
    "@ouro/menu",
    "@ouro/tooltip"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/navigation-rail/navigation-rail-styles.ts",
      "content": "export { countClass, footerClass, headerClass, iconClass, indicatorClass, itemClass, labelClass, listClass, menuCountClass, railClass, separatorClass, shownCount, spokenCountClass };\n\n// Class strings are literal so the app's Tailwind finds them when it compiles.\n\n/**\n * The count as the badge shows it: up to 99, then \"99+\". Screen readers hear the whole number.\n *\n * @claim \"The count as the\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail counts > shows a count on the icon, capped at 99+, and speaks the whole number after the label)\n * @claim \"Screen readers hear the whole number\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail counts > shows a count on the icon, capped at 99+, and speaks the whole number after the label)\n */\nfunction shownCount(count: number): string {\n  return count > 99 ? \"99+\" : String(count);\n}\n\n/**\n * The column: 68px with labels, 56px without. It fills its container's height and draws no\n * surface of its own, so it sits on the app's frame.\n * @claim \"The column: 68px with\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > is 68px wide with labels and 56px with hideLabels, with items at least 44px tall)\n * @claim \"It fills its container's\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > fills its container's height and draws no surface of its own)\n */\nconst railClass = {\n  labels: \"box-border flex h-full w-17 shrink-0 flex-col py-2\",\n  icons: \"box-border flex h-full w-14 shrink-0 flex-col py-2\",\n} as const;\n\nconst headerClass = \"flex shrink-0 items-center justify-center px-1 pb-2\";\n\nconst footerClass = \"flex shrink-0 flex-col items-center gap-1 px-1 pt-2\";\n\n/** The items, in the room left between the header and the footer; what does not fit moves under More. */\nconst listClass = \"m-0 box-border flex min-h-0 flex-1 list-none flex-col gap-1 overflow-hidden px-1 py-0\";\n\n/** A short rule between groups of items, in a list item of its own that screen readers skip. */\nconst separatorClass = \"mx-auto block h-px w-8 bg-border forced-colors:bg-[CanvasText]\";\n\n/**\n * An item: the icon over its label, at least 44px tall. The current item's label is the\n * foreground colour and its icon the primary colour; the rest are muted text mixed toward the\n * foreground, which keeps them legible on a muted frame too. A press scales it (not with reduced\n * motion), and the colours ease.\n * @claim \"the icon over its\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > is 68px wide with labels and 56px with hideLabels, with items at least 44px tall)\n * @claim \"The current item's label\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > shows the current item's bar on the rail's start edge, its label in the foreground colour and its icon in the primary colour)\n */\nconst itemClass = {\n  labels:\n    \"press group/navigation-rail relative m-0 box-border flex min-h-14 w-full cursor-pointer flex-col items-center justify-center gap-1 rounded-ouro-md border-0 bg-transparent px-0.5 py-1.5 \" +\n    \"font-[inherit] no-underline select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n    \"text-[color-mix(in_oklab,var(--muted-foreground)_80%,var(--foreground))] pointer-fine:hover:bg-accent pointer-fine:hover:text-accent-foreground data-selected:text-foreground \" +\n    \"motion-safe:active:scale-(--ouro-press-scale) outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid forced-colors:border forced-colors:border-solid\",\n  icons:\n    \"press group/navigation-rail relative m-0 box-border flex min-h-11 w-full cursor-pointer flex-col items-center justify-center rounded-ouro-md border-0 bg-transparent p-0 \" +\n    \"font-[inherit] no-underline select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n    \"text-[color-mix(in_oklab,var(--muted-foreground)_80%,var(--foreground))] pointer-fine:hover:bg-accent pointer-fine:hover:text-accent-foreground data-selected:text-foreground \" +\n    \"motion-safe:active:scale-(--ouro-press-scale) outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid forced-colors:border forced-colors:border-solid\",\n} as const;\n\n/**\n * The current item's bar on the rail's start edge. It grows from its middle when the item\n * becomes current and shrinks away from the one that was; with reduced motion it only fades.\n * Under forced colours it keeps the highlight colour.\n */\nconst indicatorClass =\n  \"pointer-events-none absolute -start-1 top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-full bg-primary opacity-0 scale-y-0 \" +\n  \"transition-[scale,opacity] duration-(--ouro-duration-base) ease-(--ouro-ease-out) \" +\n  \"group-data-selected/navigation-rail:opacity-100 group-data-selected/navigation-rail:scale-y-100 \" +\n  \"motion-reduce:scale-y-100 motion-reduce:transition-opacity motion-reduce:duration-(--ouro-duration-fast) \" +\n  \"forced-colors:bg-[Highlight] forced-colors:forced-color-adjust-none\";\n\nconst iconClass = \"relative flex size-6 shrink-0 items-center justify-center group-data-selected/navigation-rail:text-primary [&>svg]:size-full\";\n\n/**\n * The label under the icon: two lines at most, broken between words (hyphenated where the\n * page's language allows). A label that still does not fit ends in an ellipsis and gets a Tooltip.\n * A word too wide for the rail is set a size smaller (`squeezed`), and one too wide even then\n * breaks within itself, so no letter is ever cut in half.\n * @claim \"The label under the\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail labels > wraps a long label to two lines between words, and gives a label that still does not fit an ellipsis and a tooltip)\n * @claim \"A word too wide for the rail is set a size smaller\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail labels > sets a word too wide for the rail a size smaller, whole and centred when it fits there, and never clips it mid-letter)\n */\nconst labelClass = {\n  fits:\n    \"line-clamp-2 w-full text-center text-[0.6875rem] leading-[0.875rem] font-medium text-balance hyphens-auto [overflow-wrap:normal] group-data-selected/navigation-rail:font-semibold\",\n  squeezed:\n    \"line-clamp-2 w-full text-center text-[0.625rem] leading-[0.875rem] font-medium text-balance hyphens-auto [overflow-wrap:anywhere] group-data-selected/navigation-rail:font-semibold\",\n} as const;\n\n/** The count on the icon's top end corner. */\nconst countClass =\n  \"absolute -end-2.5 -top-1.5 box-border h-4 min-w-4 rounded-full bg-destructive px-1 text-center text-[0.625rem] leading-4 font-semibold text-destructive-foreground tabular-nums \" +\n  \"forced-colors:border forced-colors:border-solid forced-colors:leading-[0.875rem]\";\n\n/**\n * The count in words after the label, \", 5 new\", for screen readers only: inline text of zero size in\n * the label's own line. In a box of its own, as `sr-only` makes it, the name gains a space before its comma.\n * @claim \"The count in words after the label\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail counts > names an item with a count by its words, the label first and the count after, so the name starts with what it shows)\n */\nconst spokenCountClass = \"text-[0px] leading-0\";\n\n/** The count after a label in the More menu. */\nconst menuCountClass =\n  \"ms-auto box-border h-4 min-w-4 rounded-full bg-destructive px-1 text-center text-[0.625rem] leading-4 font-semibold text-destructive-foreground tabular-nums \" +\n  \"forced-colors:border forced-colors:border-solid forced-colors:leading-[0.875rem]\";\n",
      "type": "registry:ui",
      "target": "@components/ouro/navigation-rail/navigation-rail-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/navigation-rail/navigation-rail.tsx",
      "content": "\"use client\";\n\nimport { flushSync } from \"react-dom\";\nimport { useLayoutEffect, useMemo, useRef, useState, type JSX, type KeyboardEvent, type MouseEvent, type ReactElement, type ReactNode, type Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { currentHref } from \"@/registry/ouro/lib/ouro/current-path\";\nimport { navigationKey } from \"@/registry/ouro/lib/ouro/navigation-key\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { RouterLink } from \"@/registry/ouro/lib/ouro/router-link\";\nimport { useDevWarnings, type DevWarning } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { Menu, MenuItem, MenuSeparator } from \"@/registry/ouro/components/ouro/menu/menu\";\nimport { Tooltip } from \"@/registry/ouro/components/ouro/tooltip/tooltip\";\nimport {\n  countClass,\n  footerClass,\n  headerClass,\n  iconClass,\n  indicatorClass,\n  itemClass,\n  labelClass,\n  listClass,\n  menuCountClass,\n  railClass,\n  separatorClass,\n  shownCount,\n  spokenCountClass,\n} from \"@/registry/ouro/components/ouro/navigation-rail/navigation-rail-styles\";\n\n/** What a NavigationRail item has: its label, its icon and a count. */\ninterface NavigationRailItemBase {\n  /** An item, the default. A `{ type: \"separator\" }` entry draws a rule between groups instead. */\n  type?: \"item\" | undefined;\n  /** The item's text under the icon, a short word or phrase: \"Calendar\". Screen readers hear it as the item's name. */\n  label: string;\n  /**\n   * The item's icon, an `<svg>` (a lucide-react or Fluent UI System icon, for example). It is\n   * hidden from screen readers; the label names the item.\n   */\n  icon: ReactNode;\n  /** The icon while the item is current, such as the filled form of `icon`. `icon` when not given. */\n  currentIcon?: ReactNode;\n  /**\n   * New things on the item's page: a badge on the icon, capped at \"99+\", that screen readers hear\n   * after the label with `countLabel`. The item's name is its label and then the count, \"Activity, 5\n   * new\", so it starts with the words the item shows. Nothing shows for 0.\n   * @claim \"The item's name is its label and then the count\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail counts > names an item with a count by its words, the label first and the count after, so the name starts with what it shows)\n   * @claim \"Nothing shows for 0\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail counts > shows a count on the icon, capped at 99+, and speaks the whole number after the label)\n   */\n  count?: number | undefined;\n  /** Marks this item as the current page or view (`aria-current=\"page\"`), when `currentPath` cannot tell. */\n  current?: boolean | undefined;\n\n  /** Not a prop. A number goes in `count`: `{ label: \"Activity\", count: 3 }`. */\n  badge?: { \"Use count={3}\": never };\n  /** Not a prop. Ouro UI uses `currentIcon`: `{ icon: <ChatRegular />, currentIcon: <ChatFilled /> }`. */\n  activeIcon?: { \"Use currentIcon\": never };\n  /** Not a prop. Ouro UI uses `currentIcon`: `{ icon: <ChatRegular />, currentIcon: <ChatFilled /> }`. */\n  selectedIcon?: { \"Use currentIcon\": never };\n}\n\n/** A link in a NavigationRail: one of the app's top-level pages. */\nexport interface NavigationRailLinkItem extends NavigationRailItemBase {\n  /** Where it goes. Internal paths go through `OuroProvider`'s `linkComponent` (your router's link). */\n  href: string;\n  /**\n   * Other paths whose pages belong to this item, so it stays current there: a Chat item that\n   * also owns `/people`. Each matches its own path and the pages under it.\n   * @claim \"Each matches its own path\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:fileLine(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx, /\\[\"\\/people\",\\s\"Chat\"\\]/)\n   */\n  paths?: readonly string[] | undefined;\n  /** Called when the link is followed, before your router navigates. */\n  onClick?: ((event: MouseEvent<HTMLElement>) => void) | undefined;\n}\n\n/**\n * A button in a NavigationRail, for an app that switches views without its router: give the\n * shown view's item `current`.\n */\nexport interface NavigationRailButtonItem extends NavigationRailItemBase {\n  /** What the item does: show its view. */\n  onClick: (event: MouseEvent<HTMLElement>) => void;\n  /** Not with `onClick` alone. Give a link `href`; a button has none. */\n  href?: never;\n  /** Not on a button. A button is current by its `current` flag. */\n  paths?: never;\n}\n\n/** One item of a NavigationRail: a link (`href`) or a button (`onClick`). */\nexport type NavigationRailItem = NavigationRailLinkItem | NavigationRailButtonItem;\n\n/** A short rule between groups of items, as Menu's `{ type: \"separator\" }` is. */\nexport interface NavigationRailSeparator {\n  type: \"separator\";\n}\n\n/** One entry in a NavigationRail's `items`: an item, or a separator between groups. */\nexport type NavigationRailEntry = NavigationRailItem | NavigationRailSeparator;\n\n/** Props for {@link NavigationRail}. */\nexport interface NavigationRailProps {\n  /** Names the navigation for screen readers (\"Main\"). It is not shown. */\n  label: string;\n  /**\n   * The items, in order, with `{ type: \"separator\" }` between groups. Those that do not fit\n   * the rail's height move, from the last, into a More menu at its end; the current item stays\n   * on the rail.\n   */\n  items: readonly NavigationRailEntry[];\n  /**\n   * The path of the page being shown, from your router (`useLocation().pathname`, or\n   * `usePathname()` in Next.js). The item whose `href` or `paths` match it, or else the longest\n   * one above it (`/chat` for `/chat/12`), gets `aria-current=\"page\"` and the current look.\n   */\n  currentPath?: string | undefined;\n  /** Above the items: your app's mark, or a workspace `Menu`. */\n  header?: ReactNode;\n  /** Below the items, out of their way: a settings `Button` or an account `Menu`. */\n  footer?: ReactNode;\n  /**\n   * Shows the icons alone, in a 56px rail; each item's label names it for screen readers and\n   * shows in a Tooltip on hover and keyboard focus.\n   * @default false\n   * @claim \"Shows the icons alone\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > is 68px wide with labels and 56px with hideLabels, with items at least 44px tall)\n   * @claim \"Shows the icons alone\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail labels > with hideLabels, keeps each label as the item's name and shows it in a tooltip toward the page)\n   */\n  hideLabels?: boolean | undefined;\n  /**\n   * What screen readers hear after an item's label when it has a `count`, with `{count}` for the\n   * number: \"Activity, 5 new\".\n   * @default \"{count} new\"\n   */\n  countLabel?: string | undefined;\n  /** The label of the button that holds the items that do not fit. @default \"More\" */\n  moreLabel?: string | undefined;\n  /** Layout only: placement and width, or `max-sm:hidden` where a `TabBar` takes over. Appearance classes warn in development. */\n  className?: string | undefined;\n  /** Reaches the `<nav>`. */\n  ref?: Ref<HTMLElement> | undefined;\n\n  /** Not a prop. Ouro UI uses `items`: `<NavigationRail label=\"Main\" items={[{ label, href, icon }]} />`. */\n  links?: { 'Use <NavigationRail label=\"Main\" items={[{ label: \"Chat\", href: \"/chat\", icon: <ChatIcon /> }]} />': never };\n  /** Not a prop. Ouro UI uses `currentPath`: `<NavigationRail currentPath={pathname}>`. */\n  pathname?: { \"Use <NavigationRail currentPath={pathname}>\": never };\n  /** Not a prop. The current item follows `currentPath`, or an item's `current`. */\n  value?: { \"Use <NavigationRail currentPath={pathname}>, or current: true on the item\": never };\n  /** Not a prop. Mark the shown view's item `current: true`, and switch views in each item's `onClick`. */\n  selectedId?: { \"Use current: true on the item, and onClick to switch views\": never };\n  /** Not a prop. Give the items their own `onClick`. */\n  onSelect?: { \"Use onClick on each item\": never };\n  /** Not a prop. `hideLabels` shows the icons alone. */\n  collapsed?: { \"Use hideLabels\": never };\n  /** Not rendered. The rail is `items`, `header` and `footer`. */\n  children?: { \"Use items={[{ label, href, icon }]}, header={...} and footer={...}\": never };\n}\n\nconst example = '<NavigationRail label=\"Main\" items={[{ label: \"Chat\", href: \"/chat\", icon: <ChatIcon /> }]} />';\n\n/** The paths a link item owns, with the item's place in `items`, for `currentHref`. */\nfunction ownedPaths(entries: readonly NavigationRailEntry[]): Array<{ path: string; index: number }> {\n  return entries.flatMap((entry, index) => {\n    const { href, paths } = entry as Partial<NavigationRailLinkItem>;\n    // Stryker disable next-line ArrayDeclaration: a path that is no page's marks nothing, as no path does.\n    return href === undefined ? [] : [href, ...(paths ?? [])].map((path) => ({ path, index }));\n  });\n}\n\n/** A count worth showing: a positive number, whole. */\nfunction countOf(item: NavigationRailItem): number {\n  return Math.max(0, Math.floor(item.count ?? 0));\n}\n\n/**\n * Which separators show: the first of a run between two shown items. A separator with no shown\n * item before it, or none after it, hides.\n * @claim \"the first of a run\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail separators > hides a separator with no item before it or after it, and all but the first of a run)\n * @claim \"A separator with no\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail separators > hides a separator with no item before it or after it, and all but the first of a run)\n */\nfunction shownSeparators(entries: readonly NavigationRailEntry[], shown: (index: number) => boolean): Set<number> {\n  const separators = new Set<number>();\n  let afterItem = false;\n  let pending = -1;\n  entries.forEach((entry, index) => {\n    if (entry.type === \"separator\") {\n      if (afterItem) pending = index;\n      afterItem = false;\n    } else if (shown(index)) {\n      if (pending !== -1) separators.add(pending);\n      pending = -1;\n      afterItem = true;\n    }\n  });\n  return separators;\n}\n\n/** What the client measured: the places of the items moved under More and of the labels cut short, and the labels set a size smaller. */\ninterface Fit {\n  hidden: readonly number[];\n  truncated: readonly number[];\n  squeezed: readonly string[];\n}\n\nconst same = (a: readonly (number | string)[], b: readonly (number | string)[]) => a.join() === b.join();\n\n/** Whether a word of the label is wider than the label, so it runs past its edge or breaks within itself. */\nfunction wordTooWide(text: HTMLElement): boolean {\n  const words = text.firstChild!;\n  const range = document.createRange();\n  return [...words.textContent!.matchAll(/\\S+/g)].some((word) => {\n    range.setStart(words, word.index);\n    range.setEnd(words, word.index + word[0].length);\n    const lines = range.getClientRects();\n    // Stryker disable next-line EqualityOperator,ArithmeticOperator: a word within half a pixel of the label's width fits either way.\n    return lines.length > 1 || lines[0]!.width > text.clientWidth + 0.5;\n  });\n}\n\nconst rovingKeys = new Set([\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"]);\n\n/** What the rail looks like: an icon over its label, or the icon alone. */\ntype Look = \"labels\" | \"icons\";\n\n/** An item moved under More, with its place in `items`. */\ninterface MovedItem {\n  entry: NavigationRailItem;\n  index: number;\n}\n\n/** The development messages for props an agent guesses and for a missing or wordless label. */\nfunction guessedProps(props: NavigationRailProps): DevWarning[] {\n  const { label, items, countLabel = \"{count} new\", links, pathname, value, selectedId, onSelect, collapsed, children } = props;\n  const guessed = (name: \"badge\" | \"activeIcon\" | \"selectedIcon\") => items.find((entry) => entry.type !== \"separator\" && entry[name] !== undefined) as NavigationRailItem | undefined;\n  const badge = guessed(\"badge\");\n  const icon = guessed(\"activeIcon\") ?? guessed(\"selectedIcon\");\n  return [\n    !label && [\"label is required; it names the navigation for screen readers\", '<NavigationRail label=\"Main\">'],\n    links !== undefined && [\"links is not a prop\", example],\n    pathname !== undefined && [\"pathname is not a prop\", \"<NavigationRail currentPath={pathname}>\"],\n    value !== undefined && [\"value is not a prop; the current item follows the page's path\", \"<NavigationRail currentPath={pathname}>, or current: true on the item\"],\n    selectedId !== undefined && [\"selectedId is not a prop\", '{ label: \"Chat\", onClick: () => setView(\"chat\"), current: view === \"chat\" }'],\n    onSelect !== undefined && [\"onSelect is not a prop; each item has its own onClick\", '{ label: \"Chat\", onClick: () => setView(\"chat\") }'],\n    collapsed !== undefined && [\"collapsed is not a prop\", \"<NavigationRail hideLabels>\"],\n    children !== undefined && [\"children are not rendered\", example],\n    !countLabel.includes(\"{count}\") && [`countLabel \"${countLabel}\" has no {count}, so screen readers never hear the number`, 'countLabel=\"{count} new\"'],\n    badge !== undefined && [`badge is not an item prop (\"${badge.label}\")`, `{ label: \"${badge.label}\", count: 3 }`],\n    icon !== undefined && [`activeIcon and selectedIcon are not item props (\"${icon.label}\")`, `{ label: \"${icon.label}\", icon: <ChatIcon />, currentIcon: <ChatFilledIcon /> }`],\n  ];\n}\n\n// The current item's place, or -1: an item's own `current` wins; otherwise the path decides.\nfunction currentIndex(items: readonly NavigationRailEntry[], currentPath: string | undefined): number {\n  const flagged = items.findIndex((entry) => (entry as NavigationRailItem).current === true);\n  if (flagged !== -1) return flagged;\n  const owned = ownedPaths(items);\n  const match = currentHref(\n    owned.map((entry) => entry.path),\n    currentPath,\n  );\n  return match === undefined ? -1 : owned.find((entry) => entry.path === match)!.index;\n}\n\n/**\n * What the rail last measured: each entry's height, by key, so a hidden item still has one; the\n * list's width then; and whether the text has changed since (a font loaded), which no size shows.\n * @claim \"whether the text has changed since\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail fit > measures its labels again when a font loads, so a word the new face makes too wide is set smaller, never cut)\n */\ninterface Sizes {\n  heights: Map<string, number>;\n  width: number;\n  textChanged: boolean;\n  /** The list's row gap and height at the last measure, so a change of the current item fits arithmetically. */\n  gap: number;\n  room: number;\n}\n\n/** The items that stay on the list, worked out from cached sizes alone: the current one is kept, and room is left for More. */\nfunction keptItems(items: readonly NavigationRailEntry[], current: number, heights: ReadonlyMap<string, number>, gap: number, room: number): Set<number> {\n  const indexes = items.flatMap((entry, index) => (entry.type === \"separator\" ? [] : [index]));\n  /** The list's height with `shown` items on it, and More when `more`. */\n  const total = (shown: ReadonlySet<number>, more: boolean) => {\n    const separators = shownSeparators(items, (index) => shown.has(index));\n    const keys = [...[...shown].map(String), ...[...separators].map(() => \"separator\"), ...(more ? [\"more\"] : [])];\n    return keys.reduce((sum, key) => sum + (heights.get(key) ?? 0), 0) + gap * (keys.length - 1);\n  };\n  let kept = new Set(indexes);\n  // Stryker disable next-line EqualityOperator: heights are whole pixels and gaps CSS lengths, so a total is never exactly half a pixel over.\n  if (total(kept, false) > room + 0.5) {\n    kept = new Set(current === -1 ? [] : [current]);\n    for (const index of indexes) {\n      if (index === current) continue;\n      kept.add(index);\n      // Stryker disable next-line EqualityOperator: as above, a total is never exactly half a pixel over.\n      if (total(kept, true) > room + 0.5) {\n        kept.delete(index);\n        break;\n      }\n    }\n  }\n  return kept;\n}\n\n/** The heights the fit adds up, with the tallest known size standing in for an item not measured yet (one hidden since it first rendered), until the observer reports its own. Empty when nothing is measured. */\nfunction estimated(items: readonly NavigationRailEntry[], heights: ReadonlyMap<string, number>): Map<string, number> {\n  const filled = new Map(heights);\n  // Stryker disable next-line MethodExpression,ArrayDeclaration,ArrowFunction,ConditionalExpression,LogicalOperator,EqualityOperator,StringLiteral: the stand-in only matters for an item hidden since it first rendered, which a measure never leaves unmeasured.\n  const tallest = Math.max(0, ...[...heights].filter(([key]) => key !== \"more\" && key !== \"separator\").map(([, height]) => height));\n  // Stryker disable next-line ConditionalExpression,BlockStatement: every measure stores More first, so an unmeasured rail never gets here with sizes.\n  if (!heights.has(\"more\")) return new Map();\n  // Stryker disable next-line BlockStatement,CallExpression,ArrowFunction: see the stand-in above.\n  items.forEach((entry, index) => {\n    // Stryker disable next-line ConditionalExpression,LogicalOperator,EqualityOperator,StringLiteral,BooleanLiteral,CallExpression: see the stand-in above.\n    /* istanbul ignore next @preserve -- an item hidden since it first rendered has no size until it shows once; every measure here shows all first */ if (entry.type !== \"separator\" && !filled.has(String(index))) filled.set(String(index), tallest);\n  });\n  return filled;\n}\n\n// What fits the laid-out list: the items that move under More, from the last, with the current\n// one kept, and the labels cut short. When the list's width, a shown entry's height or the text\n// changed (the rail widened, the text size changed, a label changed, a font loaded), a hidden\n// entry's height is stale: it counts nothing until it shows again, and the measure that follows\n// puts it back if it does not fit.\nfunction measureFit(element: HTMLUListElement, items: readonly NavigationRailEntry[], current: number, sizes: Sizes): Fit {\n  const { heights } = sizes;\n  const measured = new Map<string, number>();\n  for (const child of element.children) {\n    const height = (child as HTMLElement).offsetHeight;\n    if (height > 0) measured.set((child as HTMLElement).dataset.ouroNavigationRailEntry!, height);\n  }\n  const width = element.clientWidth;\n  // Stryker disable next-line MethodExpression: some and every differ only when some shown heights change and others do not, as when one label changes, which leaves the hidden heights as they were.\n  const resized = [...measured].some(\n    ([key, height]) =>\n      // Stryker disable next-line ConditionalExpression: an entry measured for the first time that counted as resized too only shows the hidden ones once more, and the fit settles where it would.\n      heights.has(key) && heights.get(key) !== height,\n  );\n  if (resized || width !== sizes.width || sizes.textChanged) heights.clear();\n  for (const [key, height] of measured) heights.set(key, height);\n  sizes.width = width;\n  sizes.textChanged = false;\n  const gap = parseFloat(getComputedStyle(element).rowGap);\n  const room = element.clientHeight;\n  sizes.gap = gap;\n  sizes.room = room;\n  const indexes = items.flatMap((entry, index) => (entry.type === \"separator\" ? [] : [index]));\n  // More is not on the list until something hides, so its height stands in as the tallest item's: the first measure then leaves room for it.\n  const withMore = new Map(heights);\n  // Stryker disable next-line ConditionalExpression,StringLiteral: the stand-in only saves a later re-measure; the fit that settles is the same without it\n  if (!withMore.has(\"more\")) withMore.set(\"more\", Math.max(0, ...[...measured.values()]));\n  const kept = keptItems(items, current, withMore, gap, room);\n  // Labels hidden under More, or by hideLabels, measure nothing and are never set smaller.\n  // The labels of items about to move under More are left out too, so the one measure gives the fit that settles.\n  // Stryker disable next-line MethodExpression: the spread only makes the NodeList an array; the filter that follows keeps the same labels\n  const shownLabels = [...element.querySelectorAll<HTMLElement>(\"[data-ouro-navigation-rail-label]\")].filter((text) => kept.has(Number(text.dataset.ouroNavigationRailLabel)));\n  const labels = shownLabels.filter((text) => text.clientWidth > 1);\n  const isSqueezed = (text: HTMLElement) => text.hasAttribute(\"data-ouro-navigation-rail-squeezed\");\n  return {\n    hidden: indexes.filter((index) => !kept.has(index)),\n    // A label cut short: by its two lines, or by a word too wide even a size smaller, which breaks within it. (A word too\n    // wide at the label's own size sets it smaller first.)\n    truncated: shownLabels\n      .filter((text) => text.scrollHeight > text.clientHeight || (isSqueezed(text) && wordTooWide(text)))\n      .map((text) => Number(text.dataset.ouroNavigationRailLabel)),\n    // A label with a word too wide is set a size smaller, and stays so while its words stay the same: a size smaller, it would measure as fitting.\n    squeezed: labels.filter((text) => isSqueezed(text) || wordTooWide(text)).map((text) => text.firstChild!.textContent!),\n  };\n}\n\n/**\n * What decides the fit, besides sizes: the entries' labels in order, the current item, whether\n * labels show, More's label, the rail's classes and the last fit. A count or an icon changes none\n * of it, nor does a render with the same items.\n * @claim \"A count or an icon changes none\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail fit > lays nothing out when it renders again with only a new count, or with the same items)\n */\nfunction fitInputs(items: readonly NavigationRailEntry[], current: number, hideLabels: boolean, moreLabel: string, className: string | undefined): string {\n  // A separator has no label, which JSON writes as null.\n  return JSON.stringify([items.map((entry) => (entry as { label?: string }).label), current, hideLabels, moreLabel, className]);\n}\n\n// The fit of the rail's list, measured before paint when what decides it changes, and when the\n// list or an entry changes size. A measure reads layout, which inside a commit lays the page out at\n// once, so the first commit (server HTML hydrating, or a client mount) and a render that changes no\n// input measure nothing. The resize observer, whose callback runs once the page is laid out and\n// reports each element it starts to watch, measures then, before the first paint, and sets a fit\n// only when it differs: a rail whose items fit renders once, and one that overflows paints with its\n// items already under More.\nfunction useFit(list: { readonly current: HTMLUListElement | null }, items: readonly NavigationRailEntry[], current: number, inputs: string, others: string): Fit {\n  // Stryker disable next-line ArrayDeclaration: a place that is no item's moves and cuts nothing, as an empty list does.\n  const [fit, setFit] = useState<Fit>({ hidden: [], truncated: [], squeezed: [] });\n  // One not yet measured counts nothing until it shows, and the measure that follows corrects the fit before paint.\n  // Stryker disable next-line BooleanLiteral: the first measure has no heights to forget, whatever this says.\n  // Stryker disable next-line ObjectLiteral,BooleanLiteral: sizes start empty and the first measure fills every field.\n  const sizes = useRef<Sizes>({ heights: new Map(), width: 0, textChanged: false, gap: 0, room: 0 });\n  const measure = useRef<() => void>(null);\n  const observer = useRef<ResizeObserver | null>(null);\n  const observed = useRef(new WeakSet<Element>());\n  // The fit the last commit showed, so a measure that finds it again renders nothing.\n  const shown = useRef(fit);\n  const committed = useRef(false);\n  // What the last effect ran for, and whether its fit came from sizes alone.\n  // Stryker disable next-line ObjectLiteral: the first commit only records what it ran for; no branch reads it before a later commit sets it.\n  const last = useRef({ others, current });\n  // Stryker disable next-line BooleanLiteral: the first commit never reads it before it is set.\n  const fromSizes = useRef(false);\n  // Every later commit measures before paint, so a change never shows items that do not fit. The\n  // observer calls the latest measure, which reads the entries and current item of the render that\n  // set it: until `inputs` change, any later render's give the same fit.\n  useLayoutEffect(() => {\n    shown.current = fit;\n    measure.current = () => {\n      const element = list.current!;\n      // Not laid out (hidden by the app): nothing to measure.\n      if (element.getClientRects().length === 0) return;\n      const next = measureFit(element, items, current, sizes.current);\n      const last = shown.current;\n      const moved = !same(last.hidden, next.hidden) || !same(last.truncated, next.truncated);\n      // Stryker disable next-line LogicalOperator,ConditionalExpression: a name left in `squeezed` sets no label smaller until a label of that name, as wide, comes back.\n      if (!moved && same(last.squeezed, next.squeezed)) return;\n      shown.current = next;\n      setFit(next);\n    };\n    // Its callback runs after layout and before paint, so a fit it finds commits there, and the frame paints it.\n    observer.current ??= new ResizeObserver(() => flushSync(() => measure.current!()));\n    // Each element once: observing one again makes the observer report it again (WebKit does) and measure for nothing.\n    for (const element of [list.current!, ...list.current!.children]) {\n      // Stryker disable next-line ConditionalExpression: in Chromium, observing an element again does nothing; elsewhere the measure it starts finds the same fit.\n      if (observed.current.has(element)) continue;\n      // Stryker disable next-line CallExpression: as above, an element observed again changes no fit.\n      observed.current.add(element);\n      observer.current.observe(element);\n    }\n    const before = last.current;\n    // Stryker disable next-line ObjectLiteral: see the ref above.\n    last.current = { others, current };\n    if (committed.current) {\n      // Stryker disable next-line ConditionalExpression,LogicalOperator,EqualityOperator: a measure after a fit from sizes finds the same fit and renders nothing.\n      const settled = fromSizes.current && before.others === others && before.current === current;\n      // Stryker disable next-line ConditionalExpression,EqualityOperator: without sizes the arithmetic fit is empty, and the measure that follows corrects it before paint.\n      if (before.others === others && before.current !== current && sizes.current.heights.size > 0) {\n        // Only the current item changed: what fits follows from the sizes the observer keeps current, and a layout read inside the commit would lay the page out.\n        const filled = estimated(items, sizes.current.heights);\n        const kept = keptItems(items, current, filled, sizes.current.gap, sizes.current.room);\n        // Stryker disable next-line ConditionalExpression,LogicalOperator,EqualityOperator,ArrayDeclaration,ArrowFunction,BlockStatement,StringLiteral,BooleanLiteral: the observer's measure that follows corrects any fit the sizes get wrong before paint, so only the final fit shows.\n        const hidden = items.flatMap((entry, index) => (entry.type === \"separator\" || kept.has(index) ? [] : [index]));\n        // Stryker disable next-line ConditionalExpression,BlockStatement: as above.\n        if (!same(shown.current.hidden, hidden)) {\n          // Stryker disable next-line BooleanLiteral: as above.\n          fromSizes.current = true;\n          shown.current = { ...shown.current, hidden };\n          setFit(shown.current);\n        }\n      }\n      else {\n        // The fit that just rendered came from sizes: the items it shows or hides report their new sizes to the observer, which measures once the page is laid out.\n        // Stryker disable next-line ConditionalExpression,BlockStatement: a measure the observer starts after a fit from sizes finds the same fit and renders nothing.\n        if (settled) {\n          // Stryker disable next-line BooleanLiteral,BlockStatement: as above.\n          fromSizes.current = false;\n        } else {\n          fromSizes.current = false;\n          measure.current!();\n        }\n      }\n    }\n    committed.current = true;\n    // A new fit can change sizes the measure read (More shows, a label is set smaller), so it measures again.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [inputs, current, fit]);\n  // A font that loads changes the labels' widths, and maybe nothing the observer sees, so the rail measures again once\n  // the fonts are ready, outside any commit, where the page lays out the new text anyway. (WebKit sends no\n  // loadingdone for a face it finds at once, only loading.)\n  useLayoutEffect(\n    () => {\n      const fonts = list.current!.ownerDocument.fonts;\n      const loading = () =>\n        void fonts.ready.then(() => {\n          // Unmounted while the fonts loaded: nothing to measure.\n          if (list.current === null) return;\n          sizes.current.textChanged = true;\n          measure.current!();\n        });\n      fonts.addEventListener(\"loading\", loading);\n      return () => {\n        // Stryker disable next-line StringLiteral,CallExpression: a listener left behind finds the rail gone when the fonts are ready, and measures nothing.\n        fonts.removeEventListener(\"loading\", loading);\n        observer.current!.disconnect();\n        observed.current = new WeakSet();\n      };\n    },\n    // Stryker disable next-line ArrayDeclaration: the list's ref is the same object for the rail's life, so any constant list runs it once, as this one does.\n    [list],\n  );\n  return fit;\n}\n\n/** The rail's keys: Up and Down move along its shown stops, wrapping, and Home and End go to the ends. */\nfunction moveAlongRail(event: KeyboardEvent<HTMLUListElement>) {\n  // ⌘↑ and ⌘↓ on a Mac are its Home and End.\n  const key = navigationKey(event);\n  // A modified key the rail leaves alone is null, which no roving key is.\n  if (!rovingKeys.has(key as string)) return;\n  const stops = [...event.currentTarget.querySelectorAll<HTMLElement>(\"[data-ouro-navigation-rail-stop]\")].filter((element) => element.getClientRects().length > 0);\n  const at = stops.indexOf(event.target as HTMLElement);\n  if (at === -1) return;\n  event.preventDefault();\n  const to = key === \"ArrowDown\" ? at + 1 : key === \"ArrowUp\" ? at - 1 : key === \"Home\" ? 0 : stops.length - 1;\n  stops[(to + stops.length) % stops.length]!.focus();\n}\n\n\n/** `element` in a Tooltip of `text` toward the page when `show`. */\nfunction withTip(show: boolean, text: string, element: ReactElement): ReactElement {\n  return show ? (\n    <Tooltip content={text} side=\"right\">\n      {element}\n    </Tooltip>\n  ) : (\n    element\n  );\n}\n\n/**\n * An item's inside: the bar, the icon with its count, and the label. The item is named by its\n * words: the label, then the count as `countLabel` speaks it, \"Activity, 5 new\", so its name starts\n * with the words it shows. The badge itself is hidden.\n */\nfunction itemInside(text: string, icon: ReactNode, count: number, countLabel: string, index: number | undefined, hideLabels: boolean, squeezed: boolean, selected = false) {\n  return (\n    <>\n      {/* The bar says it is selected itself: it is the part that moves when its item becomes current. */}\n      <span aria-hidden=\"true\" data-ouro-part=\"indicator\" data-selected={selected ? \"true\" : undefined} className={indicatorClass} />\n      <span aria-hidden=\"true\" className={iconClass}>\n        {icon}\n        {count > 0 && (\n          <span data-ouro-navigation-rail-count=\"\" className={countClass}>\n            {shownCount(count)}\n          </span>\n        )}\n      </span>\n      <span\n        data-ouro-navigation-rail-label={index}\n        data-ouro-navigation-rail-squeezed={squeezed || undefined}\n        className={hideLabels ? \"sr-only\" : labelClass[squeezed ? \"squeezed\" : \"fits\"]}\n      >\n        {text}\n        {count > 0 && <span className={spokenCountClass}>, {countLabel.replace(\"{count}\", String(count))}</span>}\n      </span>\n    </>\n  );\n}\n\n/** One entry of the rail: a separator, or an item's link or button, in a Tooltip when its label does not show whole. */\nfunction RailEntry({\n  entry,\n  index,\n  current,\n  stop,\n  look,\n  hideLabels,\n  countLabel,\n  hidden,\n  truncated,\n  squeezed,\n  separatorShown,\n  onFocus,\n}: {\n  entry: NavigationRailEntry;\n  index: number;\n  current: number;\n  stop: string | undefined;\n  look: Look;\n  hideLabels: boolean;\n  countLabel: string;\n  hidden: boolean;\n  truncated: boolean;\n  squeezed: ReadonlySet<string>;\n  separatorShown: boolean;\n  onFocus: (key: string) => void;\n}) {\n  if (entry.type === \"separator\") {\n    return (\n      <li aria-hidden=\"true\" data-ouro-navigation-rail-entry=\"separator\" className={cn(\"block shrink-0 py-1\", !separatorShown && \"hidden\")}>\n        <span className={separatorClass} />\n      </li>\n    );\n  }\n  const isCurrent = index === current;\n  const count = countOf(entry);\n  const key = String(index);\n  const shared = {\n    \"aria-current\": isCurrent ? (\"page\" as const) : undefined,\n    // \"true\", the only form shadcn's data-selected variant matches; Tailwind's matches any.\n    \"data-selected\": isCurrent ? \"true\" : undefined,\n    \"data-ouro-navigation-rail-stop\": key,\n    tabIndex: key === stop ? 0 : -1,\n    onFocus: () => onFocus(key),\n    className: itemClass[look],\n  };\n  const content = itemInside(entry.label, isCurrent && entry.currentIcon !== undefined ? entry.currentIcon : entry.icon, count, countLabel, index, hideLabels, squeezed.has(entry.label), isCurrent);\n  return (\n    <li data-ouro-navigation-rail-entry={key} className={cn(\"flex shrink-0\", hidden && \"hidden\")}>\n      {withTip(\n        hideLabels || truncated,\n        entry.label,\n        entry.href !== undefined ? (\n          <RouterLink data-ouro-control=\"navigation-rail\" data-ouro-part=\"link\" href={entry.href} onClick={entry.onClick} {...shared}>\n            {content}\n          </RouterLink>\n        ) : (\n          <button data-ouro-control=\"navigation-rail\" data-ouro-part=\"button\" type=\"button\" onClick={entry.onClick} {...shared}>\n            {content}\n          </button>\n        ),\n      )}\n    </li>\n  );\n}\n\n/** The More button at the rail's end and its Menu of the items that do not fit. */\nfunction MoreEntry({\n  items,\n  moved,\n  look,\n  hideLabels,\n  moreLabel,\n  countLabel,\n  squeezed,\n  isStop,\n  onFocus,\n}: {\n  items: readonly NavigationRailEntry[];\n  moved: readonly MovedItem[];\n  look: Look;\n  hideLabels: boolean;\n  moreLabel: string;\n  countLabel: string;\n  squeezed: boolean;\n  isStop: boolean;\n  onFocus: () => void;\n}) {\n  const movedCount = moved.reduce((sum, { entry }) => sum + countOf(entry), 0);\n  return (\n    <li data-ouro-navigation-rail-entry=\"more\" className=\"flex shrink-0\">\n      <Menu\n        side=\"right\"\n        trigger={withTip(\n          hideLabels,\n          moreLabel,\n          <button\n            type=\"button\"\n            data-ouro-control=\"navigation-rail\"\n            data-ouro-part=\"more\"\n            data-ouro-navigation-rail-stop=\"more\"\n            tabIndex={isStop ? 0 : -1}\n            onFocus={onFocus}\n            // The trigger's own keys are off, since the arrows (which would open the menu) move along\n            // the rail; Enter and Space press the button, which opens it.\n            onKeyDown={(event: KeyboardEvent<HTMLButtonElement>) => (event as typeof event & { preventBaseUIHandler: () => void }).preventBaseUIHandler()}\n            className={itemClass[look]}\n          >\n            {itemInside(\n              moreLabel,\n              <svg viewBox=\"0 0 24 24\" fill=\"currentColor\">\n                <circle cx=\"5\" cy=\"12\" r=\"1.75\" />\n                <circle cx=\"12\" cy=\"12\" r=\"1.75\" />\n                <circle cx=\"19\" cy=\"12\" r=\"1.75\" />\n              </svg>,\n              movedCount,\n              countLabel,\n              undefined,\n              hideLabels,\n              squeezed,\n            )}\n          </button>,\n        )}\n      >\n        {moved.map(({ entry, index }, at) => {\n          const count = countOf(entry);\n          const previous = moved[at - 1];\n          const separated = previous !== undefined && items.slice(previous.index, index).some((between) => between.type === \"separator\");\n          return [\n            // Stryker disable next-line StringLiteral: the separator's only sibling is the item, keyed by its number, so any other key is unique.\n            separated && <MenuSeparator key={`separator-${index}`} />,\n            <MenuItem key={index} href={entry.href} onClick={entry.onClick}>\n              {entry.label}\n              {count > 0 && (\n                <>\n                  <span aria-hidden=\"true\" className={menuCountClass}>\n                    {shownCount(count)}\n                  </span>\n                  <span className=\"sr-only\">, {countLabel.replace(\"{count}\", String(count))}</span>\n                </>\n              )}\n            </MenuItem>,\n          ];\n        })}\n      </Menu>\n    </li>\n  );\n}\n\n/**\n * The vertical bar of the app's top-level pages on the start edge of a wide screen, as in a\n * chat or mail app or an editor's activity bar: each item an icon over a short label, the\n * current one with its `currentIcon`, a bar on the rail's edge and `aria-current=\"page\"`. An\n * item can carry a `count`, capped at \"99+\" on the badge and spoken in full, be a button for\n * an app that switches views without its router (`onClick` without `href`), and sit after a\n * `{ type: \"separator\" }`. A `header` (your app's mark) sits above the items and a `footer`\n * (settings, the account) below them.\n *\n * The rail is one tab stop: Up and Down move between its items, wrapping, and Home and End go\n * to the ends, while Tab moves on to the footer and the page. Items that do not fit the rail's\n * height move, from the last, into a More menu at its end; the current item stays on the rail.\n * Labels wrap to two lines between words; one still too long ends in an ellipsis and shows whole\n * in a Tooltip, as every label does with `hideLabels`. The current item's bar grows in from its\n * middle; with reduced motion it only fades.\n *\n * Links render through `OuroProvider`'s `linkComponent`, so your router navigates. The rail\n * fills its container's height and draws no surface of its own, so it sits on your app's\n * frame.\n *\n * Use `TabBar` instead for the bar at the bottom of a phone screen (hide the rail there with\n * `className=\"max-sm:hidden\"`), `Sidebar` for a column of labelled links in sections, and\n * `Navbar` for a few links across the top.\n *\n * @group Navigation\n * @see https://ui.ouroboros.bot/docs/navigation-rail\n * @claim \"The vertical bar of\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > is a labelled navigation with a list of links, each named by its label, with the icons hidden)\n * @claim \"The vertical bar of\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > shows the current item's bar on the rail's start edge, its label in the foreground colour and its icon in the primary colour)\n * @claim \"The vertical bar of\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > draws the current item's currentIcon, and its icon when it has none)\n * @claim \"Labels wrap to two lines\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail labels > wraps a long label to two lines between words, and gives a label that still does not fit an ellipsis and a tooltip)\n * @claim \"Labels wrap to two lines\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail labels > with hideLabels, keeps each label as the item's name and shows it in a tooltip toward the page)\n * @claim \"The rail fills its\" registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx verify:testExists(registry/ouro/components/ouro/navigation-rail/navigation-rail.test.tsx::NavigationRail > fills its container's height and draws no surface of its own)\n *\n * @example\n * <NavigationRail\n *   label=\"Main\"\n *   currentPath={pathname}\n *   header={<AppMark />}\n *   items={[\n *     { label: \"Activity\", href: \"/activity\", icon: <BellIcon />, currentIcon: <BellFilledIcon />, count: 3 },\n *     { label: \"Chat\", href: \"/chat\", icon: <ChatIcon />, currentIcon: <ChatFilledIcon /> },\n *     { label: \"Calendar\", href: \"/calendar\", icon: <CalendarIcon /> },\n *     { type: \"separator\" },\n *     { label: \"Files\", href: \"/files\", icon: <FolderIcon /> },\n *   ]}\n *   footer={<SettingsButton />}\n * />\n */\nexport function NavigationRail(props: NavigationRailProps): JSX.Element {\n  const { label, items, currentPath, header, footer, hideLabels = false, countLabel = \"{count} new\", moreLabel = \"More\", className, ref } = props;\n  useAppearanceClassNameCheck(\n    \"NavigationRail\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; NavigationRail sets its own look from the theme`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\"NavigationRail\", process.env.NODE_ENV !== \"production\" ? () => guessedProps(props) : /* istanbul ignore next @preserve -- production only */ undefined);\n\n  const current = currentIndex(items, currentPath);\n  const nav = useRef<HTMLElement>(null);\n  const navRef = useMergedRef(ref, nav);\n  const list = useRef<HTMLUListElement>(null);\n  // Stryker disable next-line UnaryOperator: -2 only stands for \"no current item\"; +2 is as absent from the rail's items.\n  const fit = useFit(list, items, current, fitInputs(items, current, hideLabels, moreLabel, className), fitInputs(items, -2, hideLabels, moreLabel, className));\n  // Indexed once per measure, which keeps its last result while nothing moves.\n  const { hidden, truncated, squeezed } = useMemo(() => ({ hidden: new Set(fit.hidden), truncated: new Set(fit.truncated), squeezed: new Set(fit.squeezed) }), [fit]);\n\n  // Roving tab stop: the item focused last, else the current one, else the first.\n  const [focused, setFocused] = useState<string | null>(null);\n  // The items measure moved under More. A place left over from earlier items is put right before paint.\n  const moved = items.flatMap((entry, index) => (hidden.has(index) ? [{ entry: entry as NavigationRailItem, index }] : []));\n  // Stryker disable next-line ArrayDeclaration: only a key a stop has ever focused is looked up here, so an extra key is never found.\n  const stops = [...items.flatMap((entry, index) => (entry.type === \"separator\" || hidden.has(index) ? [] : [String(index)])), ...(moved.length > 0 ? [\"more\"] : [])];\n  const stop = stops.find((key) => key === focused) ?? (current === -1 ? stops[0] : String(current));\n\n  const look: Look = hideLabels ? \"icons\" : \"labels\";\n  const shownSeparatorSet = shownSeparators(items, (index) => !hidden.has(index));\n\n  return (\n    <nav ref={navRef} data-ouro=\"navigation-rail\" aria-label={label} className={cn(railClass[look], className)}>\n      {header !== undefined && <div className={headerClass}>{header}</div>}\n      <ul ref={list} className={listClass} onKeyDown={moveAlongRail}>\n        {items.map((entry, index) => (\n          <RailEntry\n            key={index}\n            entry={entry}\n            index={index}\n            current={current}\n            stop={stop}\n            look={look}\n            hideLabels={hideLabels}\n            countLabel={countLabel}\n            hidden={hidden.has(index)}\n            truncated={truncated.has(index)}\n            squeezed={squeezed}\n            separatorShown={shownSeparatorSet.has(index)}\n            onFocus={setFocused}\n          />\n        ))}\n        {moved.length > 0 && (\n          <MoreEntry items={items} moved={moved} look={look} hideLabels={hideLabels} moreLabel={moreLabel} countLabel={countLabel} squeezed={squeezed.has(moreLabel)} isStop={stop === \"more\"} onFocus={() => setFocused(\"more\")} />\n        )}\n      </ul>\n      {footer !== undefined && <div className={footerClass}>{footer}</div>}\n    </nav>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/navigation-rail/navigation-rail.tsx"
    }
  ],
  "docs": "The vertical bar of the app's top-level pages on the start edge of a wide screen, as in a chat or mail app or an editor's activity bar: each item an icon over a short label, the current one with its `currentIcon`, a bar on the rail's edge and `aria-current=\"page\"`. Import: import { NavigationRail } from \"@/components/ouro/navigation-rail/navigation-rail\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: kbd, menu, tooltip, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/navigation-rail.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}