{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "topbar-nav",
  "type": "registry:ui",
  "title": "Topbar Nav",
  "description": "The wide-screen half of `Topbar` when its links hold groups: a row of plain links and group triggers, where a group opens a panel of its items, each with an optional icon and a one-line description. It is how a site that is a family of products lists them…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "navigation",
    "pattern"
  ],
  "dependencies": [
    "@base-ui/react",
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/patterns/topbar-nav.tsx",
      "target": "components/ui/patterns/topbar-nav.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport { NavigationMenu } from \"@base-ui/react/navigation-menu\";\n\n// @interlace/topbar-nav v1.2.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/topbar-nav\n// What changed since: https://ds.interlace.tools/c/topbar-nav#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — TopbarNav\n *\n * The wide-screen half of `Topbar` when its links hold groups: a row of plain\n * links and group triggers, where a group opens a panel of its items, each\n * with an optional icon and a one-line description. It is how a site that is\n * a family of products lists them without a second bar. Topbar renders it for\n * you from `collapseBelow` up; below that, groups become labelled sections of\n * the `TopbarMenu` drawer.\n *\n * ## Built on Base UI NavigationMenu\n *\n * A site's navigation is links, not an application menu, so this is the\n * navigation-menu pattern, not `role=\"menu\"`: each trigger is a `<button>`\n * with `aria-expanded`, its panel holds ordinary links in reading order, Tab\n * walks into the open panel and on past it, Escape closes it and returns\n * focus to its trigger, and arrow keys move between triggers. Hovering a\n * trigger opens it after a short delay, and the panel slides between groups\n * instead of closing and reopening.\n *\n * ## Links are rendered by the server\n *\n * Topbar stays a server component, so `renderLink` (a function) never crosses\n * into this file: Topbar renders every link, and passes the finished elements\n * here as `entries`. This file holds only which panel is open. Following a\n * link inside a panel closes it, so a client-side route change never leaves\n * it open over the next page.\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R6   | data-slot per part      | topbar-nav / -trigger / -panel / -popup               |\n * | R12  | Reuse over wrap         | keyboard, hover intent and dismissal from Base UI     |\n * | R19  | Tokens only             | `bg-popover` / `border-border` / `text-muted-foreground` |\n * | R25  | Client component        | which panel is open                                   |\n * | R26  | A11y                    | `<nav>` landmark, `<button aria-expanded>` triggers   |\n *\n * ## Motion\n *\n * A pill slides under whichever item the pointer is over and rests under an\n * open trigger. Between groups the panel resizes and its content slides in\n * the direction of travel. Under reduced motion the pill and panel still\n * appear, without moving.\n */\n\nimport { ChevronDownIcon } from \"lucide-react\";\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/** One entry of the row, already rendered by Topbar. */\nexport type TopbarNavEntry =\n  | { kind: \"link\"; key: string; node: React.ReactNode }\n  | {\n      kind: \"group\";\n      key: string;\n      label: React.ReactNode;\n      /** True when one of the group's items is the current page. */\n      current?: boolean;\n      /** Two columns of items (more than three), so a wider panel. */\n      wide?: boolean;\n      /** The group's items, already rendered (a list). */\n      node: React.ReactNode;\n    };\n\nexport interface TopbarNavProps {\n  entries: TopbarNavEntry[];\n  /** Accessible name of the navigation landmark. @default 'Primary' */\n  label?: string;\n  className?: string;\n}\n\n/**\n * Every row item, link or trigger, is the same padded box, so the hover pill\n * and the focus ring both frame the words with room to spare and never touch\n * them. The ring sits 2px outside the box on the page colour.\n */\nexport const TOPBAR_ROW_ITEM =\n  \"relative inline-flex min-h-control items-center gap-1 rounded-md px-2.5 py-1.5 text-sm whitespace-nowrap text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\";\n\nconst TRIGGER = cn(\n  TOPBAR_ROW_ITEM,\n  \"data-popup-open:text-foreground data-current:text-foreground\",\n);\n\n/** Moves the hover pill under `target`, or hides it. */\nfunction placePill(\n  pill: HTMLElement | null,\n  list: HTMLElement | null,\n  target: HTMLElement | null,\n) {\n  if (!pill || !list) return;\n  if (!target) {\n    pill.removeAttribute(\"data-visible\");\n    return;\n  }\n  const from = list.getBoundingClientRect();\n  const box = target.getBoundingClientRect();\n  // The first placement after hiding jumps without sliding in from the last spot.\n  if (!pill.hasAttribute(\"data-visible\")) pill.setAttribute(\"data-instant\", \"\");\n  else pill.removeAttribute(\"data-instant\");\n  pill.style.setProperty(\"--pill-x\", `${box.left - from.left}px`);\n  pill.style.setProperty(\"--pill-w\", `${box.width}px`);\n  pill.setAttribute(\"data-visible\", \"\");\n}\n\nexport function TopbarNav({\n  entries,\n  label = \"Primary\",\n  className,\n}: TopbarNavProps) {\n  const [value, setValue] = React.useState<string | null>(null);\n  const listRef = React.useRef<HTMLDivElement>(null);\n  const pillRef = React.useRef<HTMLSpanElement>(null);\n  const rowItem = (event: React.SyntheticEvent) =>\n    (event.target as HTMLElement).closest<HTMLElement>(\n      \"[data-slot=topbar-nav-trigger], [data-slot=topbar-nav-link] > a\",\n    );\n  // With a panel open, the pill rests under its trigger; otherwise it leaves.\n  const restPill = () =>\n    placePill(\n      pillRef.current,\n      listRef.current,\n      listRef.current?.querySelector<HTMLElement>(\n        \"[data-slot=topbar-nav-trigger][data-popup-open]\",\n      ) ?? null,\n    );\n  React.useEffect(restPill, [value]);\n  return (\n    <NavigationMenu.Root\n      data-slot=\"topbar-nav\"\n      aria-label={label}\n      value={value}\n      onValueChange={(next) => setValue(typeof next === \"string\" ? next : null)}\n      className={className}\n    >\n      {/* The pill is a sibling of the list, not inside it: a list holds only items. */}\n      <div\n        ref={listRef}\n        className=\"relative isolate\"\n        onPointerOver={(event) => {\n          const item = rowItem(event);\n          if (item) placePill(pillRef.current, listRef.current, item);\n        }}\n        onPointerLeave={restPill}\n      >\n        <span\n          ref={pillRef}\n          aria-hidden\n          data-slot=\"topbar-nav-pill\"\n          className=\"bg-foreground/6 pointer-events-none absolute inset-y-0 left-0 z-backdrop w-(--pill-w) translate-x-(--pill-x) rounded-md opacity-0 data-visible:opacity-100 motion-safe:transition-[translate,width,opacity] motion-safe:duration-(--duration-medium) motion-safe:ease-move motion-safe:data-instant:transition-opacity\"\n        />\n        <NavigationMenu.List className=\"flex items-center gap-1\">\n          {entries.map((entry) =>\n            entry.kind === \"link\" ? (\n              <NavigationMenu.Item\n                key={entry.key}\n                data-slot=\"topbar-nav-link\"\n                className=\"flex\"\n              >\n                {entry.node}\n              </NavigationMenu.Item>\n            ) : (\n              <NavigationMenu.Item key={entry.key} value={entry.key}>\n                <NavigationMenu.Trigger\n                  data-slot=\"topbar-nav-trigger\"\n                  data-current={entry.current ? \"\" : undefined}\n                  className={TRIGGER}\n                >\n                  {entry.label}\n                  <NavigationMenu.Icon className=\"motion-safe:transition-transform motion-safe:duration-(--duration-fast) data-popup-open:rotate-180\">\n                    <ChevronDownIcon aria-hidden className=\"size-4\" />\n                  </NavigationMenu.Icon>\n                </NavigationMenu.Trigger>\n                <NavigationMenu.Content\n                  data-slot=\"topbar-nav-panel\"\n                  className={cn(\n                    \"p-2\",\n                    // Moving between groups, the old panel slides out the way the\n                    // pointer went and the new one slides in after it.\n                    \"motion-safe:transition-[opacity,translate] motion-safe:duration-(--duration-medium) motion-safe:ease-enter\",\n                    \"data-starting-style:opacity-0 data-ending-style:opacity-0\",\n                    \"motion-safe:data-starting-style:data-[activation-direction=left]:-translate-x-1/4 motion-safe:data-starting-style:data-[activation-direction=right]:translate-x-1/4\",\n                    \"motion-safe:data-ending-style:data-[activation-direction=left]:translate-x-1/4 motion-safe:data-ending-style:data-[activation-direction=right]:-translate-x-1/4\",\n                    entry.wide\n                      ? \"w-[min(36rem,calc(100vw-2rem))]\"\n                      : \"w-[min(22rem,calc(100vw-2rem))]\",\n                  )}\n                  onClick={(event) => {\n                    if ((event.target as HTMLElement).closest(\"a\"))\n                      setValue(null);\n                  }}\n                >\n                  {entry.node}\n                </NavigationMenu.Content>\n              </NavigationMenu.Item>\n            ),\n          )}\n        </NavigationMenu.List>\n      </div>\n      <NavigationMenu.Portal>\n        <NavigationMenu.Positioner\n          sideOffset={12}\n          align=\"start\"\n          collisionPadding={16}\n          className=\"z-popover h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) motion-safe:transition-[top,left,right,bottom] motion-safe:duration-(--duration-base) motion-safe:ease-enter data-instant:transition-none\"\n        >\n          <NavigationMenu.Popup\n            data-slot=\"topbar-nav-popup\"\n            className={cn(\n              \"bg-popover text-popover-foreground border-border relative h-(--popup-height) w-(--popup-width) origin-(--transform-origin) overflow-hidden rounded-xl border shadow-lg\",\n              \"motion-safe:transition-[opacity,scale,width,height] motion-safe:duration-(--duration-base) motion-safe:ease-enter\",\n              \"data-starting-style:opacity-0 data-ending-style:opacity-0 motion-safe:data-starting-style:scale-95 motion-safe:data-ending-style:scale-95\",\n            )}\n          >\n            <NavigationMenu.Viewport className=\"relative h-full w-full overflow-hidden\" />\n          </NavigationMenu.Popup>\n        </NavigationMenu.Positioner>\n      </NavigationMenu.Portal>\n    </NavigationMenu.Root>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.2.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/topbar-nav\n\nInstalled to `components/ui/patterns/topbar-nav.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/topbar-nav';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/topbar-nav\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
