Navigation

Sidebar layout

The frame of an app: navigation down the side, the page beside it.

Installation

npx sinaui add sidebar-layout

Examples

Library app

Collapse to an icon rail with the button or ⌘B; the icons name themselves in tooltips. The highlight glides to the page you choose.

Catalog

Press ⌘B or Ctrl+B to collapse the sidebar to icons. Make the window narrow for the menu.

<script lang="ts">
	import {
		Book02Icon,
		BookOpen01Icon,
		Calendar03Icon,
		Home01Icon,
		Location01Icon
	} from '@hugeicons/core-free-icons';
	import SidebarLayout, { type SidebarGroup } from '#lib/ui/SidebarLayout.svelte';

	const groups: SidebarGroup[] = [
		{
			items: [
				{ label: 'Home', href: '#home', icon: Home01Icon },
				{ label: 'Catalog', href: '#catalog', icon: BookOpen01Icon },
				{ label: 'My loans', href: '#loans', icon: Book02Icon },
				{ label: 'Bookings', href: '#bookings', icon: Calendar03Icon }
			]
		},
		{
			title: 'Reading rooms',
			items: [
				{ label: 'Baghdad', href: '#baghdad', icon: Location01Icon },
				{ label: 'Córdoba', href: '#cordoba', icon: Location01Icon },
				{ label: 'Fez', href: '#fez', icon: Location01Icon }
			]
		}
	];
	let current = $state('#catalog');
	const title = $derived(groups.flatMap((g) => g.items).find((i) => i.href === current)?.label);
</script>

<!-- A framed app for the example; in your app, give the layout the whole window. -->
<div class="frame">
	<SidebarLayout label="Library" {groups} {current} onselect={(item) => (current = item.href)}>
		{#snippet header(collapsed)}
			<span class="brand">
				<span class="mark" aria-hidden="true">B</span>
				{#if !collapsed}<strong>Bayt al-Ḥikma</strong>{/if}
			</span>
		{/snippet}
		<div class="page">
			<h4>{title}</h4>
			<p>
				Press ⌘B or Ctrl+B to collapse the sidebar to icons. Make the window narrow for the menu.
			</p>
		</div>
	</SidebarLayout>
</div>

<style>
	.frame {
		inline-size: 100%;
		block-size: 28rem;
		overflow: hidden;
		border-radius: calc(var(--ui-radius) * 1.5);
		background: var(--ui-surface);
		box-shadow: 0 1px 3px rgb(0 0 0 / 0.06);
	}
	.brand {
		display: flex;
		align-items: center;
		gap: 0.625rem;
	}
	.mark {
		display: grid;
		flex: none;
		place-items: center;
		inline-size: 1.75rem;
		block-size: 1.75rem;
		border-radius: calc(var(--ui-radius) * 0.75);
		background: var(--ui-accent);
		color: var(--ui-on-accent);
		font-weight: 600;
	}
	.page {
		padding: 1.25rem 1.5rem;
	}
	h4 {
		margin: 0 0 0.5rem;
		font-size: 1.125rem;
	}
	p {
		margin: 0;
		color: var(--ui-muted);
	}
</style>

Props

PropTypeDefault
labelstring (required)
groups{ title?, items: { label, href, icon }[] }[]
currentstring: href of the page shown
collapsedboolean, bindablefalse
persiststring: remember collapsed under this key
onselect(item) => void
header, footerSnippet

Accessibility

  • A labeled navigation landmark; the current page carries aria-current="page".
  • Collapsed, each icon's tooltip is its name, for sighted people and screen readers alike.
  • The collapse button says whether the sidebar is open, and its shortcut is announced.
  • On narrow screens the same links open in a modal sheet with a close button.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme