{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tab-bar",
  "title": "TabBar",
  "description": "The bar of tabs at the bottom of a phone screen: two to five of the app's top-level pages, each an icon over a short label, with the current page marked `aria-current=\"page\"` and an accent wash.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-current-path",
    "@ouro/lib-env",
    "@ouro/lib-router-link",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/tab-bar/tab-bar-styles.ts",
      "content": "export { accessoryClass, barClass, breakpoints, iconClass, labelClass, listClass, rootClass, tabClass };\n\n// Class strings are literal so the app's Tailwind finds them when it compiles.\n\n/**\n * The root holds the bar's room at the end of the page, so the last of the content scrolls\n * clear of it: the bar's 64px, the gap above it and the gap below it (at least the phone's\n * home-indicator inset). The bar itself is fixed to the bottom of the screen.\n * @claim \"The root holds the bar's room\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx::TabBar > sits fixed at the bottom of a phone screen, with equal 64px tabs, and keeps its room in the page)\n */\nconst rootClass = \"block h-[calc(5rem+max(1rem,env(safe-area-inset-bottom,0px)))] shrink-0 print:hidden\";\n\n/** Where the bar hides, because the app's Navbar or Sidebar takes over from there. */\nconst breakpoints = {\n  sm: \"sm:hidden\",\n  md: \"md:hidden\",\n  lg: \"lg:hidden\",\n  xl: \"xl:hidden\",\n  never: \"\",\n} as const;\n\n/**\n * The bar, fixed to the bottom of the screen. While the on-screen keyboard is up\n * (`data-closed`) it slides below the screen and fades; with reduced motion it fades in place.\n */\nconst barClass =\n  \"fixed inset-x-0 bottom-0 z-(--ouro-layer) mx-auto mb-[max(1rem,env(safe-area-inset-bottom,0px))] box-border flex max-w-lg items-center gap-2 \" +\n  \"ps-[max(0.75rem,env(safe-area-inset-left,0px))] pe-[max(0.75rem,env(safe-area-inset-right,0px))] \" +\n  \"transition-[translate,opacity] duration-(--ouro-duration-base) ease-(--ouro-ease-out) \" +\n  \"data-closed:pointer-events-none data-closed:translate-y-[calc(100%+max(1rem,env(safe-area-inset-bottom,0px)))] data-closed:opacity-0 \" +\n  \"motion-reduce:transition-opacity motion-reduce:duration-(--ouro-duration-fast) motion-reduce:data-closed:translate-y-0\";\n\n/**\n * One solid surface for the tabs and the accessory, so no page content shows through.\n *\n * @claim \"One solid surface for the tabs\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx::TabBar > sits fixed at the bottom of a phone screen, with equal 64px tabs, and keeps its room in the page)\n */\nconst surface = \"bg-popover text-muted-foreground ring-1 ring-border/60 shadow-(--shadow-lg) forced-colors:border forced-colors:border-solid\";\n\nconst listClass = `m-0 box-border flex h-16 min-w-0 flex-1 list-none items-stretch rounded-full p-1 ${surface}`;\n\n/**\n * A tab: the icon over a short label. The current page's tab has the accent wash; a press\n * scales it (not with reduced motion), and the colors change at once.\n */\nconst tabClass =\n  \"press relative box-border flex min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-full px-0.5 no-underline \" +\n  \"text-muted-foreground select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"pointer-fine:hover:text-foreground aria-[current=page]:bg-accent aria-[current=page]:text-accent-foreground \" +\n  \"forced-colors:aria-[current=page]:outline-2 forced-colors:aria-[current=page]:outline-solid \" +\n  \"motion-safe:active:scale-(--ouro-press-scale) outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\";\n\nconst iconClass = \"flex size-[1.375rem] shrink-0 items-center justify-center [&>svg]:size-full\";\n\nconst labelClass = \"max-w-full truncate text-[0.6875rem] leading-none font-semibold tracking-[0.01em]\";\n\n/** The accessory sits apart in a circle of its own, as tall as the bar. */\nconst accessoryClass =\n  `press relative box-border grid size-16 shrink-0 place-items-center rounded-full no-underline ${surface} ` +\n  \"select-none touch-manipulation [-webkit-tap-highlight-color:transparent] \" +\n  \"pointer-fine:hover:text-foreground aria-[current=page]:bg-accent aria-[current=page]:text-accent-foreground \" +\n  \"forced-colors:aria-[current=page]:outline-2 forced-colors:aria-[current=page]:outline-solid \" +\n  \"motion-safe:active:scale-(--ouro-press-scale) outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\";\n",
      "type": "registry:ui",
      "target": "@components/ouro/tab-bar/tab-bar-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/tab-bar/tab-bar.tsx",
      "content": "\"use client\";\n\nimport { useSyncExternalStore, type JSX, 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 { RouterLink } from \"@/registry/ouro/lib/ouro/router-link\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport {\n  accessoryClass,\n  barClass,\n  breakpoints,\n  iconClass,\n  labelClass,\n  listClass,\n  rootClass,\n  tabClass,\n} from \"@/registry/ouro/components/ouro/tab-bar/tab-bar-styles\";\n\n/** One tab in a TabBar: a page of the app, with its icon and a short label. */\nexport interface TabBarItem {\n  /** The tab's text, one short word under the icon: \"Recipes\". Screen readers hear it as the link's name. */\n  label: string;\n  /** Where the tab goes. Internal paths go through `OuroProvider`'s `linkComponent` (your router's link). */\n  href: string;\n  /** The tab's icon, an `<svg>` (a lucide-react icon, for example). It is hidden from screen readers; the label names the tab. */\n  icon: ReactNode;\n  /**\n   * Other paths whose pages belong to this tab, so it stays current there: a Home tab that\n   * also owns `/account`. Each matches its own path and the pages under it.\n   * @claim \"Each matches its own path and\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:fileLine(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx, /\\[\"/account/settings\",\\s\"Home\"\\]/)\n   */\n  paths?: readonly string[] | undefined;\n  /** Marks this tab as the current page (`aria-current=\"page\"`), when the paths cannot tell. */\n  current?: boolean | undefined;\n}\n\n/** Props for {@link TabBar}. */\nexport interface TabBarProps {\n  /** Names the navigation for screen readers (\"Main\"). It is not shown. */\n  label: string;\n  /**\n   * The tabs, in order: two to five of the app's top-level pages.\n   *\n   * @claim \"The tabs, in order: two to\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:fileLine(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx, /6\\stabs\\sdo\\snot\\sfit\\sa\\sphone's\\swidth/)\n   */\n  items: readonly TabBarItem[];\n  /**\n   * An item that sits apart, in a circle of its own at the end of the bar, as iOS sets\n   * Search apart from the tabs. Only its icon shows; its `label` names it for screen readers.\n   */\n  accessory?: TabBarItem | undefined;\n  /**\n   * The path of the page being shown, from your router (`useLocation().pathname`, or\n   * `usePathname()` in Next.js). The tab whose `href` or `paths` match it, or else the longest\n   * one above it (`/recipes` for `/recipes/12`), gets `aria-current=\"page\"` and the current look.\n   */\n  currentPath?: string | undefined;\n  /**\n   * The breakpoint from which the bar hides, because the app's `Navbar` or `Sidebar` takes over\n   * there. `never` keeps it at every width.\n   * @default \"sm\"\n   * @claim \"`never` keeps it at every width\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:fileLine(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx, /hides\\sfrom\\s%s\\s\\(%ipx\\),\\sand\\swith\\snever\\sstays/)\n   */\n  hideFrom?: \"sm\" | \"md\" | \"lg\" | \"xl\" | \"never\" | (string & { 'Use \"sm\", \"md\", \"lg\", \"xl\" or \"never\"': never }) | undefined;\n  /** Layout only: rarely needed, since the bar places itself. 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`: `<TabBar label=\"Main\" items={[{ label, href, icon }]} />`. */\n  tabs?: { 'Use <TabBar label=\"Main\" items={[{ label: \"Recipes\", href: \"/recipes\", icon: <BookOpen /> }]} />': never };\n  /** Not a prop. Ouro UI uses `items`: `<TabBar label=\"Main\" items={[{ label, href, icon }]} />`. */\n  links?: { 'Use <TabBar label=\"Main\" items={[{ label: \"Recipes\", href: \"/recipes\", icon: <BookOpen /> }]} />': never };\n  /** Not a prop. Ouro UI uses `currentPath`: `<TabBar currentPath={pathname}>`. */\n  pathname?: { 'Use <TabBar currentPath={pathname}>': never };\n  /** Not a prop. The current tab follows `currentPath`, or an item's `current`: `<TabBar currentPath={pathname}>`. */\n  value?: { 'Use <TabBar currentPath={pathname}>, or current: true on the item': never };\n  /** Not rendered. The bar is `items` and `accessory`. */\n  children?: { 'Use items={[{ label, href, icon }]} and accessory={{ label, href, icon }}': never };\n}\n\nconst example = '<TabBar label=\"Main\" items={[{ label: \"Recipes\", href: \"/recipes\", icon: <BookOpen /> }]} />';\n\n/**\n * How much of the screen a keyboard covers, at the least: more than a browser's own toolbars, which also shrink the visual viewport.\n *\n * @claim \"How much of the screen a\" registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx::TabBar and the on-screen keyboard > slides away while the keyboard shrinks the visual viewport, even with no field focused, but not for a zoom)\n */\nconst KEYBOARD = 150;\n/**\n * Input types that bring up no on-screen keyboard.\n *\n * @claim \"Input types that bring up no\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx::TabBar > stays in place when a field takes focus under a fine pointer, which brings up no on-screen keyboard)\n */\nconst keyless = new Set([\"button\", \"checkbox\", \"color\", \"file\", \"hidden\", \"image\", \"radio\", \"range\", \"reset\", \"submit\"]);\n\n/** Whether the focused element takes typing: a text field, a text area or an editable region. */\nfunction typing(): boolean {\n  const field = document.activeElement;\n  if (field instanceof HTMLTextAreaElement) return !field.readOnly;\n  if (field instanceof HTMLInputElement) return !field.readOnly && !keyless.has(field.type);\n  return field instanceof HTMLElement && field.isContentEditable;\n}\n\n/** The tallest the layout viewport has been at its current width; a turn of the phone starts again. */\nlet layout = { width: 0, height: 0 };\n\n/**\n * Whether the on-screen keyboard is up. Where it covers the page (iOS, and Android by default),\n * it shrinks the visual viewport below the layout viewport, and that alone decides: a field\n * keeps its focus when the keyboard is put away (Android's back gesture, iPad's hide-keyboard\n * key), so focus would keep the bar away. A pinch zoom shrinks the visual viewport too, so it\n * is measured at the zoom's scale. Where the keyboard resizes the page instead, the layout\n * viewport shrinks well below the tallest it has been at this width, with a text field focused\n * on a touch screen. With no visual viewport to read, the focused field is the only sign.\n * @claim \"With no visual viewport to read\" registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx::TabBar and the on-screen keyboard > where the browser has no visual viewport > follows a focused field)\n * @claim \"With no visual viewport to read\" registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx::TabBar and the on-screen keyboard > slides away while the keyboard shrinks the visual viewport, even with no field focused, but not for a zoom)\n */\nfunction keyboardUp(): boolean {\n  const viewport = window.visualViewport;\n  const field = matchMedia(\"(pointer: coarse)\").matches && typing();\n  if (viewport === null) return field;\n  if (innerHeight - viewport.height * viewport.scale > KEYBOARD) return true;\n  if (innerWidth === layout.width) layout.height = Math.max(layout.height, innerHeight);\n  else layout = { width: innerWidth, height: innerHeight };\n  return field && layout.height - innerHeight > KEYBOARD;\n}\n\nfunction subscribeKeyboard(listener: () => void): () => void {\n  const viewport = window.visualViewport;\n  // Focus moving from one field to the next leaves nothing focused for a moment; the focusin that follows reports it.\n  const left = (event: FocusEvent) => {\n    if (event.relatedTarget === null) listener();\n  };\n  viewport?.addEventListener(\"resize\", listener);\n  document.addEventListener(\"focusin\", listener);\n  document.addEventListener(\"focusout\", left);\n  return () => {\n    viewport?.removeEventListener(\"resize\", listener);\n    document.removeEventListener(\"focusin\", listener);\n    document.removeEventListener(\"focusout\", left);\n  };\n}\n\nconst serverFalse = () => false;\n\n/**\n * Every path a tab owns, with the tab's index, for `currentHref`.\n *\n * @claim \"Every path a tab owns, with\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx::TabBar > lets an item's current flag win over the path)\n * @claim \"Every path a tab owns, with\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx::TabBar > gives the current tab the accent wash and the rest the muted text)\n */\nfunction ownedPaths(items: readonly TabBarItem[]): Array<{ path: string; index: number }> {\n  return items.flatMap((item, index) => [item.href, ...(item.paths ?? [])].map((path) => ({ path, index })));\n}\n\n/**\n * The bar of tabs at the bottom of a phone screen: two to five of the app's top-level\n * pages, each an icon over a short label, with the current page marked `aria-current=\"page\"`\n * and an accent wash. An `accessory`, such as Search, sits apart in a circle of its own, as\n * in iOS. The bar is navigation only and the same on every page: put page actions (create,\n * share, edit) on the page itself, never in the bar, so a tab never changes meaning.\n *\n * The bar is fixed to the bottom of the screen, clear of the home indicator, and the\n * component keeps its room at the end of the page, so render it last in the layout and the\n * content scrolls clear of it. It hides from `hideFrom` (640px by default), where the app's\n * `Navbar` or `Sidebar` takes over, and when printing. While the on-screen keyboard is up it\n * slides away below the screen (with reduced motion it fades), so it never rides on the\n * keyboard over the field a person types in, and it comes back when the keyboard goes. To\n * hide it on a page that fills the screen (a full-screen editor, a single decision), don't\n * render it there.\n *\n * Tabs render through `OuroProvider`'s `linkComponent`, so your router navigates. Each tab\n * is 64px tall, well over the 44px a finger needs.\n *\n * Use `Navbar` instead for the links across the top of a wider screen, `NavigationRail` for the\n * same pages down the side of a wider screen, `Sidebar` for many destinations, and `Tabs` for\n * views of one page.\n *\n * @group Navigation\n * @see https://ui.ouroboros.bot/docs/tab-bar\n *\n * @example\n * <TabBar\n *   label=\"Main\"\n *   currentPath={pathname}\n *   items={[\n *     { label: \"Home\", href: \"/\", icon: <House />, paths: [\"/account\"] },\n *     { label: \"Recipes\", href: \"/recipes\", icon: <BookOpen /> },\n *     { label: \"Shopping\", href: \"/shopping-list\", icon: <ShoppingBag /> },\n *   ]}\n *   accessory={{ label: \"Search\", href: \"/search\", icon: <Search /> }}\n * />\n * @claim \"Each tab is 64px tall, well\" registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.touch.test.tsx::fits five tabs and an accessory on a phone, each well over 44px, and a tap reaches the tab under the finger)\n * @claim \"The bar of tabs at the\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:testExists(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx::TabBar > sits fixed at the bottom of a phone screen, with equal 64px tabs, and keeps its room in the page)\n * @claim \"The bar is navigation only and\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:fileLine(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx, /hides\\sfrom\\s%s\\s\\(%ipx\\),\\sand\\swith\\snever\\sstays/)\n * @claim \"It hides from `hideFrom` (640px by\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:fileLine(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx, /hides\\sfrom\\s%s\\s\\(%ipx\\),\\sand\\swith\\snever\\sstays/)\n * @claim \"While the on-screen keyboard is up\" registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx verify:fileLine(registry/ouro/components/ouro/tab-bar/tab-bar.test.tsx, /hides\\sfrom\\s%s\\s\\(%ipx\\),\\sand\\swith\\snever\\sstays/)\n * @claim \"It hides from `hideFrom` (640px by\" registry/ouro/components/ouro/tab-bar/tab-bar-styles.ts verify:fileLine(registry/ouro/components/ouro/tab-bar/tab-bar-styles.ts, /print:hidden/)\n */\nexport function TabBar(props: TabBarProps): JSX.Element {\n  const {\n    label,\n    items,\n    accessory,\n    currentPath,\n    hideFrom: hideFromProp = \"sm\",\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    tabs,\n    links,\n    pathname,\n    value,\n    children,\n  } = props;\n  // A breakpoint that is not one of Ouro UI's (a type error) warns and renders the default.\n  const hideFrom = Object.hasOwn(breakpoints, hideFromProp) ? (hideFromProp as keyof typeof breakpoints) : \"sm\";\n  useAppearanceClassNameCheck(\n    \"TabBar\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; TabBar sets its own look from the theme`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"TabBar\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !label && [\"label is required; it names the navigation for screen readers\", '<TabBar label=\"Main\">'],\n          tabs !== undefined && [\"tabs is not a prop\", example],\n          links !== undefined && [\"links is not a prop\", example],\n          pathname !== undefined && [\"pathname is not a prop\", \"<TabBar currentPath={pathname}>\"],\n          value !== undefined && [\"value is not a prop; the current tab follows the page's path\", \"<TabBar currentPath={pathname}>\"],\n          children !== undefined && [\"children are not rendered\", example],\n          hideFrom !== hideFromProp && [`hideFrom=\"${String(hideFromProp)}\" is not a breakpoint; use \"sm\", \"md\", \"lg\", \"xl\" or \"never\"`, '<TabBar hideFrom=\"lg\">'],\n          items.length > 5 && [\n            `${items.length} tabs do not fit a phone's width`,\n            \"keep two to five items, and link the rest from a page of their own\",\n          ],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  // An item's own `current` wins; otherwise the path decides, across the tabs and the accessory.\n  const all = accessory === undefined ? items : [...items, accessory];\n  const flagged = all.findIndex((item) => item.current);\n  let current = flagged;\n  if (flagged === -1) {\n    const owned = ownedPaths(all);\n    const match = currentHref(\n      owned.map((entry) => entry.path),\n      currentPath,\n    );\n    current = match === undefined ? -1 : owned.find((entry) => entry.path === match)!.index;\n  }\n  const isCurrent = (index: number) => (index === current ? (\"page\" as const) : undefined);\n  // The server cannot know, so the bar renders in place and steps aside after hydration if the keyboard is up.\n  const aside = useSyncExternalStore(subscribeKeyboard, keyboardUp, serverFalse);\n\n  return (\n    <div data-ouro=\"tab-bar\" className={cn(rootClass, breakpoints[hideFrom], className)}>\n      <nav\n        ref={ref}\n        aria-label={label}\n        data-ouro-part=\"bar\"\n        data-open={aside ? undefined : \"\"}\n        data-closed={aside ? \"\" : undefined}\n        inert={aside}\n        className={barClass}\n      >\n        <ul className={listClass}>\n          {items.map((item, index) => (\n            <li key={index} className=\"flex min-w-0 flex-1\">\n              <RouterLink href={item.href} aria-current={isCurrent(index)} data-ouro-control=\"tab-bar\" data-ouro-part=\"tab\" className={tabClass}>\n                <span aria-hidden=\"true\" className={iconClass}>\n                  {item.icon}\n                </span>\n                <span className={labelClass}>{item.label}</span>\n              </RouterLink>\n            </li>\n          ))}\n        </ul>\n        {accessory !== undefined && (\n          <RouterLink\n            href={accessory.href}\n            aria-current={isCurrent(items.length)}\n            data-ouro-control=\"tab-bar\"\n            data-ouro-part=\"accessory\"\n            className={accessoryClass}\n          >\n            <span aria-hidden=\"true\" className={cn(iconClass, \"size-6\")}>\n              {accessory.icon}\n            </span>\n            <span className=\"sr-only\">{accessory.label}</span>\n          </RouterLink>\n        )}\n      </nav>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/tab-bar/tab-bar.tsx"
    }
  ],
  "docs": "The bar of tabs at the bottom of a phone screen: two to five of the app's top-level pages, each an icon over a short label, with the current page marked `aria-current=\"page\"` and an accent wash. Import: import { TabBar } from \"@/components/ouro/tab-bar/tab-bar\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports 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/tab-bar.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}