Sidebar

The app's main navigation, down the left edge of every page. One item per area; an area with many pages gets a navigation list inside its content instead.

Playground

Click items, drag the edge, or collapse it.

Width
<script lang="ts">
	const sidebar = new SidebarState({ storageKey: 'app-sidebar' });
	onMount(() => sidebar.restore());
</script>

<div class="flex h-dvh">
	<Sidebar state={sidebar}>
		{#snippet header()}<Logo class="size-6" />{/snippet}
		<SidebarGroup label="Operations">
			<SidebarItem href="/projects" icon="folder" label="Projects" active />
			<SidebarItem href="/missions" icon="route" label="Missions" />
		</SidebarGroup>
	</Sidebar>
	<main class="min-w-0 flex-1">...</main>
</div>

Areas

An app in parts, each with its own pages: tabs at the top of the sidebar pick the part, and its navigation slides in from the side the tab is on. Only the picked tab shows its icon. Collapsed, the tabs become a column of icons.

Missions

The page's content.

Each area keeps its own page, so going back to one lands where you left it.

<script lang="ts">
	const areas = [
		{ value: 'operations', label: 'Operations', icon: 'ship' },
		{ value: 'sales', label: 'Sales', icon: 'briefcase' },
		{ value: 'delivery', label: 'Delivery', icon: 'file-export' },
	];
	let area = $state('operations');
</script>

<Sidebar state={sidebar}>
	{#snippet header()}<Logo class="size-6" />{/snippet}
	<SidebarTabs tabs={areas} bind:value={area} />
	<SidebarAreas value={area} order={areas.map((a) => a.value)}>
		{#snippet children(area)}
			{#if area === 'operations'}
				<SidebarGroup>
					<SidebarItem href="/missions" icon="route" label="Missions" />
				</SidebarGroup>
			{:else if area === 'sales'}
				...
			{/if}
		{/snippet}
	</SidebarAreas>
</Sidebar>

Behaviour

Collapse
The button at the bottom, or ⌘B / Ctrl+B anywhere outside a text field.
Resize
Drag the right edge, 200 to 360px. Drag past 140px and it collapses. Double-click the edge to reset to 240px.
Keyboard
Tab to the edge, then arrow keys resize (Shift for bigger steps) and Enter collapses.
Remembered
Pass a storageKey and the state and width survive reloads. Call restore() on mount.
Fixed positions
Icons, the logo and the toggle sit at the same spot open or collapsed. Only the width moves and labels fade.
Active rail
The current page gets the primary rail on the sidebar edge. It slides to the next page when you navigate.