Library MCP Setup About Template Factory ↗
← Library / Navigation & Shells UI SDK Agentic

Nested Workspace & Docked Section Nav

Two-column app navigation shell extracted from MSAI: a collapsible left rail with workspace switcher, primary nav, time-bucketed scheduled items, and expandable project folders beside a docked Level-1/Level-2 SectionNav column that folds down to a clickable 11px edge strip.

Install UI SDK & packages

npm install @ui-sdk/react @ui-sdk/core lucide-react

Give your agent the UI SDK skill

npx skills add vercel-labs/ui --skill ui-sdk

UI SDK entries: @ui-sdk/react/button @ui-sdk/react/dropdown-menu @ui-sdk/react/collapsible @ui-sdk/react/tooltip
"use client";

import * as React from "react";
import {
  ArrowLeft,
  Blocks,
  Check,
  ChevronDown,
  ChevronLeft,
  ChevronRight,
  ChevronsUpDown,
  Clock,
  Folder,
  Inbox,
  LayoutDashboard,
  MessageSquare,
  PanelLeft,
  Plus,
  Sparkles,
} from "lucide-react";
import { Button } from "@ui-sdk/react/button";
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@ui-sdk/react/collapsible";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@ui-sdk/react/dropdown-menu";

export interface WorkspaceOption {
  id: string;
  name: string;
  initial: string;
  color: string;
  teamInitials?: string[];
}

export interface SectionNavItem {
  id: string;
  label: string;
  href: string;
  count?: number;
  soon?: boolean;
}

export interface SectionNavGroup {
  label?: string;
  items: SectionNavItem[];
}

export interface NestedWorkspaceNavProps {
  workspaces?: WorkspaceOption[];
  activeWorkspaceId?: string;
  onSelectWorkspace?: (id: string) => void;
  activeRoute?: string;
  onNavigate?: (href: string) => void;
  sectionTitle?: string;
  sectionGroups?: SectionNavGroup[];
  contextLabel?: string;
  contextOptions?: { id: string; name: string; sub?: string }[];
  backLink?: { label: string; href: string };
  children?: React.ReactNode;
}

const DEFAULT_WORKSPACES: WorkspaceOption[] = [
  { id: "ws-main", name: "Acme Growth", initial: "A", color: "#38bdf8", teamInitials: ["W", "S", "B"] },
  { id: "ws-studio", name: "Launch Studio", initial: "L", color: "#a855f7", teamInitials: ["W", "M"] },
  { id: "ws-lab", name: "Solo Lab", initial: "S", color: "#10b981" },
];

const DEFAULT_GROUPS: SectionNavGroup[] = [
  {
    label: "Knowledge",
    items: [
      { id: "memory", label: "Memory", href: "/brain/memory", count: 24 },
      { id: "library", label: "Asset Library", href: "/brain/library", count: 18 },
    ],
  },
  {
    label: "Capabilities",
    items: [
      { id: "skills", label: "Skills", href: "/brain/skills", count: 9 },
      { id: "routines", label: "Routines", href: "/brain/routines" },
    ],
  },
  {
    label: "Workspace",
    items: [
      { id: "integrations", label: "Integrations", href: "/brain/integrations" },
      { id: "team", label: "Team", href: "/brain/team" },
      { id: "audit", label: "Audit Log", href: "/brain/audit", soon: true },
    ],
  },
];

const DEFAULT_PROJECTS = [
  {
    id: "p1",
    name: "Q4 Funnel Launch",
    chats: [
      { id: "c1", title: "Pricing page copy review" },
      { id: "c2", title: "Onboarding email sequence" },
    ],
  },
  {
    id: "p2",
    name: "Mobile Checkout Fix",
    chats: [{ id: "c3", title: "Keyboard inset verification" }],
  },
];

/**
 * MSAI-derived nested navigation architecture:
 * - Primary rail holds workspace switcher, top destinations, time-bucketed scheduled runs, and project folders.
 * - Docked SectionNav column owns deep section navigation with ruled-off groups and a trailing count OR active chevron (never both).
 * - Collapsing the SectionNav leaves an 11px clickable edge strip so users never lose where it went.
 */
export function NestedWorkspaceNav({
  workspaces = DEFAULT_WORKSPACES,
  activeWorkspaceId,
  onSelectWorkspace,
  activeRoute = "/brain/memory",
  onNavigate,
  sectionTitle = "Brain",
  sectionGroups = DEFAULT_GROUPS,
  contextLabel = "Persona",
  contextOptions = [
    { id: "founder", name: "Wynter (Direct)", sub: "Plain, builder-first voice" },
    { id: "coach", name: "Head Coach", sub: "Warm workshop guidance" },
  ],
  backLink,
  children,
}: NestedWorkspaceNavProps) {
  const [wsId, setWsId] = React.useState(activeWorkspaceId || workspaces[0]?.id || "ws-main");
  const [railCollapsed, setRailCollapsed] = React.useState(false);
  const [sectionOpen, setSectionOpen] = React.useState(true);
  const [openProject, setOpenProject] = React.useState<string | null>("p1");
  const [ctxId, setCtxId] = React.useState(contextOptions[0]?.id || "");
  const currentWs = workspaces.find((w) => w.id === (activeWorkspaceId ?? wsId)) || workspaces[0];
  const currentCtx = contextOptions.find((c) => c.id === ctxId) || contextOptions[0];

  const go = (href: string) => {
    onNavigate?.(href);
  };

  return (
    <div className="flex min-h-[560px] w-full overflow-hidden rounded-2xl border border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-800 dark:bg-[#090d16] dark:text-slate-100">
      {/* Primary Left Rail */}
      <aside
        aria-label="Primary rail"
        className={`flex shrink-0 flex-col border-r border-slate-200 bg-white transition-[width] duration-200 dark:border-slate-800 dark:bg-[#0e1422] ${
          railCollapsed ? "w-[68px]" : "w-[236px]"
        }`}
      >
        <div className="flex items-center justify-between gap-2 px-3 pt-3 pb-2">
          <DropdownMenu name="Switch workspace">
            <DropdownMenuTrigger asChild>
              <button
                type="button"
                className="flex min-w-0 flex-1 cursor-pointer items-center gap-2.5 rounded-xl border border-slate-200 bg-slate-50 px-2 py-2 text-left transition hover:border-slate-300 dark:border-slate-700/70 dark:bg-[#141c2e] dark:hover:border-slate-600"
              >
                <span
                  className="grid h-7 w-7 shrink-0 place-items-center rounded-lg text-xs font-extrabold text-slate-950"
                  style={{ backgroundColor: currentWs.color }}
                >
                  {currentWs.initial}
                </span>
                {!railCollapsed && (
                  <>
                    <span className="min-w-0 flex-1">
                      <span className="block truncate text-[13px] font-bold">{currentWs.name}</span>
                      {currentWs.teamInitials && currentWs.teamInitials.length > 1 && (
                        <span className="mt-0.5 flex -space-x-1">
                          {currentWs.teamInitials.map((ini, idx) => (
                            <span
                              key={idx}
                              className="grid h-4 w-4 place-items-center rounded-full border border-white bg-slate-700 text-[9px] font-bold text-white dark:border-[#141c2e]"
                            >
                              {ini}
                            </span>
                          ))}
                        </span>
                      )}
                    </span>
                    <ChevronsUpDown className="h-3.5 w-3.5 shrink-0 text-slate-400" />
                  </>
                )}
              </button>
            </DropdownMenuTrigger>
            <DropdownMenuContent align="start" className="w-56">
              {workspaces.map((w) => (
                <DropdownMenuItem
                  key={w.id}
                  onSelect={() => {
                    setWsId(w.id);
                    onSelectWorkspace?.(w.id);
                  }}
                >
                  <span
                    className="mr-2 grid h-5 w-5 place-items-center rounded text-[11px] font-bold text-slate-950"
                    style={{ backgroundColor: w.color }}
                  >
                    {w.initial}
                  </span>
                  <span className="flex-1 truncate">{w.name}</span>
                  {w.id === currentWs.id && <Check className="h-3.5 w-3.5 text-sky-400" />}
                </DropdownMenuItem>
              ))}
            </DropdownMenuContent>
          </DropdownMenu>
        </div>

        <div className="flex-1 space-y-4 overflow-y-auto px-2.5 py-2">
          <nav aria-label="Primary nav" className="space-y-0.5">
            {[
              { label: "Overview", href: "/", icon: LayoutDashboard },
              { label: "Inbox", href: "/inbox", icon: Inbox, badge: 3 },
              { label: "Chat", href: "/chat", icon: MessageSquare },
              { label: "Tools", href: "/tools", icon: Blocks },
              { label: "Brain", href: "/brain/memory", icon: Sparkles, activePrefix: "/brain" },
            ].map((item) => {
              const Icon = item.icon;
              const active = item.activePrefix
                ? activeRoute.startsWith(item.activePrefix)
                : activeRoute === item.href;
              return (
                <button
                  key={item.label}
                  type="button"
                  onClick={() => {
                    setSectionOpen(true);
                    go(item.href);
                  }}
                  title={railCollapsed ? item.label : undefined}
                  className={`flex w-full cursor-pointer items-center gap-2.5 rounded-xl px-2.5 py-2 text-[13px] font-semibold transition ${
                    active
                      ? "bg-sky-500/15 text-sky-600 dark:text-sky-300"
                      : "text-slate-600 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800/70 dark:hover:text-slate-100"
                  }`}
                >
                  <Icon className="h-4 w-4 shrink-0" />
                  {!railCollapsed && <span className="flex-1 truncate text-left">{item.label}</span>}
                  {!railCollapsed && item.badge && !active && (
                    <span className="rounded-full bg-sky-500 px-1.5 py-0.5 text-[10px] font-bold text-slate-950">
                      {item.badge}
                    </span>
                  )}
                  {!railCollapsed && active && <ChevronRight className="h-3.5 w-3.5 shrink-0 opacity-70" />}
                </button>
              );
            })}
          </nav>

          {!railCollapsed && (
            <>
              <div className="space-y-1.5 border-t border-slate-200 pt-3 dark:border-slate-800">
                <div className="flex items-center justify-between px-2 text-[11px] font-bold text-slate-500">
                  <span className="inline-flex items-center gap-1.5">
                    <Clock className="h-3 w-3" /> Scheduled
                  </span>
                  <span className="text-[10px] font-semibold text-slate-400">Today</span>
                </div>
                <button
                  type="button"
                  onClick={() => go("/brain/routines")}
                  className="block w-full cursor-pointer truncate rounded-lg px-2 py-1.5 text-left text-xs font-medium text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-800/60"
                >
                  Daily morning brief
                </button>
              </div>

              <div className="space-y-1 border-t border-slate-200 pt-3 dark:border-slate-800">
                <div className="flex items-center justify-between px-2 text-[11px] font-bold text-slate-500">
                  <span>Projects</span>
                  <button type="button" aria-label="New project" className="rounded p-0.5 hover:bg-slate-200 dark:hover:bg-slate-800">
                    <Plus className="h-3.5 w-3.5" />
                  </button>
                </div>
                {DEFAULT_PROJECTS.map((proj) => {
                  const isOpen = openProject === proj.id;
                  return (
                    <div key={proj.id}>
                      <button
                        type="button"
                        aria-expanded={isOpen}
                        onClick={() => setOpenProject(isOpen ? null : proj.id)}
                        className="flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-100 dark:text-slate-200 dark:hover:bg-slate-800/60"
                      >
                        <Folder className="h-3.5 w-3.5 shrink-0 text-slate-400" />
                        <span className="flex-1 truncate text-left">{proj.name}</span>
                        {!isOpen && <span className="text-[11px] text-slate-400">{proj.chats.length}</span>}
                      </button>
                      {isOpen && (
                        <div className="mt-0.5 space-y-0.5 pl-6">
                          {proj.chats.map((c) => (
                            <button
                              key={c.id}
                              type="button"
                              onClick={() => go(`/chat/${c.id}`)}
                              className="block w-full cursor-pointer truncate rounded-md px-2 py-1 text-left text-xs text-slate-500 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800/60 dark:hover:text-slate-100"
                            >
                              {c.title}
                            </button>
                          ))}
                        </div>
                      )}
                    </div>
                  );
                })}
              </div>
            </>
          )}
        </div>

        <div className="border-t border-slate-200 p-2.5 dark:border-slate-800">
          <Button
            name="Collapse rail"
            variant="ghost"
            onClick={() => setRailCollapsed((v) => !v)}
            className="flex h-9 w-full items-center justify-center gap-2 rounded-lg text-xs font-semibold text-slate-500 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-slate-100"
          >
            <PanelLeft className="h-4 w-4 shrink-0" />
            {!railCollapsed && <span>Collapse rail</span>}
          </Button>
        </div>
      </aside>

      {/* Docked Level-1/Level-2 SectionNav with 11px Re-expand Strip */}
      <Collapsible name="Section nav" open={sectionOpen} onOpenChange={setSectionOpen} asChild>
        <aside
          aria-label={sectionTitle}
          className={`relative shrink-0 border-r border-slate-200 bg-slate-50/90 transition-[width] duration-200 dark:border-slate-800 dark:bg-[#111827] ${
            sectionOpen ? "w-[218px]" : "w-[12px]"
          }`}
        >
          {!sectionOpen ? (
            <CollapsibleTrigger asChild>
              <button
                type="button"
                aria-label={`Expand ${sectionTitle}`}
                title={`Expand ${sectionTitle}`}
                className="h-full w-full cursor-pointer bg-transparent transition hover:bg-sky-500/20"
              />
            </CollapsibleTrigger>
          ) : (
            <CollapsibleContent forceMount className="flex h-full flex-col">
              <div className="flex items-center justify-between px-3.5 pt-3.5 pb-2">
                <span className="text-sm font-bold">{sectionTitle}</span>
                <CollapsibleTrigger asChild>
                  <button
                    type="button"
                    aria-label={`Collapse ${sectionTitle}`}
                    className="grid h-7 w-7 cursor-pointer place-items-center rounded-lg text-slate-400 hover:bg-slate-200/70 hover:text-slate-900 dark:hover:bg-slate-800 dark:hover:text-white"
                  >
                    <ChevronLeft className="h-4 w-4" />
                  </button>
                </CollapsibleTrigger>
              </div>

              {currentCtx && (
                <div className="px-2.5 pb-2.5">
                  <DropdownMenu name="Section context picker">
                    <DropdownMenuTrigger asChild>
                      <button
                        type="button"
                        className="flex w-full cursor-pointer items-center justify-between gap-2 rounded-xl border border-slate-200 bg-white px-2.5 py-2 text-left transition hover:border-slate-300 dark:border-slate-700/80 dark:bg-[#162033]"
                      >
                        <span className="min-w-0">
                          <span className="block text-[10px] font-semibold text-slate-400">{contextLabel}</span>
                          <span className="block truncate text-xs font-bold">{currentCtx.name}</span>
                        </span>
                        <ChevronDown className="h-3.5 w-3.5 shrink-0 text-slate-400" />
                      </button>
                    </DropdownMenuTrigger>
                    <DropdownMenuContent align="start" className="w-52">
                      {contextOptions.map((opt) => (
                        <DropdownMenuItem key={opt.id} onSelect={() => setCtxId(opt.id)}>
                          <span className="flex-1">
                            <span className="block text-xs font-semibold">{opt.name}</span>
                            {opt.sub && <span className="block text-[11px] text-slate-400">{opt.sub}</span>}
                          </span>
                          {opt.id === currentCtx.id && <Check className="h-3.5 w-3.5 text-sky-400" />}
                        </DropdownMenuItem>
                      ))}
                    </DropdownMenuContent>
                  </DropdownMenu>
                </div>
              )}

              <div className="flex-1 overflow-y-auto px-2.5 pb-4">
                {backLink && (
                  <div className="mb-2 border-b border-slate-200 pb-2 dark:border-slate-800">
                    <button
                      type="button"
                      onClick={() => go(backLink.href)}
                      className="flex w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-xs font-semibold text-slate-500 hover:bg-slate-200/70 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white"
                    >
                      <ArrowLeft className="h-3.5 w-3.5" />
                      <span>{backLink.label}</span>
                    </button>
                  </div>
                )}

                {sectionGroups.map((group, gi) => (
                  <div
                    key={group.label ?? gi}
                    className={gi > 0 ? "mt-3 border-t border-slate-200 pt-3 dark:border-slate-800" : ""}
                  >
                    {group.label && (
                      <div className="px-2.5 pb-1 text-[11px] font-semibold text-slate-400">
                        {group.label}
                      </div>
                    )}
                    <div className="space-y-0.5">
                      {group.items.map((item) => {
                        const active = activeRoute === item.href;
                        if (item.soon) {
                          return (
                            <div
                              key={item.id}
                              title="Coming soon"
                              className="flex cursor-not-allowed items-center justify-between rounded-lg px-2.5 py-1.5 text-[13px] font-medium text-slate-400/60"
                            >
                              <span>{item.label}</span>
                            </div>
                          );
                        }
                        return (
                          <button
                            key={item.id}
                            type="button"
                            aria-current={active ? "page" : undefined}
                            onClick={() => go(item.href)}
                            className={`flex w-full cursor-pointer items-center justify-between rounded-lg px-2.5 py-1.5 text-[13px] font-semibold transition ${
                              active
                                ? "bg-slate-900 text-white dark:bg-sky-500/18 dark:text-sky-200"
                                : "text-slate-600 hover:bg-slate-200/70 hover:text-slate-900 dark:text-slate-300 dark:hover:bg-slate-800/70 dark:hover:text-white"
                            }`}
                          >
                            <span className="truncate">{item.label}</span>
                            {item.count != null ? (
                              <span className="text-[11px] font-medium tabular-nums opacity-70">{item.count}</span>
                            ) : (
                              active && <ChevronRight className="h-3.5 w-3.5 shrink-0 opacity-75" />
                            )}
                          </button>
                        );
                      })}
                    </div>
                  </div>
                ))}
              </div>
            </CollapsibleContent>
          )}
        </aside>
      </Collapsible>

      {/* Main Content Slot */}
      <main className="min-w-0 flex-1 p-6">{children}</main>
    </div>
  );
}

export default NestedWorkspaceNav;