Sidebar
LayoutAn app's layout with a navigation panel: <Sidebar.Root> (bind:open, collapsible: offcanvas by default, icon or none) holds a Sidebar.Panel and a Sidebar.Inset (the page, main), where a Sidebar.Trigger shows and hides the panel. The panel has a Sidebar.Header, a Sidebar.Content (a navigation landmark, label) of Sidebar.Groups, each named by a Sidebar.GroupLabel and holding a Sidebar.Menu of Sidebar.MenuItems, and a Sidebar.Footer. A Sidebar.MenuButton is a link with href (a button without); active marks the current page, which the app passes from its router; its text goes in a <span>, hidden but still read when the panel collapses to icons; a Sidebar.MenuBadge shows a count. Below the md breakpoint the panel is a sheet from the left (bind:openMobile) that closes when a page is chosen.
import { Sidebar } from '@limerdev/zest'; NavigationMenu). Tabs within one page: use Tabs. A panel of details or a form: use Sheet.Examples
App frame
An app frame that collapses to icons. In an app it fills the screen; here it is sized to fit the preview. active comes from the app's router.
<script lang="ts">
import { Sidebar } from '@limerdev/zest';
import FileText from '@lucide/svelte/icons/file-text';
import LayoutDashboard from '@lucide/svelte/icons/layout-dashboard';
import Settings from '@lucide/svelte/icons/settings';
import Timer from '@lucide/svelte/icons/timer';
import Users from '@lucide/svelte/icons/users';
import type { Component } from 'svelte';
type Page = { href: string; label: string; icon: Component; count?: number };
type Section = { label: string; pages: Page[] };
const sections: Section[] = [
{
label: 'Billing',
pages: [
{ href: '#overview', label: 'Overview', icon: LayoutDashboard },
{ href: '#invoices', label: 'Invoices', icon: FileText, count: 12 },
{ href: '#customers', label: 'Customers', icon: Users }
]
},
{
label: 'Time',
pages: [{ href: '#entries', label: 'Time entries', icon: Timer }]
}
];
let current = $state('#invoices');
</script>
<div class="h-[26rem] w-full overflow-hidden rounded-box border border-border">
<Sidebar.Root collapsible="icon" class="h-full min-h-0">
<Sidebar.Panel class="static h-full">
<Sidebar.Header>
<span class="truncate px-2 py-1 font-semibold group-data-[icon-only]/sidebar:sr-only">
Acme Billing
</span>
</Sidebar.Header>
<Sidebar.Content>
{#each sections as section (section.label)}
<Sidebar.Group>
<Sidebar.GroupLabel>{section.label}</Sidebar.GroupLabel>
<Sidebar.Menu>
{#each section.pages as item (item.href)}
<Sidebar.MenuItem>
<Sidebar.MenuButton
href={item.href}
active={current === item.href}
onclick={(event: MouseEvent) => {
event.preventDefault();
current = item.href;
}}
>
<item.icon aria-hidden="true" />
<span>{item.label}</span>
</Sidebar.MenuButton>
{#if item.count}
<Sidebar.MenuBadge>{item.count}</Sidebar.MenuBadge>
{/if}
</Sidebar.MenuItem>
{/each}
</Sidebar.Menu>
</Sidebar.Group>
{/each}
</Sidebar.Content>
<Sidebar.Footer>
<Sidebar.Menu>
<Sidebar.MenuItem>
<Sidebar.MenuButton href="#settings">
<Settings aria-hidden="true" />
<span>Settings</span>
</Sidebar.MenuButton>
</Sidebar.MenuItem>
</Sidebar.Menu>
</Sidebar.Footer>
</Sidebar.Panel>
<Sidebar.Inset>
<header class="flex h-12 items-center gap-2 border-b border-border px-3">
<Sidebar.Trigger />
<span class="text-sm font-medium">
{sections.flatMap((section) => section.pages).find((p) => p.href === current)?.label}
</span>
</header>
<div class="p-4 text-sm text-muted">The page.</div>
</Sidebar.Inset>
</Sidebar.Root>
</div> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
Sidebar.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| collapsible | "none" | "icon" | "offcanvas" | 'offcanvas' | How the panel collapses on a wide screen: off the screen (offcanvas), to its icons (icon), or not at all (none). |
| open bindable | boolean | true | Whether the panel is expanded on a wide screen. |
| openMobile bindable | boolean | false | Whether the panel's sheet is open on a small screen. |
Sidebar.Panel
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | the Config's `strings.sidebar`, else 'Sidebar' | The name of the panel's sheet on a small screen. |
Sidebar.Header
No props of its own beyond the common ones.
Sidebar.Content
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | the Config's `strings.mainNavigation`, else 'Main' | The name of the navigation landmark. |
Sidebar.Footer
No props of its own beyond the common ones.
Sidebar.Group
No props of its own beyond the common ones.
Sidebar.GroupLabel
No props of its own beyond the common ones.
Sidebar.Menu
No props of its own beyond the common ones.
Sidebar.MenuItem
No props of its own beyond the common ones.
Sidebar.MenuButton
| Prop | Type | Default | Description |
|---|---|---|---|
| active | boolean | false | Marks the current page: aria-current="page" and the active look. The app knows its route and passes it. |
Sidebar.MenuBadge
No props of its own beyond the common ones.
Sidebar.Trigger
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | the Config's `strings.toggleSidebar`, else 'Toggle sidebar' | The button's name for screen readers. |
| size | "default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg" | 'icon-sm' | The height and padding, from the theme's field size; the icon sizes are square. |
| variant | "link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost" | 'ghost' | The look, by the theme's colour roles: primary for the main action, error for deleting, secondary, neutral and outline for the rest, ghost in toolbars, link for a navigation that looks like text. |
Sidebar.Inset
No props of its own beyond the common ones.