Blocks
App shell
Next.js layouts with sidebar and header.
When to use
- Sidebar shell: apps with more than five destinations, or people who stay in the app all day.
- Top navbar shell: up to five or six sections, content that wants the full width (tables, boards), or a product that also has a marketing site with the same header.
Not for: marketing pages (use the Hero and Footer blocks with a Navbar) or a single-page tool.
Next.js usage
Put the shell in the layout of a route group, so it renders once and stays mounted while the pages inside it change. Split it at the interactive parts: the layout itself is a Server Component, AppSidebar and SiteHeader carry 'use client' because they read the current path, and every page passed in as children stays a Server Component that can fetch its own data.
app/(app)/layout.tsx
import type { ReactNode } from 'react';
import { SidebarInset, SidebarProvider } from 'ui-kit';
import { AppSidebar } from '@/components/app-sidebar';
import { SiteHeader } from '@/components/site-header';
// Every page in the (app) route group renders inside this shell. The layout
// stays mounted while people move between pages, so the sidebar keeps its
// state and only {children} changes. No 'use client' here: the provider and
// the two shell parts are client components, the pages stay on the server.
export default function AppLayout({ children }: { children: ReactNode }) {
return (
<SidebarProvider>
<AppSidebar />
<SidebarInset className="@container flex flex-col">
<SiteHeader />
<main className="flex-1 p-4 @2xl:p-6">{children}</main>
</SidebarInset>
</SidebarProvider>
);
}components/app-sidebar.tsx
'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import {
Icon,
Sidebar,
SidebarContent,
SidebarGroup,
SidebarGroupLabel,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
type IconName,
} from 'ui-kit';
const nav: { href: string; label: string; icon: IconName }[] = [
{ href: '/dashboard', label: 'Overview', icon: 'layout-dashboard' },
{ href: '/projects', label: 'Projects', icon: 'folder' },
{ href: '/customers', label: 'Customers', icon: 'users' },
{ href: '/settings', label: 'Settings', icon: 'settings' },
];
export function AppSidebar() {
const pathname = usePathname();
return (
<Sidebar aria-label="App navigation">
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Workspace</SidebarGroupLabel>
<SidebarMenu>
{nav.map((item) => (
<SidebarMenuItem key={item.href}>
{/* asChild: the row is a real link, so prefetching and new-tab clicks work */}
<SidebarMenuButton asChild isActive={pathname.startsWith(item.href)} tooltip={item.label}>
<Link href={item.href}>
<Icon name={item.icon} />
<span>{item.label}</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroup>
</SidebarContent>
</Sidebar>
);
}components/site-header.tsx
'use client';
import { usePathname } from 'next/navigation';
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbList,
BreadcrumbPage,
Separator,
SidebarTrigger,
ThemeSwitch,
} from 'ui-kit';
const titles: Record<string, string> = {
dashboard: 'Overview',
projects: 'Projects',
customers: 'Customers',
settings: 'Settings',
};
export function SiteHeader() {
const section = usePathname().split('/')[1] ?? '';
return (
<header className="sticky top-0 z-10 flex h-14 flex-none items-center gap-2 border-b border-border bg-background/85 px-3 backdrop-blur">
<SidebarTrigger />
<Separator orientation="vertical" className="mx-1 h-5" />
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbPage>{titles[section] ?? 'Overview'}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
<div className="ml-auto flex items-center gap-2">
<ThemeSwitch size="sm" />
</div>
</header>
);
}SidebarProvideris a client component, but Server Components passed to it as children stay on the server. That is why the provider can wrap the whole layout without turning your pages into client code.- Pass
usePathname()to<Navbar routeKey>in the navbar shell so the mobile menu closes after navigation. The sidebar sheet closes itself when a row is clicked. - The collapsed state is remembered in
localStorage(storageKey) and restored before paint, so the first frame already has the right width and nothing animates on load. - Add
ThemeScriptto the root layout once, so the theme is applied before the first paint and the theme switch hydrates without a flash.
app/layout.tsx
import { ThemeScript } from 'ui-kit';
import './globals.css';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<ThemeScript />
</head>
<body>{children}</body>
</html>
);
}Keyboard
| Key | Action |
|---|---|
| Ctrl / ⌘ + B | Collapse or expand the sidebar (opens the sheet on phones). |
| Ctrl / ⌘ + K | Open or close the command palette (sidebar shell). |
| Tab | Moves through the sidebar rows, then the header controls, then the page. |
| Esc | Closes the open menu, sheet or palette and returns focus to its trigger. |
Accessibility
- The sidebar is a named
asidelandmark; the current page row hasaria-current="page"and the breadcrumb ends with the current page. - Icon-only buttons (sidebar trigger, search on narrow screens, notifications, account) have accessible names.
- On the icon rail every row keeps its name, and its label appears in a tooltip on hover or focus.
- The theme switch is a radio group; the account menu offers the same choice for narrow headers where the switch is hidden.