{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "navigation-menu",
  "title": "Navigation menu",
  "description": "Site navigation (Base UI Navigation Menu): a control frame of section triggers and links, the open trigger inverse, the current page cobalt; each section's panel docks to the frame's keyline with link cells on shared seams (title, description, code).",
  "dependencies": [
    "@base-ui/react@1.9.0"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "utils",
    "@keyline-ui/keyline-scope",
    "@keyline-ui/scroll-edges",
    "@keyline-ui/keyline-motion",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/navigation-menu.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { NavigationMenu as NavigationMenuPrimitive } from \"@base-ui/react/navigation-menu\";\nimport { DirectionProvider } from \"@base-ui/react/direction-provider\";\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\n\nimport { cn } from \"@/lib/utils\";\nimport { scopeProps, useDomDirection, useKeylineScope, useMergedRef } from \"../lib/keyline-scope\";\nimport { useScrollEdges } from \"../lib/scroll-edges\";\nimport { useStretch } from \"../lib/keyline-motion\";\nimport { resolveClassName, resolveStyle, type PartProps } from \"../lib/keyline-render\";\n\n/**\n * Navigation menu: site navigation whose sections open a panel of links (Base UI Navigation\n * Menu). For an application's own commands use Menubar; for an app's sections, Nav.\n *\n *   ┌──────────┬────────────┬─────────┬──────────┐\n *   │ Services▾│ Terminals ▾│ Pricing │ Contact  │   a control frame of cells: section triggers and links;\n *   └──────────┴────────────┼─────────┴──────────┘   the open trigger is the inverse cell, the current\n *   ┌───────────────────────┴──┬───────────────────┐  page's link is cobalt (location)\n *   │ Ocean freight     OCN    │ Customs     CUS   │   the panel docks to the frame's bottom keyline at its\n *   │ Door to door by sea      │ Filing, permits   │   weight, cells of links on shared seams (title, a\n *   ├──────────────────────────┼───────────────────┤   description, an optional code)\n *\n * - Behaviour is Base UI's: Tab moves between top-level items, Enter, Space or Down opens a section and\n *   moves into its panel; hover opens after a short delay; Escape closes and returns to the trigger.\n *   Left/Right follow the reading direction (the DOM `dir` is passed to Base UI).\n * - The panel never animates its size between sections (frames don't move); it unfolds from the frame's\n *   keyline when it opens (Unfold) and is instant under reduced motion. Moving from one open section to the\n *   next, the inverse cell stretches across to the new trigger (Stretch): the panel swaps in\n *   place, so the band is what says which section it now belongs to. Opening and closing do not stretch.\n * - Narrow: the frame scrolls sideways and marks its hidden edge; the panel is one column.\n *\n * Parts are named as Base UI names them. `NavigationMenu` is the root with its popup already in place;\n * `NavigationMenuRoot` and `NavigationMenuPopup` compose the same by hand.\n */\ntype Frame = {\n  /** The list (the control frame) the panel docks to; set by NavigationMenuList. */\n  frame: HTMLElement | null;\n  setFrame: React.Dispatch<React.SetStateAction<HTMLElement | null>> | null;\n};\nconst FrameContext = React.createContext<Frame>({ frame: null, setFrame: null });\n\n/** The root: Base UI's NavigationMenu.Root, told the DOM's reading direction. */\nfunction NavigationMenuRoot({\n  className,\n  ref: refProp,\n  ...props\n}: React.ComponentProps<typeof NavigationMenuPrimitive.Root>): React.ReactElement {\n  const ref = React.useRef<HTMLElement | null>(null);\n  const [frame, setFrame] = React.useState<HTMLElement | null>(null);\n  const [dir] = useDomDirection(ref);\n  const setRef = useMergedRef(ref, refProp);\n  const value = React.useMemo(() => ({ frame, setFrame }), [frame]);\n  return (\n    <DirectionProvider direction={dir}>\n      <FrameContext.Provider value={value}>\n        <NavigationMenuPrimitive.Root\n          ref={setRef}\n          className={resolveClassName(\n            \"grid min-w-0 max-w-full grid-cols-[minmax(0,1fr)] justify-items-start\",\n            className,\n          )}\n          {...props}\n          data-slot=\"navigation-menu\"\n        />\n      </FrameContext.Provider>\n    </DirectionProvider>\n  );\n}\n\n/** The root with its popup in place: the list goes inside, the panel docks under it. */\nfunction NavigationMenu({ children, ...props }: React.ComponentProps<typeof NavigationMenuRoot>): React.ReactElement {\n  return (\n    <NavigationMenuRoot {...props}>\n      {children}\n      <NavigationMenuPopup />\n    </NavigationMenuRoot>\n  );\n}\n\n/* the control frame. The band is its first child (the stretch engine's copy keeps it there as a placeholder, without\n   its attributes, so these rules count children rather than read the band's markers): the first cell after it\n   draws no divider, and its label clears the frame's cut. */\nconst list = cn(\n  \"kl-ctl kl-cells relative isolate m-0 min-h-(--kl-ctl) w-max max-w-full list-none overflow-x-auto bg-kl-cell p-0\",\n  \"[&>:nth-child(2)]:border-s-0 [&>li:nth-child(2)>:is(a,button)]:ps-[calc(14px+var(--kl-c,0px)*0.35)]\",\n);\n\nfunction NavigationMenuList({\n  className,\n  children,\n  ref: refProp,\n  ...props\n}: React.ComponentProps<typeof NavigationMenuPrimitive.List>): React.ReactElement {\n  const ref = React.useRef<HTMLUListElement | null>(null);\n  useScrollEdges(ref as React.RefObject<HTMLElement | null>);\n  // the open trigger, as an index among the list's cells; Base UI owns the state, the band follows its attribute\n  const [open, setOpen] = React.useState(-1);\n  React.useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    // moving between sections, Base UI may close the old one a few ms before opening the next (WebKit):\n    // a close is held briefly, so a section that opens within the grace makes the band travel instead of snap\n    let grace = 0;\n    const read = () => {\n      const items = Array.from(el.querySelectorAll<HTMLElement>(\"[data-kl-item]\"));\n      const i = items.findIndex((it) => it.hasAttribute(\"data-popup-open\"));\n      clearTimeout(grace);\n      if (i >= 0) setOpen(i);\n      else grace = window.setTimeout(() => setOpen(-1), 80);\n    };\n    read();\n    const mo = new MutationObserver(read);\n    mo.observe(el, { subtree: true, childList: true, attributeFilter: [\"data-popup-open\"] });\n    return () => {\n      mo.disconnect();\n      clearTimeout(grace);\n    };\n  }, []);\n  useStretch(ref as React.RefObject<HTMLElement | null>, open);\n  const { setFrame } = React.useContext(FrameContext);\n  React.useLayoutEffect(() => {\n    if (!setFrame) return;\n    setFrame(ref.current);\n    return () => setFrame(null);\n  }, [setFrame]);\n  const setRef = useMergedRef(ref, refProp);\n  return (\n    <NavigationMenuPrimitive.List\n      ref={setRef}\n      data-kl-stretch=\"\"\n      className={resolveClassName(list, className)}\n      {...props}\n      data-slot=\"navigation-menu-list\"\n    >\n      {/* Stretch: the open trigger's inverse cell is a band that travels between sections (a presentational list\n          item: a <ul> may only contain <li>) */}\n      <li\n        data-kl-band=\"\"\n        role=\"presentation\"\n        className=\"pointer-events-none absolute -z-1 list-none bg-kl-inverse forced-colors:hidden\"\n        aria-hidden\n        hidden\n      />\n      {children}\n    </NavigationMenuPrimitive.List>\n  );\n}\n\nfunction NavigationMenuItem({\n  className,\n  ...props\n}: React.ComponentProps<typeof NavigationMenuPrimitive.Item>): React.ReactElement {\n  return (\n    <NavigationMenuPrimitive.Item\n      className={resolveClassName(\"flex flex-none\", className)}\n      {...props}\n      data-slot=\"navigation-menu-item\"\n    />\n  );\n}\n\n/* a top-level cell, trigger or link. The band paints the open cell; the label flips with the band's cover, so it is\n   legible all the way across */\nconst cell = cn(\n  \"kl-key m-0 box-border flex min-h-full cursor-pointer items-center gap-1.5 border-0 bg-transparent bg-none px-3.5\",\n  \"font-(family-name:--kl-font) text-(length:--kl-text-body) font-(--kl-weight-strong) whitespace-nowrap text-kl-ink no-underline outline-0\",\n  \"hover:[&:not([data-popup-open],[data-kl-covered],[aria-current],[data-disabled])]:bg-kl-tint\",\n  \"focus-visible:outline-(length:--kl-ring) focus-visible:outline-offset-(--kl-ring-in) focus-visible:outline-kl-focus focus-visible:outline-solid\",\n  \"forced-colors:data-kl-covered:text-inherit\",\n);\n\nfunction NavigationMenuTrigger({\n  className,\n  children,\n  ...props\n}: React.ComponentProps<typeof NavigationMenuPrimitive.Trigger>): React.ReactElement {\n  return (\n    <NavigationMenuPrimitive.Trigger\n      data-kl-item=\"\"\n      className={resolveClassName(\n        cn(\n          cell,\n          \"group/navigation-menu-trigger pe-2.5 data-kl-covered:text-kl-on-inverse\",\n          \"data-disabled:cursor-not-allowed data-disabled:bg-(image:--kl-hatch) data-disabled:text-kl-dis\",\n          \"forced-colors:data-popup-open:outline-3 forced-colors:data-popup-open:outline-offset-[-4px]\",\n          \"forced-colors:data-popup-open:outline-[Highlight] forced-colors:data-popup-open:outline-solid\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"navigation-menu-trigger\"\n    >\n      <span>{children}</span>\n      <NavigationMenuPrimitive.Icon\n        data-slot=\"navigation-menu-icon\"\n        className=\"flex flex-none group-data-popup-open/navigation-menu-trigger:rotate-180\"\n      >\n        <svg\n          viewBox=\"0 0 16 16\"\n          width=\"16\"\n          height=\"16\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"1.75\"\n          strokeLinecap=\"square\"\n          aria-hidden\n        >\n          <path d=\"M4 6l4 4 4-4\" />\n        </svg>\n      </NavigationMenuPrimitive.Icon>\n    </NavigationMenuPrimitive.Trigger>\n  );\n}\n\n/* the current page: the cobalt cell (location) */\nconst current = cn(\n  \"aria-[current=page]:bg-kl-cobalt aria-[current=page]:text-kl-on-cobalt aria-[current=page]:focus-visible:outline-kl-on-cobalt\",\n  \"forced-colors:aria-[current=page]:bg-[Highlight] forced-colors:aria-[current=page]:text-[HighlightText]\",\n  \"forced-colors:aria-[current=page]:forced-color-adjust-none\",\n);\n\n/** A top-level link cell (no panel). `active` marks the current page (aria-current=\"page\", cobalt). */\nfunction NavigationMenuLink({\n  className,\n  ...props\n}: React.ComponentProps<typeof NavigationMenuPrimitive.Link>): React.ReactElement {\n  return (\n    <NavigationMenuPrimitive.Link\n      data-kl-item=\"\"\n      className={resolveClassName(\n        cn(\n          cell,\n          current,\n          \"active:[&:not([data-kl-covered],[aria-current],[data-disabled])]:bg-kl-press\",\n          \"[&[data-kl-covered]:not([aria-current])]:text-kl-on-inverse\",\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"navigation-menu-link\"\n    />\n  );\n}\n\n/** A section's panel content; it swaps in place inside the popup. */\nfunction NavigationMenuContent({\n  className,\n  ...props\n}: React.ComponentProps<typeof NavigationMenuPrimitive.Content>): React.ReactElement {\n  return (\n    <NavigationMenuPrimitive.Content\n      className={resolveClassName(\n        \"@container box-border w-[min(600px,calc(100vw-24px-4px))] data-ending-style:opacity-0\",\n        className,\n      )}\n      {...props}\n      data-slot=\"navigation-menu-content\"\n    />\n  );\n}\n\ntype PositionerProps = NavigationMenuPrimitive.Positioner.Props;\n\ntype NavigationMenuPopupProps = NavigationMenuPrimitive.Popup.Props &\n  Pick<PositionerProps, \"anchor\" | \"side\" | \"align\" | \"sideOffset\" | \"alignOffset\" | \"collisionPadding\"> & {\n    /** Where the portal renders (defaults to <body>). */\n    container?: NavigationMenuPrimitive.Portal.Props[\"container\"];\n    /** Props for Base UI's NavigationMenu.Portal. */\n    portalProps?: Omit<NavigationMenuPrimitive.Portal.Props, \"container\" | \"children\">;\n  };\n\n/**\n * The panel: Base UI's Portal, Positioner, Popup and Viewport in one part, with the positioner's placement props\n * lifted. Docked to the frame (the list), not the open trigger: the trigger sits inside the frame's k2 border, so a\n * trigger-anchored panel ran k2 inside the frame's edge. On the frame, the panel's top border lies on the frame's\n * bottom border (sideOffset -k2) and their outer start edges coincide; the panel stays put between sections and never\n * animates its size. It carries the configuration of the place it is written.\n */\nfunction NavigationMenuPopup({\n  anchor,\n  side = \"bottom\",\n  align = \"start\",\n  sideOffset = -2,\n  alignOffset,\n  collisionPadding = 12,\n  container,\n  portalProps,\n  className,\n  style,\n  children,\n  ...props\n}: NavigationMenuPopupProps): React.ReactElement {\n  const { frame } = React.useContext(FrameContext);\n  const [marker, scope, probe] = useKeylineScope(false, container);\n  return (\n    <>\n      {marker}\n      <NavigationMenuPrimitive.Portal container={container} {...portalProps}>\n        {probe}\n        <NavigationMenuPrimitive.Positioner\n          anchor={anchor ?? frame ?? undefined}\n          side={side}\n          align={align}\n          sideOffset={sideOffset}\n          alignOffset={alignOffset}\n          collisionPadding={collisionPadding}\n          {...scopeProps(scope, { className: \"kl-positioner\" })}\n        >\n          <NavigationMenuPrimitive.Popup\n            className={resolveClassName(\n              \"kl-attached kl-dock box-border h-[var(--popup-height,auto)] max-h-none w-[var(--popup-width,auto)] overflow-visible bg-kl-cell\",\n              className,\n            )}\n            style={resolveStyle({ \"--kl-attach\": \"2px\" } as React.CSSProperties, style)}\n            {...props}\n            data-slot=\"navigation-menu-popup\"\n          >\n            <NavigationMenuPrimitive.Viewport\n              className=\"relative size-full overflow-hidden\"\n              data-slot=\"navigation-menu-viewport\"\n            />\n            {children}\n          </NavigationMenuPrimitive.Popup>\n        </NavigationMenuPrimitive.Positioner>\n      </NavigationMenuPrimitive.Portal>\n    </>\n  );\n}\n\ntype PartState = Record<string, never>;\nconst PART_STATE: PartState = {};\n\n/** The panel's links as cells on shared seams: two columns where there is room, one where there is not. Each cell\n * draws its end and bottom keylines; the grid's negative end and bottom margins hide the last ones. */\nfunction NavigationMenuGrid({ render, className, style, children, ...props }: PartProps<\"ul\", PartState>) {\n  const own = {\n    \"data-slot\": \"navigation-menu-grid\",\n    className: resolveClassName(\n      cn(\n        \"m-0 -me-px -mb-px grid list-none grid-cols-[repeat(2,minmax(0,1fr))] p-0\",\n        \"[@container_(max-width:420px)]:grid-cols-[minmax(0,1fr)]\",\n      ),\n      className,\n    )(PART_STATE),\n    style: resolveStyle(undefined, style)(PART_STATE),\n    children: React.Children.map(children, (c) =>\n      c == null || c === false ? null : (\n        <li\n          data-slot=\"navigation-menu-grid-item\"\n          className=\"flex border-e-(length:--kl-k1) border-b-(length:--kl-k1) border-e-kl-seam border-b-kl-seam\"\n        >\n          {c}\n        </li>\n      ),\n    ),\n  };\n  return useRender({ defaultTagName: \"ul\", render, state: PART_STATE, props: mergeProps<\"ul\">(props, own) });\n}\n\ntype CardProps = Omit<React.ComponentProps<typeof NavigationMenuPrimitive.Link>, \"title\"> & {\n  title: React.ReactNode;\n  description?: React.ReactNode;\n  /** A Code-voice identifier at the cell's end (a service code, a terminal code). */\n  code?: React.ReactNode;\n};\n\n/** A link cell in a panel: title, description, code. `active` marks the current page. */\nfunction NavigationMenuCard({ className, title, description, code, ...props }: CardProps): React.ReactElement {\n  return (\n    <NavigationMenuPrimitive.Link\n      className={resolveClassName(\n        cn(\n          \"group/navigation-menu-card grid min-h-16 flex-1 grid-cols-[minmax(0,1fr)_auto] content-start gap-x-3 gap-y-0.5\",\n          \"px-(--kl-inset) pt-2.5 pb-3 text-kl-ink no-underline outline-0\",\n          \"hover:[&:not([aria-current])]:bg-kl-tint\",\n          \"focus-visible:outline-(length:--kl-ring) focus-visible:outline-offset-(--kl-ring-in) focus-visible:outline-kl-focus focus-visible:outline-solid\",\n          current,\n        ),\n        className,\n      )}\n      {...props}\n      data-slot=\"navigation-menu-card\"\n    >\n      <span data-slot=\"navigation-menu-card-title\" className=\"text-(length:--kl-text-body) font-(--kl-weight-strong)\">\n        {title}\n      </span>\n      {code != null ? (\n        <span\n          data-slot=\"navigation-menu-card-code\"\n          className={cn(\n            \"font-(family-name:--kl-font-mono) text-(length:--kl-text-code)/[1.6] font-medium not-italic normal-nums\",\n            \"text-kl-ink-2 group-aria-[current=page]/navigation-menu-card:text-inherit\",\n          )}\n        >\n          {code}\n        </span>\n      ) : null}\n      {description != null ? (\n        <span\n          data-slot=\"navigation-menu-card-description\"\n          className=\"col-span-full text-(length:--kl-text-label)/[1.4] text-kl-ink-2 group-aria-[current=page]/navigation-menu-card:text-inherit\"\n        >\n          {description}\n        </span>\n      ) : null}\n    </NavigationMenuPrimitive.Link>\n  );\n}\n\nexport {\n  NavigationMenu,\n  NavigationMenuRoot,\n  NavigationMenuList,\n  NavigationMenuItem,\n  NavigationMenuTrigger,\n  NavigationMenuLink,\n  NavigationMenuContent,\n  NavigationMenuPopup,\n  NavigationMenuGrid,\n  NavigationMenuCard,\n};\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/navigation-menu.tsx"
    }
  ],
  "type": "registry:ui"
}