Skip to content

Sidebar Tree

CMS page tree: nested pages drawn with hairline guide lines and +/− toggles (aria-expanded), mono “Pages” header with an add button; active page ink with signal dot; drawer on mobile.

mono-clean/layout/sidebar-tree
Open ↗

Source

"use client";

import { useEffect, useId, useState, type ReactNode } from "react";
import { cn } from "@/lib/utils";

export interface TreeNode {
  label: string;
  href: string;
  children?: TreeNode[];
}

export interface SidebarTreeProps {
  brand?: string;
  tree?: TreeNode[];
  activeHref?: string;
  children?: ReactNode;
  className?: string;
}

const DEFAULT_TREE: TreeNode[] = [
  { label: "Home", href: "#home" },
  {
    label: "Work",
    href: "#work",
    children: [
      { label: "Oslo Opera", href: "#oslo" },
      { label: "Kiln Coffee", href: "#kiln" },
      { label: "Moss", href: "#moss" },
    ],
  },
  {
    label: "About",
    href: "#about",
    children: [
      { label: "Team", href: "#team" },
      { label: "Clients", href: "#clients" },
    ],
  },
  { label: "Journal", href: "#journal" },
  { label: "Contact", href: "#contact" },
];

function FrameMark({ className }: { className?: string }) {
  return (
    <svg aria-hidden viewBox="0 0 24 24" className={cn("size-6 shrink-0", className)}>
      <rect x="1" y="1" width="22" height="22" fill="none" stroke="currentColor" strokeWidth="2" />
      <path d="M7 1v22M1 7h22" stroke="currentColor" strokeWidth="2" />
      <rect x="15" y="15" width="4" height="4" fill="var(--da-accent)" />
    </svg>
  );
}

/** CMS page tree: nested pages drawn with hairline guide lines and +/− toggles (aria-expanded), mono “Pages” header with an add button; active page ink with signal dot; drawer on mobile. */
export function SidebarTree({ brand = "Frame", tree = DEFAULT_TREE, activeHref = "#oslo", children, className }: SidebarTreeProps) {
  const [open, setOpen] = useState(false);
  const id = useId();
  useEffect(() => {
    if (!open) return;
    const onKey = (e: KeyboardEvent) => e.key === "Escape" && setOpen(false);
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [open]);
  const [openNodes, setOpenNodes] = useState<string[]>(["#work"]);
  const toggle = (h: string) => setOpenNodes((o) => (o.includes(h) ? o.filter((x) => x !== h) : [...o, h]));
  const render = (nodes: TreeNode[], depth: number) => (
    <ul role={depth ? "group" : "tree"} aria-label={depth ? undefined : "Pages"} className={cn(depth > 0 && "ml-3 border-l border-da-border pl-3")}>
      {nodes.map((n) => {
        const on = n.href === activeHref;
        const expanded = openNodes.includes(n.href);
        return (
          <li key={n.href} role="treeitem" aria-expanded={n.children ? expanded : undefined} aria-selected={on}>
            <div className="flex items-center gap-1">
              {n.children ? (
                <button
                  type="button"
                  onClick={() => toggle(n.href)}
                  aria-label={`${expanded ? "Collapse" : "Expand"} ${n.label}`}
                  className="da-focus grid size-5 place-items-center rounded-da-sm font-da-mono text-xs text-da-muted-fg hover:text-da-fg"
                >
                  {expanded ? "−" : "+"}
                </button>
              ) : (
                <span aria-hidden className="size-5" />
              )}
              <a
                href={n.href}
                aria-current={on ? "page" : undefined}
                className={cn(
                  "da-focus flex flex-1 items-center gap-2 rounded-da-sm py-1 text-[15px]",
                  on ? "text-da-fg" : "text-da-muted-fg hover:text-da-fg",
                )}
              >
                {n.label}
                {on && <span aria-hidden className="size-1.5 rounded-full bg-da-accent" />}
              </a>
            </div>
            {n.children && expanded && render(n.children, depth + 1)}
          </li>
        );
      })}
    </ul>
  );
  return (
    <div className={cn("flex min-h-dvh bg-da-bg text-da-fg", className)}>
      {open && <div aria-hidden className="fixed inset-0 z-40 bg-da-overlay lg:hidden" onClick={() => setOpen(false)} />}
      <aside
        id={id}
        aria-label="Sidebar"
        className={cn(
          "fixed inset-y-0 left-0 z-50 flex w-64 flex-col border-r border-da-border bg-da-bg transition-transform duration-(--da-duration) ease-da lg:sticky lg:top-0 lg:h-dvh lg:translate-x-0 motion-reduce:transition-none",
          open ? "translate-x-0" : "-translate-x-full",
        )}
      >
        <div className="flex h-14 items-center gap-2.5 border-b border-da-border px-4 font-da-display font-semibold tracking-da-display">
          <FrameMark className="size-5" />
          {brand}
          <button
            type="button"
            onClick={() => setOpen(false)}
            className="da-focus ml-auto rounded-da-sm font-da-mono text-xs font-normal tracking-da-label uppercase lg:hidden"
          >
            Close
          </button>
        </div>
        <div className="flex items-center justify-between px-4 pt-5 pb-2">
          <p className="font-da-mono text-[10px] tracking-da-label text-da-muted-fg uppercase">Pages</p>
          <button
            type="button"
            aria-label="Add page"
            className="da-focus grid size-6 place-items-center rounded-da-sm border border-da-border font-da-mono text-sm hover:border-da-border-strong"
          >
            +
          </button>
        </div>
        <nav aria-label="Pages" className="flex-1 overflow-y-auto px-3 pb-4">
          {render(tree, 0)}
        </nav>
      </aside>
      <div className="flex min-w-0 flex-1 flex-col">
        <div className="flex h-14 items-center justify-between border-b border-da-border px-4 lg:hidden">
          <span className="font-da-display font-semibold tracking-da-display">{brand}</span>
          <button
            type="button"
            aria-expanded={open}
            aria-controls={id}
            onClick={() => setOpen(true)}
            className="da-focus rounded-da-sm font-da-mono text-xs tracking-da-label uppercase"
          >
            Menu
          </button>
        </div>
        <main className="flex-1">{children}</main>
      </div>
    </div>
  );
}

export default SidebarTree;

modules/mono-clean/layout/sidebar-tree/index.tsx

Props

PropTypeDefaultDescription
brandstring—Brand name.
treeTreeNode[]—Tree.
activeHrefstring—Active Href.
childrenReactNode—Content.
classNamestring—Extra classes on the root.

Other sidebar variants in Mono Clean

Sidebar in other art directions

App Sidebar

App shell with a sticky left sidebar: workspace header, grouped nav with yellow active state and counters, usage meter, user footer. Becomes a top bar + slide-over drawer below lg.

BrutalistSidebar

Icon Rail

Compact 80px icon rail: ink brand square, square icon links with yellow active state, red counters and ink tooltips on hover/focus, settings pinned at the bottom. Server-safe, CSS-only tooltips.

BrutalistSidebar

Sidebar Collapsible

App sidebar that collapses from 256px to a 76px icon column with a stepped width animation; ink active item, labels become sr-only when collapsed, collapse toggle pinned at the bottom.

BrutalistSidebar

Sidebar Dual

Two-level navigation: an ink icon rail switches sections, and a paper second panel lists that section's links with counts and a yellow active link. Second panel hides on very small screens.

BrutalistSidebar

App Sidebar

Floating frosted sidebar inset from the viewport edges: gradient-orb brand, pill nav items with an ink active state and gradient badges, workspace group, gradient promo card and user chip. Becomes a floating pill top bar + glass drawer below lg.

GlassSidebar

Sidebar Adaptive

Adaptive navigation: a full glass sidebar with brand, gradient action button, labelled links and a usage meter on desktop; a floating bottom tab bar with a raised gradient “+” on mobile.

GlassSidebar

Sidebar Channels

Chat-app style double sidebar: a column of gradient workspace squircles plus a glass channel panel with collapsible sections, private/live icons, unread counts and LIVE meeting badges; drawer on mobile.

GlassSidebar

Sidebar Floating

Floating glass icon rail detached from the viewport edges: gradient logo orb, gradient active item, unread badges, glass tooltips on hover/focus, settings and avatar at the bottom; a floating bottom bar on mobile.

GlassSidebar

App Sidebar

Linear-style app shell: 240px translucent sidebar with workspace switcher, search, "New" button with shortcut, grouped 32px nav rows with counters, team list with color squares and settings at the bottom. Slide-in drawer below lg.

MinimalSidebar

Sidebar Inset

Inset app shell: the sidebar sits on the tinted page background while content lives in a raised rounded panel. Workspace header, collapsible nested sections with guide line, support/settings and user card; drawer on mobile.

MinimalSidebar

Sidebar Rail

Sidebar that collapses between a 224px labelled list and a 56px icon rail (⌘B or bottom button) with tooltips on hover/focus and corner badges; icon-only on mobile. Controlled or uncontrolled.

MinimalSidebar

Sidebar Tree

Docs / settings sidebar with a filter box and a nested collapsible tree auto-expanded to the active page (highlighted in indigo); stacks above content on mobile.

MinimalSidebar

App Sidebar

Classic enterprise app shell: white bordered sidebar with brand, entity switcher, grouped nav (uppercase group labels, count badges, blue active state), settings and user footer; off-canvas drawer on mobile.

Neo CorporateSidebar

Sidebar Collapsible

Sidebar that collapses from 240px to a 64px icon rail with a toggle button (aria-expanded); collapsed items keep tooltips (title) and sr-only labels. Always a rail on small screens.

Neo CorporateSidebar

Sidebar Dual

Two-level navigation: a narrow icon rail of top-level sections (tooltips, aria-pressed) and a secondary panel listing the selected section’s pages; the panel hides below md.

Neo CorporateSidebar

Sidebar Navy

Dark navy sidebar (fg-colored in light mode, surface in dark mode — dark in both): brand, search field, nav with white-tint active state and badges, and a cash-balance card at the bottom; drawer on mobile.

Neo CorporateSidebar

App Sidebar

Calm app shell: cream sidebar with leaf logo, pill nav items (sage pill for the active page), a small “this year” footprint card with a sprout, and settings at the bottom; drawer on mobile.

Organic SoftSidebar

Sidebar Floating

Floating sidebar: a rounded cream panel inset from the page edges with a soft shadow, italic serif group labels, a sage “New entry” pill and sage-tinted active items; drawer on mobile.

Organic SoftSidebar

Sidebar Garden

Deep sage sidebar (dark sage tint in dark mode) with cream text, a translucent active pill, count bubbles, rolling hills illustrated along the bottom and the user’s name on the hill; drawer on mobile.

Organic SoftSidebar

Sidebar Rail

Slim round icon rail: circular icon links on a sand column, the active one a sage circle with a leaf-shaped marker; labels appear as soft tooltips on hover/focus; becomes a bottom tab bar on mobile.

Organic SoftSidebar

App Sidebar

Friendly app shell: warm sidebar with emoji workspace chip, big periwinkle “New task” pill, search field, nav with peach count bubbles and a colored-dot board list; slide-in drawer on mobile.

Soft FlatSidebar

Sidebar Boards

Board navigator: starred favorites, then collapsible emoji spaces holding emoji boards with count bubbles; active board in a white pill; dashed “New space” button.

Soft FlatSidebar

Sidebar Card

Floating white sidebar card with generous radius on a tinted page: two-dot logo, nav with lavender active pill, butter “tip of the day” card and user row; horizontal nav on mobile.

Soft FlatSidebar

Sidebar Rail

Slim rounded icon rail: round icons whose active item fills with its own pastel color, dark pill tooltips, emoji avatar at the bottom; floating bottom bar on mobile.

Soft FlatSidebar