Navigation
Sidebar layout
The frame of an app: navigation down the side, the page beside it.
Installation
npx sinaui add sidebar-layoutCopy src/lib/ui/SidebarLayout.svelte, Dialog.svelte, Tooltip.svelte, Popover.svelte, floating.ts, glide.ts, Icon.svelte and tokens.css. No other dependencies.
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 },
{
label: 'Samarkand',
href: '#samarkand',
icon: Location01Icon,
badge: 'Soon',
disabled: true
}
]
}
];
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: var(--ui-radius);
background: var(--ui-surface);
border: 1px solid var(--ui-field-line);
}
.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: var(--ui-radius);
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>Inset
inset sets the page on its own rounded panel, a little in from the window, with the sidebar on the window's tint.
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="Scriptorium"
inset
{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: var(--ui-radius);
background: var(--ui-surface);
border: 1px solid var(--ui-field-line);
}
.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: var(--ui-radius);
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>Pages under pages
An item with children opens an indented list; it's open while one of its pages is current, and the parent is marked current while it's closed. Children's icons are optional.
Maps
Collections opened by itself, since its Maps page is current. Collapsed to icons, a parent opens its pages beside the rail.
<script lang="ts">
import { BookOpen01Icon, 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: 'Collections',
href: '#collections',
icon: BookOpen01Icon,
children: [
{ label: 'Manuscripts', href: '#manuscripts' },
{ label: 'Maps', href: '#maps' },
{ label: 'Star charts', href: '#star-charts', badge: 3 }
]
},
{
label: 'Reading rooms',
href: '#rooms',
icon: Location01Icon,
children: [
{ label: 'Baghdad', href: '#baghdad' },
{ label: 'Córdoba', href: '#cordoba' }
]
}
]
}
];
let current = $state('#maps');
const title = $derived(
groups
.flatMap((g) => g.items)
.flatMap((i) => i.children ?? [i])
.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="Archive" {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>
Collections opened by itself, since its Maps page is current. Collapsed to icons, a parent
opens its pages beside the rail.
</p>
</div>
</SidebarLayout>
</div>
<style>
.frame {
inline-size: 100%;
block-size: 28rem;
overflow: hidden;
border-radius: var(--ui-radius);
background: var(--ui-surface);
border: 1px solid var(--ui-field-line);
}
.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: var(--ui-radius);
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>With a top bar
crumbs puts a breadcrumb in a bar above the page, and the topbar snippet adds your actions at its end. The collapse button moves into the bar.
The collapse button and the breadcrumb sit in the top bar, your actions at its end.
<script lang="ts">
import { BookOpen01Icon, Home01Icon } from '@hugeicons/core-free-icons';
import Button from '#lib/ui/Button.svelte';
import SidebarLayout, { type SidebarGroup } from '#lib/ui/SidebarLayout.svelte';
const groups: SidebarGroup[] = [
{
items: [
{ label: 'Home', href: '#top-home', icon: Home01Icon },
{ label: 'Catalog', href: '#top-catalog', icon: BookOpen01Icon }
]
}
];
let current = $state('#top-home');
</script>
<div class="frame">
<SidebarLayout
label="Reading room"
{groups}
{current}
crumbs={[
{ label: 'Reading room', href: '#top-home' },
{ label: current === '#top-home' ? 'Home' : 'Catalog' }
]}
onselect={(item) => (current = item.href)}
>
{#snippet topbar()}
<Button variant="secondary">Reserve a seat</Button>
{/snippet}
<p class="page">
The collapse button and the breadcrumb sit in the top bar, your actions at its end.
</p>
</SidebarLayout>
</div>
<style>
.frame {
inline-size: 100%;
block-size: 20rem;
overflow: hidden;
border-radius: var(--ui-radius);
background: var(--ui-surface);
border: 1px solid var(--ui-field-line);
}
.page {
margin: 0;
padding: 1.25rem 1.5rem;
color: var(--ui-muted);
}
</style>Studio dashboard
A full app shell: a search that narrows the menu, titled groups, a product switcher at the foot and a top bar with a breadcrumb and actions.
Conversations
Search the menu, or press ⌘B or Ctrl+B to fold it to icons.
<script lang="ts">
import {
Add01Icon,
Alert02Icon,
BubbleChatIcon,
CallOutgoing01Icon,
Chemistry01Icon,
DashboardSquare02Icon,
Folder01Icon,
Home01Icon,
Message01Icon,
Notification01Icon,
PuzzleIcon,
RadioIcon,
SentIcon,
SmartPhone01Icon,
UserMultipleIcon,
Wrench01Icon
} from '@hugeicons/core-free-icons';
import Button from '#lib/ui/Button.svelte';
import Icon from '#lib/ui/Icon.svelte';
import SearchField from '#lib/ui/SearchField.svelte';
import SidebarLayout, { type SidebarGroup } from '#lib/ui/SidebarLayout.svelte';
const all: SidebarGroup[] = [
{
items: [
{ label: 'Home', href: '#studio-home', icon: Home01Icon },
{ label: 'Guide', href: '#studio-guide', icon: SentIcon },
{ label: 'Issues', href: '#studio-issues', icon: Alert02Icon, badge: 2 }
]
},
{
title: 'Agents',
items: [{ label: 'Create agent', href: '#studio-create', icon: Add01Icon }]
},
{
title: 'Configure',
items: [
{ label: 'Knowledge base', href: '#studio-knowledge', icon: Folder01Icon },
{ label: 'Tools', href: '#studio-tools', icon: Wrench01Icon },
{ label: 'Integrations', href: '#studio-integrations', icon: PuzzleIcon },
{ label: 'Voices', href: '#studio-voices', icon: DashboardSquare02Icon }
]
},
{
title: 'Monitor',
items: [
{ label: 'Conversations', href: '#studio-conversations', icon: Message01Icon },
{ label: 'Users', href: '#studio-users', icon: UserMultipleIcon },
{ label: 'Tests', href: '#studio-tests', icon: Chemistry01Icon }
]
},
{
title: 'Deploy',
items: [
{ label: 'Channels', href: '#studio-channels', icon: RadioIcon },
{ label: 'Phone numbers', href: '#studio-phones', icon: SmartPhone01Icon },
{ label: 'Chat apps', href: '#studio-chat', icon: BubbleChatIcon },
{ label: 'Outbound', href: '#studio-outbound', icon: CallOutgoing01Icon }
]
}
];
let query = $state('');
// Searching narrows the menu to matching pages; empty groups drop out.
const groups = $derived(
all
.map((g) => ({
...g,
items: g.items.filter((i) => i.label.toLowerCase().includes(query.trim().toLowerCase()))
}))
.filter((g) => g.items.length)
);
let current = $state('#studio-conversations');
const title = $derived(all.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="Studio"
{groups}
{current}
crumbs={[{ label: 'Studio', href: '#studio-home' }, { label: title ?? '' }]}
onselect={(item) => (current = item.href)}
>
{#snippet header(collapsed)}
<div class="head">
<strong class="logo">{collapsed ? 'B' : 'Bayt al-Ḥikma'}</strong>
{#if !collapsed}
<SearchField
label="Search pages"
hideLabel
placeholder="Search & create"
bind:value={query}
/>
{/if}
</div>
{/snippet}
{#snippet footer()}
<div class="product">
<span class="swatch" aria-hidden="true"></span>
<span class="name">Agents</span>
<Button size="sm" variant="outline">Switch</Button>
</div>
{/snippet}
{#snippet topbar()}
<span class="actions">
<Button variant="secondary">What's new</Button>
<Button variant="secondary">Docs</Button>
<Button variant="secondary" square aria-label="Notifications">
<Icon icon={Notification01Icon} size={16} />
</Button>
</span>
{/snippet}
<div class="page">
<h4>{title}</h4>
<p>Search the menu, or press ⌘B or Ctrl+B to fold it to icons.</p>
</div>
</SidebarLayout>
</div>
<style>
.frame {
inline-size: 100%;
block-size: 36rem;
overflow: hidden;
border-radius: var(--ui-radius);
background: var(--ui-surface);
border: 1px solid var(--ui-field-line);
}
.head {
display: grid;
gap: 0.75rem;
}
.logo {
font-size: 1.0625rem;
font-weight: 700;
letter-spacing: -0.02em;
}
.product {
display: flex;
align-items: center;
gap: 0.625rem;
padding-inline: 0.5rem 0;
}
.swatch {
inline-size: 1rem;
block-size: 1rem;
border-radius: var(--ui-radius-control);
background: var(--ui-fg);
}
.name {
flex: 1;
min-inline-size: 0;
}
.actions {
display: flex;
gap: 0.375rem;
}
@container (width < 34rem) {
.actions {
display: none;
}
}
.page {
padding: 2rem 2.5rem;
}
.page h4 {
margin: 0 0 0.5rem;
font-size: 1.5rem;
font-weight: 400;
letter-spacing: -0.15px;
}
.page p {
margin: 0;
color: var(--ui-muted);
}
</style>Props
| Prop | Type | Default |
|---|---|---|
label | string (required) | |
groups | { title?, items: { label, href, icon?, badge?, disabled?, children? }[] }[]: children are items too, opened from their parent; icon is needed at the top level for
the rail; badge is a count, or a word such as "Soon" shown muted; disabled shows an item that isn't a link yet | |
current | string: href of the page shown | |
collapsed | boolean, bindable | false |
persist | string: remember collapsed under this key | |
onselect | (item) => void | |
header, footer | Snippet | |
topbar | Snippet: a bar above the page; holds the collapse button | |
crumbs | { label, href? }[]: a breadcrumb in the top bar, the last item being the
current page | |
inset | boolean: the page on a rounded panel inset from the window, the sidebar on the
window's tint | false |
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.
- A parent is a button that says whether its pages are shown (
aria-expanded), and carriesaria-currentwhile it holds the current page out of sight. In the rail it opens its pages in a flyout: Escape closes it and returns focus. - 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.
Theming
--ui-sidebar-bg colors the sidebar and --ui-sidebar-line its edges (a
hairline by default). --ui-sidebar-current-bg and --ui-sidebar-current-fg color the current page's highlight.