{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-nav",
  "title": "Sidebar Nav",
  "description": "Data-driven navigation tree rendered with the sidebar primitives.",
  "dependencies": [
    "lucide-react@^1.27.0"
  ],
  "registryDependencies": [
    "@pestoui/collapsible",
    "@pestoui/kbd",
    "@pestoui/sidebar",
    "@pestoui/style",
    "@pestoui/utils"
  ],
  "files": [
    {
      "path": "pestoui/ui/sidebar-nav.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ArrowUpRightIcon, ChevronRightIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  Collapsible,\n  CollapsibleContent,\n  CollapsibleTrigger,\n} from \"@/components/ui/collapsible\"\nimport { Kbd } from \"@/components/ui/kbd\"\nimport {\n  SidebarGroup,\n  SidebarGroupAction,\n  SidebarGroupLabel,\n  SidebarMenu,\n  SidebarMenuButton,\n  SidebarMenuCollapsible,\n  SidebarMenuCollapsibleContent,\n  SidebarMenuCollapsibleTrigger,\n  SidebarMenuItem,\n  SidebarMenuMeta,\n  SidebarMenuSub,\n  SidebarMenuSubButton,\n  SidebarMenuSubItem,\n  SidebarSeparator,\n} from \"@/components/ui/sidebar\"\n\n/* ---------------------------------------------------------------------------\n   The data layer over the sidebar primitives.\n\n   Everything the primitives express is reachable by hand — that is the point of\n   them — but a nav is the one place in an app shell where hand-written JSX\n   stops paying for itself. The rows are homogeneous, there are twenty of them,\n   they come from a route table, and the active one changes on every navigation.\n   Written out longhand that is twenty near-identical blocks that drift.\n\n   So this takes `NavGroup[]` and renders the composition, and deliberately owns\n   no styling of its own beyond the two things the data implies: which row is\n   current, and what trails the label.\n\n   `renderLink` is the decoupling seam. The design system never imports a\n   router; the app passes whatever its `<Link>` is and gets the row's contents\n   back to wrap.\n\n   No cva here. `size` is a pass-through to the existing menu-button axis and\n   this component adds no variant axis of its own.\n--------------------------------------------------------------------------- */\n\nexport interface NavNode {\n  id: string\n  label: React.ReactNode\n  icon?: React.ReactNode\n  href?: string\n  badge?: number | string\n  /** Rendered as a `<Kbd>` in the trailing slot, e.g. \"⌘1\". */\n  shortcut?: string\n  external?: boolean\n  disabled?: boolean\n  children?: NavNode[]\n}\n\nexport interface NavGroup {\n  id: string\n  /** Omit for an unlabelled group. */\n  label?: React.ReactNode\n  /** Draw a rule above this group instead of labelling it. */\n  separated?: boolean\n  items: NavNode[]\n  /** Rendered as a `SidebarGroupAction` beside the label. */\n  action?: React.ReactNode\n}\n\nexport interface SidebarNavProps\n  extends Omit<React.ComponentProps<\"nav\">, \"children\"> {\n  groups: NavGroup[]\n  /** `NavNode.id` of the current page. Router-agnostic by design. */\n  activeId?: string\n  defaultExpandedIds?: string[]\n  /** Controlled-optional: pass with `onExpandedChange` to drive expansion. */\n  expandedIds?: string[]\n  onExpandedChange?: (ids: string[]) => void\n  /** Inject the app's link component. Return an element wrapping `children`. */\n  renderLink?: (node: NavNode, children: React.ReactNode) => React.ReactNode\n  size?: \"sm\" | \"default\" | \"lg\"\n}\n\ntype RowRenderContext = {\n  activeId: string | undefined\n  expanded: ReadonlySet<string>\n  setExpanded: (id: string, open: boolean) => void\n  renderLink: SidebarNavProps[\"renderLink\"]\n  size: SidebarNavProps[\"size\"]\n}\n\n/* The leading icon is the only thing that takes the brand green when a row is\n   current. The row fill stays `--sidebar-accent`: a lime wash behind body text\n   is a readability problem, and one saturated 16px glyph is enough to find the\n   current row in a list of twenty.\n\n   It is also the part that answers a press. The row is full width, so squeezing\n   the whole row would move its edges by pixels; the glyph squeezes instead, on\n   the press spring, while the colour keeps its instant clock. Sub rows render\n   this same icon but sit under no `menu-button` group, so they do not squeeze —\n   a deliberate gap rather than a second group name for one effect. A disabled\n   row is pointer-events-none, so it never matches :active. */\nfunction NavIcon({ icon }: { icon: React.ReactNode }) {\n  return (\n    <span\n      data-slot=\"sidebar-nav-icon\"\n      aria-hidden=\"true\"\n      className=\"flex shrink-0 items-center justify-center text-sidebar-foreground/75 [transition-property:color,scale] [transition-duration:var(--duration-instant),var(--duration-spring-press)] [transition-timing-function:var(--ease-out-expo),var(--ease-spring-press)] group-active/menu-button:scale-(--press-squeeze) group-data-active/menu-button:text-selected\"\n    >\n      {icon}\n    </span>\n  )\n}\n\nfunction NavMeta({ node }: { node: NavNode }) {\n  if (node.badge === undefined && !node.shortcut && !node.external) {\n    return null\n  }\n\n  return (\n    <SidebarMenuMeta>\n      {node.badge !== undefined ? <span>{node.badge}</span> : null}\n      {node.shortcut ? (\n        <Kbd size=\"sm\" variant=\"muted\">\n          {node.shortcut}\n        </Kbd>\n      ) : null}\n      {/* The one row that leaves the app says so on approach: the arrow steps a\n          pixel along its own diagonal, which is the way it is pointing. */}\n      {node.external ? (\n        <ArrowUpRightIcon\n          aria-hidden=\"true\"\n          className=\"size-3.5 transition-transform duration-base ease-out-expo group-hover/menu-button:translate-x-px group-hover/menu-button:-translate-y-px\"\n        />\n      ) : null}\n    </SidebarMenuMeta>\n  )\n}\n\nfunction NavRowContent({ node }: { node: NavNode }) {\n  return (\n    <>\n      {node.icon ? <NavIcon icon={node.icon} /> : null}\n      <span className=\"min-w-0 flex-1 truncate\">{node.label}</span>\n      <NavMeta node={node} />\n    </>\n  )\n}\n\n/* Returns the props a row needs to host either a plain button or the caller's\n   link element. `asChild` is only ever true when there is a real element to\n   hand over, so a nav with no routing still renders semantic buttons. */\nfunction resolveRowHost(\n  node: NavNode,\n  renderLink: SidebarNavProps[\"renderLink\"],\n  content: React.ReactNode\n) {\n  if (renderLink) {\n    return { asChild: true, children: renderLink(node, content) }\n  }\n\n  if (node.href) {\n    return {\n      asChild: true,\n      children: (\n        <a\n          href={node.href}\n          target={node.external ? \"_blank\" : undefined}\n          rel={node.external ? \"noreferrer\" : undefined}\n        >\n          {content}\n        </a>\n      ),\n    }\n  }\n\n  return { asChild: false, children: content }\n}\n\nfunction NavLeaf({\n  node,\n  context,\n}: {\n  node: NavNode\n  context: RowRenderContext\n}) {\n  const host = resolveRowHost(\n    node,\n    context.renderLink,\n    <NavRowContent node={node} />\n  )\n\n  return (\n    <SidebarMenuItem>\n      <SidebarMenuButton\n        size={context.size}\n        isActive={context.activeId === node.id}\n        aria-disabled={node.disabled || undefined}\n        tooltip={{ children: node.label }}\n        asChild={host.asChild}\n      >\n        {host.children}\n      </SidebarMenuButton>\n    </SidebarMenuItem>\n  )\n}\n\nfunction NavBranch({\n  node,\n  context,\n}: {\n  node: NavNode\n  context: RowRenderContext\n}) {\n  const children = node.children ?? []\n  const open = context.expanded.has(node.id)\n\n  return (\n    <SidebarMenuCollapsible\n      label={node.label}\n      open={open}\n      onOpenChange={(next) => context.setExpanded(node.id, next)}\n    >\n      <SidebarMenuCollapsibleTrigger\n        size={context.size}\n        isActive={context.activeId === node.id}\n        aria-disabled={node.disabled || undefined}\n        tooltip={{ children: node.label }}\n      >\n        {node.icon ? <NavIcon icon={node.icon} /> : null}\n        <span className=\"min-w-0 flex-1 truncate\">{node.label}</span>\n      </SidebarMenuCollapsibleTrigger>\n      <SidebarMenuCollapsibleContent>\n        <NavSubList nodes={children} context={context} />\n      </SidebarMenuCollapsibleContent>\n    </SidebarMenuCollapsible>\n  )\n}\n\n/* Depth two and beyond. The sub-button is an anchor by default, so a row that\n   only toggles hands it a real `<button>` rather than an href-less link. */\nfunction NavSubList({\n  nodes,\n  context,\n}: {\n  nodes: NavNode[]\n  context: RowRenderContext\n}) {\n  return (\n    <SidebarMenuSub>\n      {nodes.map((node) => (\n        <NavSubRow key={node.id} node={node} context={context} />\n      ))}\n    </SidebarMenuSub>\n  )\n}\n\nfunction NavSubRow({\n  node,\n  context,\n}: {\n  node: NavNode\n  context: RowRenderContext\n}) {\n  const content = <NavRowContent node={node} />\n  const host = resolveRowHost(node, context.renderLink, content)\n  const nested = node.children ?? []\n  const isActive = context.activeId === node.id\n\n  if (nested.length === 0) {\n    return (\n      <SidebarMenuSubItem>\n        <SidebarMenuSubButton\n          isActive={isActive}\n          aria-disabled={node.disabled || undefined}\n          asChild={host.asChild}\n        >\n          {host.children}\n        </SidebarMenuSubButton>\n      </SidebarMenuSubItem>\n    )\n  }\n\n  return (\n    <SidebarMenuSubItem>\n      <Collapsible\n        className=\"group/sub-collapsible\"\n        open={context.expanded.has(node.id)}\n        onOpenChange={(next) => context.setExpanded(node.id, next)}\n      >\n        <CollapsibleTrigger asChild>\n          <SidebarMenuSubButton\n            data-slot=\"sidebar-menu-sub-button\"\n            isActive={isActive}\n            asChild\n          >\n            <button type=\"button\">\n              {content}\n              <ChevronRightIcon\n                aria-hidden=\"true\"\n                className=\"ml-auto shrink-0 text-sidebar-foreground/60 transition-transform duration-base ease-out-expo group-data-open/sub-collapsible:rotate-90\"\n              />\n            </button>\n          </SidebarMenuSubButton>\n        </CollapsibleTrigger>\n        <CollapsibleContent>\n          <NavSubList nodes={nested} context={context} />\n        </CollapsibleContent>\n      </Collapsible>\n    </SidebarMenuSubItem>\n  )\n}\n\nfunction SidebarNav({\n  className,\n  groups,\n  activeId,\n  defaultExpandedIds,\n  expandedIds,\n  onExpandedChange,\n  renderLink,\n  size = \"default\",\n  \"aria-label\": ariaLabel = \"Main\",\n  ...props\n}: SidebarNavProps) {\n  const [uncontrolled, setUncontrolled] = React.useState<string[]>(\n    () => defaultExpandedIds ?? []\n  )\n  const resolved = expandedIds ?? uncontrolled\n\n  const expanded = React.useMemo(() => new Set(resolved), [resolved])\n\n  const setExpanded = React.useCallback(\n    (id: string, open: boolean) => {\n      const next = new Set(resolved)\n      if (open) {\n        next.add(id)\n      } else {\n        next.delete(id)\n      }\n      const value = Array.from(next)\n      if (expandedIds === undefined) {\n        setUncontrolled(value)\n      }\n      onExpandedChange?.(value)\n    },\n    [expandedIds, onExpandedChange, resolved]\n  )\n\n  const context = React.useMemo<RowRenderContext>(\n    () => ({ activeId, expanded, setExpanded, renderLink, size }),\n    [activeId, expanded, setExpanded, renderLink, size]\n  )\n\n  return (\n    <nav\n      data-slot=\"sidebar-nav\"\n      aria-label={ariaLabel}\n      className={cn(\"flex w-full min-w-0 flex-col\", className)}\n      {...props}\n    >\n      {groups.map((group, index) => (\n        <React.Fragment key={group.id}>\n          {/* A rule above the group is the *alternative* to a heading, which is\n              what makes \"sections with subheadings\" and \"sections with\n              dividers\" one component reading two data shapes. A rule above the\n              first group would be an edge, not a divider. */}\n          {group.separated && index > 0 ? <SidebarSeparator /> : null}\n          <SidebarGroup>\n            {group.label ? (\n              <SidebarGroupLabel>{group.label}</SidebarGroupLabel>\n            ) : null}\n            {group.action ? (\n              <SidebarGroupAction asChild={React.isValidElement(group.action)}>\n                {group.action}\n              </SidebarGroupAction>\n            ) : null}\n            <SidebarMenu>\n              {group.items.map((node) =>\n                node.children && node.children.length > 0 ? (\n                  <NavBranch key={node.id} node={node} context={context} />\n                ) : (\n                  <NavLeaf key={node.id} node={node} context={context} />\n                )\n              )}\n            </SidebarMenu>\n          </SidebarGroup>\n        </React.Fragment>\n      ))}\n    </nav>\n  )\n}\n\nexport { SidebarNav }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}