App sidebar
Application shell with collapsible desktop icon rail and switchable workspace, mail inbox, and documentation navigation modes.
pnpm dlx shadcn@latest add @haze/app-sidebar---
import { BookOpen, ChevronsLeft, ChevronsRight, FolderKanban, Home, Inbox, Mail, Settings, Users } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
id?: string;
workspace?: string;
class?: string;
}
const {
id = "haze-app-sidebar",
workspace = "Tidewell Studio",
class: className,
} = Astro.props;
const modes = [
{ id: "workspace", label: "Workspace", items: ["Overview", "Projects", "Members", "Settings"] },
{ id: "mail", label: "Mail", items: ["Inbox (12)", "Starred", "Sent", "Archive"] },
{ id: "docs", label: "Docs", items: ["Getting started", "Tokens", "Components", "API"] },
] as const;
---
<section aria-labelledby={`${id}-title`} data-haze-app-sidebar class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-4xl space-y-3">
<div class="flex flex-wrap items-center justify-between gap-2">
<h2 id={`${id}-title`} class="text-sm/5 font-semibold text-foreground">Application sidebar shell</h2>
<div role="tablist" aria-label="Sidebar shell variant" class="inline-flex rounded-lg border border-border bg-card p-0.5">
{
modes.map((m, i) => (
<button
type="button"
role="tab"
data-sb-mode={m.id}
aria-selected={i === 0 ? "true" : "false"}
class="inline-flex h-7 cursor-pointer items-center rounded-md px-2.5 text-xs font-medium text-muted-foreground hover:text-foreground aria-selected:bg-accent aria-selected:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
>
{m.label}
</button>
))
}
</div>
</div>
<div class="grid min-h-72 overflow-hidden rounded-2xl border border-border bg-card sm:grid-cols-[auto_minmax(0,1fr)]">
<aside
data-sb-rail
data-collapsed="false"
aria-label="App navigation"
class="flex min-w-0 flex-col justify-between border-b border-border bg-muted/40 p-3 transition-[width] duration-200 ease-snappy sm:w-56 sm:border-r sm:border-b-0 data-[collapsed=true]:sm:w-16"
>
<div class="space-y-3">
<div class="flex items-center justify-between gap-2 px-1">
<span data-sb-label class="truncate text-xs font-semibold text-foreground">{workspace}</span>
<button
type="button"
data-sb-collapse
aria-label="Toggle compact icon rail"
aria-pressed="false"
class="inline-flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-frame bg-field text-muted-foreground hover:border-frame-strong hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75"
>
<ChevronsLeft data-sb-ico="open" class="size-3.5" aria-hidden="true" />
<ChevronsRight data-sb-ico="closed" class="hidden size-3.5" aria-hidden="true" />
</button>
</div>
{
modes.map((m, mi) => (
<nav data-sb-nav={m.id} hidden={mi !== 0} aria-label={`${m.label} navigation`}>
<ul role="list" class="grid gap-1">
{m.items.map((item, ii) => (
<li>
<a
href={`#${id}-${m.id}-${ii}`}
aria-current={ii === 0 ? "page" : undefined}
class="flex h-8 items-center gap-2.5 rounded-lg px-2 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground aria-[current=page]:bg-accent aria-[current=page]:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
>
{m.id === "mail" ? (
<Mail class="size-4 shrink-0" aria-hidden="true" />
) : m.id === "docs" ? (
<BookOpen class="size-4 shrink-0" aria-hidden="true" />
) : ii === 0 ? (
<Home class="size-4 shrink-0" aria-hidden="true" />
) : ii === 1 ? (
<FolderKanban class="size-4 shrink-0" aria-hidden="true" />
) : ii === 2 ? (
<Users class="size-4 shrink-0" aria-hidden="true" />
) : (
<Settings class="size-4 shrink-0" aria-hidden="true" />
)}
<span data-sb-label class="truncate">{item}</span>
</a>
</li>
))}
</ul>
</nav>
))
}
</div>
<div class="mt-4 flex items-center gap-2 border-t border-border pt-3 text-xs text-muted-foreground">
<span class="grid size-7 shrink-0 place-items-center rounded-full border border-frame bg-muted font-mono text-[0.6875rem] font-medium text-foreground">NP</span>
<span data-sb-label class="truncate">Nina Patel · Admin</span>
</div>
</aside>
<div class="flex min-w-0 flex-col justify-between p-5 sm:p-6">
<div>
<span class="inline-flex items-center gap-1.5 rounded-full border border-frame bg-muted/40 px-2.5 py-0.5 text-[0.6875rem] font-medium text-muted-foreground">
<Inbox class="size-3 text-muted-foreground" aria-hidden="true" />
Active shell view
</span>
<h3 data-sb-heading class="mt-3 text-lg/7 font-semibold tracking-tight text-foreground">Workspace overview</h3>
<p class="mt-1.5 text-sm/6 text-pretty text-muted-foreground">
Collapse the sidebar into an icon rail on desktop or switch between workspace, mail, and documentation navigation modes.
</p>
</div>
<p data-sb-status role="status" class="mt-4 min-h-4 text-xs/4 text-muted-foreground"></p>
</div>
</div>
</div>
</section>
<script>
function initAppSidebars() {
document.querySelectorAll<HTMLElement>("[data-haze-app-sidebar]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const rail = root.querySelector<HTMLElement>("[data-sb-rail]");
const toggle = root.querySelector<HTMLButtonElement>("[data-sb-collapse]");
const heading = root.querySelector<HTMLElement>("[data-sb-heading]");
const status = root.querySelector<HTMLElement>("[data-sb-status]");
toggle?.addEventListener("click", () => {
if (!rail) return;
const collapsed = rail.dataset.collapsed !== "true";
rail.dataset.collapsed = String(collapsed);
toggle.setAttribute("aria-pressed", String(collapsed));
root.querySelectorAll<HTMLElement>("[data-sb-label]").forEach((el) => (el.hidden = collapsed));
const openIco = root.querySelector<SVGElement>('[data-sb-ico="open"]');
const closedIco = root.querySelector<SVGElement>('[data-sb-ico="closed"]');
openIco?.classList.toggle("hidden", collapsed);
closedIco?.classList.toggle("hidden", !collapsed);
if (status) status.textContent = collapsed ? "Collapsed sidebar to icon rail." : "Expanded sidebar navigation.";
});
root.querySelectorAll<HTMLButtonElement>("[data-sb-mode]").forEach((tab) => {
tab.addEventListener("click", () => {
const mode = tab.dataset.sbMode!;
root.querySelectorAll<HTMLButtonElement>("[data-sb-mode]").forEach((t) => t.setAttribute("aria-selected", String(t === tab)));
root.querySelectorAll<HTMLElement>("[data-sb-nav]").forEach((n) => (n.hidden = n.dataset.sbNav !== mode));
if (heading) heading.textContent = `${tab.textContent?.trim()} overview`;
if (status) status.textContent = `Switched shell to ${tab.textContent?.trim()} navigation.`;
});
});
});
}
initAppSidebars();
document.addEventListener("astro:page-load", initAppSidebars);
</script>When to use
- Scaffolding a SaaS app layout whose sidebar collapses cleanly into a compact icon rail
- Switching between workspace, mail inbox, and documentation tree navigation structures
When not to use
- You only need a standalone vertical nav list without an app canvas; use sidebar
Installation
Add the Haze registry to components.json once, then install App sidebar with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/app-sidebarnpx shadcn@latest add @haze/app-sidebaryarn dlx shadcn@latest add @haze/app-sidebarbunx --bun shadcn@latest add @haze/app-sidebarFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-app-sidebar" | Unique prefix for navigation anchors and heading IDs. |
| workspace | string | "Tidewell Studio" | Workspace title shown at the top of the rail. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across mode tabs, rail collapse toggle and navigation links
- EnterSpace
- Switch shell navigation mode or collapse/expand the sidebar rail
Accessibility
- The collapse toggle exposes aria-pressed and announces rail state changes through a polite role="status" region.
- Mode tabs use role="tab" with aria-selected while each mode renders its own labelled nav landmark.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI block "App sidebar" with `npx shadcn@latest add @haze/app-sidebar`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AppSidebar from "@/components/haze/blocks/app-sidebar.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/blocks/app-sidebar.md
Customize with real content
Adapt the Haze app-sidebar block for our product. Replace the demo values of these props with our real content: id, workspace, class. Keep the layout, the heading level rules and these accessibility details: The collapse toggle exposes aria-pressed and announces rail state changes through a polite role="status" region. Mode tabs use role="tab" with aria-selected while each mode renders its own labelled nav landmark. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using app-sidebar, check it fits: use it when scaffolding a saas app layout whose sidebar collapses cleanly into a compact icon rail; switching between workspace, mail inbox, and documentation tree navigation structures. Avoid it when you only need a standalone vertical nav list without an app canvas; use sidebar. Alternatives: @haze/sidebar, @haze/navigation-menu.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.