{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tab-bar",
  "type": "registry:ui",
  "title": "Tab Bar",
  "description": "The row of three to five destinations at the bottom of a phone screen, where a thumb reaches. Each tab is a real link with an icon and a word; the current one says so to assistive tech (`aria-current=\"page\"`) and to the eye with a filled pill behind its…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "navigation",
    "pattern"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/patterns/tab-bar.tsx",
      "target": "components/ui/patterns/tab-bar.tsx",
      "type": "registry:ui",
      "content": "import * as React from 'react';\n\n// @interlace/tab-bar v1.1.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/tab-bar\n// What changed since: https://ds.interlace.tools/c/tab-bar#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — TabBar\n *\n * The row of three to five destinations at the bottom of a phone screen,\n * where a thumb reaches. Each tab is a real link with an icon and a word;\n * the current one says so to assistive tech (`aria-current=\"page\"`) and to\n * the eye with a filled pill behind its icon and a heavier label, never by\n * colour alone.\n *\n * ## Anatomy\n *\n *   <nav data-slot=\"tab-bar\" aria-label=\"Primary\">\n *     <ul>\n *       <li><a data-slot=\"tab-bar-item\" aria-current=\"page\">\n *         <span data-slot=\"tab-bar-icon\">{icon}<span data-slot=\"tab-bar-badge\" /></span>\n *         <span data-slot=\"tab-bar-label\">{label}</span>\n *       </a></li>\n *     </ul>\n *   </nav>\n *\n * ## Placement\n *\n * The bar is `sticky` to the bottom of the viewport, so it sits after the\n * page's content and never covers the last line of it. Put it last inside\n * `AppShell` (or any column at least as tall as the screen). It pads itself\n * by the device's safe areas (`env(safe-area-inset-*)`), which needs\n * `viewport-fit=cover` in the page's viewport meta.\n *\n * `hideFrom` hides it from a width up (`md` by default), where a Topbar or\n * a sidebar takes over the same links. `hideFrom=\"never\"` keeps it.\n *\n * ## Motion\n *\n * The current tab's pill grows in from the middle (150ms, `--ease-enter`)\n * when it changes, a press dips the icon slightly, and under reduced motion\n * the pill is simply there.\n *\n * ## MIN_VIEWPORT — 320\n *\n * Five tabs share 320px at 64px each; a label longer than its tab wraps\n * onto a second line, hyphenated where the page sets `lang`, instead of being cut.\n *\n * | Rule | Concept                  | Where in this file                                |\n * | ---- | ------------------------ | ------------------------------------------------- |\n * | R4   | Extends native el        | `React.ComponentProps<'nav'>` + TabBar props      |\n * | R6   | data-slot per part       | tab-bar, tab-bar-item, -icon, -label, -badge      |\n * | R7   | className merged + rest  | `cn(BASE, className)` + `{...props}`              |\n * | R14  | Declares min viewport    | `data-min-viewport` + exported const              |\n * | R19  | Tokens only              | `bg-background`, `bg-muted`, `text-primary`       |\n * | R25  | Server component         | no hooks; links are plain or `renderLink`         |\n * | R26  | A11y from native el      | `<nav>` landmark, a list, `aria-current=\"page\"`   |\n */\n\nimport { cn } from '@/lib/utils';\n\nexport const MIN_VIEWPORT = 320 as const;\n\nexport interface TabBarItem {\n  href: string;\n  /** The tab's word. Always shown: an icon alone is a guess. */\n  label: React.ReactNode;\n  /** An outlined icon, decorative (hidden from assistive tech). */\n  icon: React.ReactNode;\n  /** The icon for the current tab, such as a filled version. Falls back to `icon`. */\n  activeIcon?: React.ReactNode;\n  /**\n   * A count or a dot on the icon: a number shows the number (99+ above 99), `true`\n   * shows a dot. Pair it with `badgeLabel`, since the mark itself is hidden.\n   */\n  badge?: number | boolean;\n  /** Read after the label when there is a badge, such as \"3 new\". */\n  badgeLabel?: string;\n}\n\nexport interface TabBarLinkRenderProps {\n  href: string;\n  className: string;\n  children: React.ReactNode;\n  'aria-current'?: 'page';\n  'data-slot': 'tab-bar-item';\n  'data-active'?: '';\n}\n\nexport interface TabBarProps extends Omit<React.ComponentProps<'nav'>, 'children'> {\n  /** Three to five destinations, in order. */\n  items: TabBarItem[];\n  /**\n   * The current page's href. The tab with this href is current; a deeper page\n   * (`/answers/42` under `/answers`) keeps its tab current. `/` matches only itself.\n   */\n  currentHref?: string;\n  /**\n   * The width from which the bar is hidden, because a Topbar or sidebar shows the\n   * same links there. @default 'md'\n   */\n  hideFrom?: 'sm' | 'md' | 'lg' | 'xl' | 'never';\n  /**\n   * Render-prop for links, for a framework's router link. Spread the rest so\n   * `aria-current` and the data attributes reach the element.\n   */\n  renderLink?: (props: TabBarLinkRenderProps) => React.ReactElement;\n}\n\nconst defaultRenderLink: NonNullable<TabBarProps['renderLink']> = ({ href, children, ...rest }) => (\n  <a href={href} {...rest}>\n    {children}\n  </a>\n);\n\n/** Each breakpoint spelled out, so Tailwind sees every class it needs. */\nconst HIDE_FROM = {\n  sm: 'sm:hidden',\n  md: 'md:hidden',\n  lg: 'lg:hidden',\n  xl: 'xl:hidden',\n  never: '',\n} as const;\n\nconst ITEM = cn(\n  'group/tab relative flex min-h-14 flex-col items-center justify-center gap-1 rounded-md px-1 py-1.5',\n  'text-muted-foreground text-xs font-medium',\n  'hover:text-foreground data-active:text-foreground data-active:font-semibold',\n  'focus-visible:ring-ring focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden',\n  'motion-safe:transition-colors motion-safe:duration-(--duration-fast)',\n  '[-webkit-tap-highlight-color:transparent]',\n);\n\n/** Whether `href` is the current page or one of its children. */\nexport function isTabCurrent(href: string, currentHref: string | undefined): boolean {\n  if (currentHref === undefined) return false;\n  const path = currentHref.split(/[?#]/)[0]!;\n  if (href === '/') return path === '/';\n  const base = href.replace(/\\/+$/, '');\n  return path === base || path.startsWith(`${base}/`);\n}\n\nfunction badgeText(badge: number): string {\n  return badge > 99 ? '99+' : String(badge);\n}\n\nfunction TabBar({\n  items,\n  currentHref,\n  hideFrom = 'md',\n  renderLink = defaultRenderLink,\n  className,\n  'aria-label': ariaLabel = 'Primary',\n  ...props\n}: TabBarProps) {\n  // The longest matching href wins, so `/answers/saved` beats `/answers`.\n  const current = items\n    .filter((item) => isTabCurrent(item.href, currentHref))\n    .sort((a, b) => b.href.length - a.href.length)[0]?.href;\n  return (\n    <nav\n      data-slot=\"tab-bar\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      aria-label={ariaLabel}\n      className={cn(\n        'border-border bg-background/90 supports-backdrop-filter:bg-background/75 sticky bottom-0 z-header border-t backdrop-blur',\n        'px-[max(env(safe-area-inset-left,0px),env(safe-area-inset-right,0px))] pb-[env(safe-area-inset-bottom,0px)]',\n        HIDE_FROM[hideFrom],\n        className,\n      )}\n      {...props}\n    >\n      <ul className=\"mx-auto grid max-w-(--container-content) auto-cols-fr grid-flow-col px-1\">\n        {items.map((item) => {\n          const active = item.href === current;\n          const hasBadge = item.badge !== undefined && item.badge !== false && item.badge !== 0;\n          return (\n            <li key={item.href} className=\"flex min-w-0 flex-col\">\n              {renderLink({\n                href: item.href,\n                className: ITEM,\n                'data-slot': 'tab-bar-item',\n                ...(active ? { 'aria-current': 'page' as const, 'data-active': '' as const } : {}),\n                children: (\n                  <>\n                    <span aria-hidden data-slot=\"tab-bar-icon\" className=\"relative flex h-8 w-14 items-center justify-center\">\n                      <span\n                        aria-hidden\n                        data-slot=\"tab-bar-pill\"\n                        className={cn(\n                          'bg-muted absolute inset-0 scale-x-50 rounded-full opacity-0',\n                          'group-data-active/tab:scale-x-100 group-data-active/tab:opacity-100',\n                          'motion-safe:transition-[scale,opacity] motion-safe:duration-(--duration-base) motion-safe:ease-enter',\n                        )}\n                      />\n                      <span\n                        aria-hidden\n                        className=\"relative flex motion-safe:transition-transform motion-safe:duration-(--duration-fast) group-active/tab:scale-90 [&_svg]:size-6\"\n                      >\n                        {active ? (item.activeIcon ?? item.icon) : item.icon}\n                      </span>\n                      {hasBadge ? (\n                        <span\n                          aria-hidden\n                          data-slot=\"tab-bar-badge\"\n                          className={cn(\n                            'bg-primary text-primary-foreground ring-background absolute rounded-full ring-2',\n                            item.badge === true\n                              ? 'end-3 top-0.5 size-2.5'\n                              : 'start-[calc(50%+0.25rem)] -top-0.5 min-w-5 px-1 text-center text-[0.6875rem] leading-5 font-semibold tabular-nums',\n                          )}\n                        >\n                          {item.badge === true ? null : badgeText(item.badge as number)}\n                        </span>\n                      ) : null}\n                    </span>\n                    <span data-slot=\"tab-bar-label\" className=\"max-w-full text-center leading-tight hyphens-auto\">\n                      {item.label}\n                      {hasBadge && item.badgeLabel ? <span className=\"sr-only\">, {item.badgeLabel}</span> : null}\n                    </span>\n                  </>\n                ),\n              })}\n            </li>\n          );\n        })}\n      </ul>\n    </nav>\n  );\n}\nTabBar.displayName = 'TabBar';\n\nexport { TabBar };\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": false,
    "minViewport": 320,
    "loading": false,
    "version": "1.1.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/tab-bar\n\nInstalled to `components/ui/patterns/tab-bar.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/tab-bar';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/tab-bar\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
