# Sidebar

An app's side rail: header, grouped menu, badges and a footer, beside the page.

Section: Components / Navigation
Page: https://ui.heyramzi.com/components/sidebar
Import path: `@heyramzi/ui/shadcn/sidebar`

## Import

```ts
import * as Sidebar from "@heyramzi/ui/shadcn/sidebar";
```

## Usage

```svelte
<Sidebar.Provider>
  <Sidebar.Root collapsible="none">
    <Sidebar.Content>
      <Sidebar.Group>
        <Sidebar.GroupLabel>Workspace</Sidebar.GroupLabel>
        <Sidebar.GroupContent>
          <Sidebar.Menu>
            <Sidebar.MenuItem>
              <Sidebar.MenuButton isActive>Home</Sidebar.MenuButton>
              <Sidebar.MenuBadge>4</Sidebar.MenuBadge>
            </Sidebar.MenuItem>
          </Sidebar.Menu>
        </Sidebar.GroupContent>
      </Sidebar.Group>
    </Sidebar.Content>
  </Sidebar.Root>
  <Sidebar.Inset>The page sits here.</Sidebar.Inset>
</Sidebar.Provider>
```

## Demo

```svelte
<script lang="ts">
	import * as Sidebar from "@heyramzi/ui/shadcn/sidebar";
	import { ChartBar, Gear, House, Tray, Users } from "phosphor-svelte";

	const rows = [
		{ title: "Home", icon: House },
		{ title: "Inbox", icon: Tray, badge: "4" },
		{ title: "Clients", icon: Users },
		{ title: "Reports", icon: ChartBar },
	];
	let active = $state("Home");
</script>

<!-- `collapsible="none"` keeps the rail in the box: the other modes pin it to the window. -->
<Sidebar.Provider
	style="--sidebar-width: 11rem"
	class="h-88 w-full max-w-2xl rounded-xl border border-border"
>
	<Sidebar.Root collapsible="none" class="border-r border-sidebar-border">
		<Sidebar.Header>
			<span class="px-2 py-1 text-sm font-semibold">Acme</span>
		</Sidebar.Header>
		<Sidebar.Content>
			<Sidebar.Group>
				<Sidebar.GroupLabel>Workspace</Sidebar.GroupLabel>
				<Sidebar.GroupContent>
					<Sidebar.Menu>
						{#each rows as row (row.title)}
							<Sidebar.MenuItem>
								<Sidebar.MenuButton
									isActive={active === row.title}
									onclick={() => (active = row.title)}
								>
									<row.icon aria-hidden="true" />
									<span>{row.title}</span>
								</Sidebar.MenuButton>
								{#if row.badge}<Sidebar.MenuBadge>{row.badge}</Sidebar.MenuBadge>{/if}
							</Sidebar.MenuItem>
						{/each}
					</Sidebar.Menu>
				</Sidebar.GroupContent>
			</Sidebar.Group>
		</Sidebar.Content>
		<Sidebar.Footer>
			<Sidebar.Menu>
				<Sidebar.MenuItem>
					<Sidebar.MenuButton
						isActive={active === "Settings"}
						onclick={() => (active = "Settings")}
					>
						<Gear aria-hidden="true" />
						<span>Settings</span>
					</Sidebar.MenuButton>
				</Sidebar.MenuItem>
			</Sidebar.Menu>
		</Sidebar.Footer>
	</Sidebar.Root>
	<Sidebar.Inset class="min-w-0 p-4 sm:p-6">
		<h3 class="text-base font-semibold">{active}</h3>
		<p class="mt-1 hidden text-sm text-muted-foreground sm:block">
			The page sits in the inset, beside the rail.
		</p>
	</Sidebar.Inset>
</Sidebar.Provider>
```

## API

### Sidebar.Provider

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `open` | `boolean` | `true` | bindable |
| `onOpenChange` | `(open: boolean) => void` | `() => {}` |  |
| `persist` | `boolean` | `true` | False for a sidebar that isn't the app's shell, such as a docs demo: it then writes no state cookie and takes no Cmd+B, so it can't fold the real one. |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `style` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Sidebar.Root

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `side` | `"left" \| "right"` | `"left"` |  |
| `variant` | `"sidebar" \| "floating" \| "inset"` | `"sidebar"` |  |
| `collapsible` | `"offcanvas" \| "icon" \| "none"` | `"offcanvas"` |  |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Sidebar.Header

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.Content

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.Group

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.GroupLabel

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `child` | `Snippet<[{ props: Record<string, unknown> }]>` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `children` | `Snippet` |  |  |
| `class` | `string` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.GroupContent

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### Sidebar.Menu

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLUListElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLUListElement>` from `svelte/elements`.

### Sidebar.MenuItem

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLLIElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLLIElement>` from `svelte/elements`.

### Sidebar.MenuButton

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `isActive` | `boolean` | `false` |  |
| `variant` | `"default"` \| `"outline"` | `"default"` |  |
| `size` | `"default"` \| `"sm"` \| `"lg"` | `"default"` |  |
| `tooltipContent` | `Snippet \| string` |  |  |
| `tooltipContentProps` | `WithoutChildrenOrChild<ComponentProps<typeof Tooltip.Content>>` |  |  |
| `child` | `Snippet<[{ props: Record<string, unknown> }]>` |  |  |
| `ref` | `HTMLButtonElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLButtonElement>` from `svelte/elements`.

### Sidebar.MenuBadge

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.Footer

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.Inset

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.GroupAction

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `child` | `Snippet<[{ props: Record<string, unknown> }]>` |  |  |
| `ref` | `HTMLButtonElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLButtonAttributes` from `svelte/elements`.

### Sidebar.Input

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` |  | `null` | bindable |
| `value` | `string` | `""` | bindable |
| `class` | `string` |  |  |

Every prop of `Input`.

### Sidebar.MenuAction

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `child` | `Snippet<[{ props: Record<string, unknown> }]>` |  |  |
| `showOnHover` | `boolean` | `false` |  |
| `ref` | `HTMLButtonElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLButtonAttributes` from `svelte/elements`.

### Sidebar.MenuSkeleton

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `showIcon` | `boolean` | `false` |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLElement>` from `svelte/elements`.

### Sidebar.MenuSub

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLUListElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLUListElement>` from `svelte/elements`.

### Sidebar.MenuSubButton

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `child` | `Snippet<[{ props: Record<string, unknown> }]>` |  |  |
| `size` | `"sm" \| "md"` | `"md"` |  |
| `isActive` | `boolean` | `false` |  |
| `ref` | `HTMLAnchorElement \| null` | `null` | bindable |
| `children` | `Snippet` |  |  |
| `class` | `string` |  |  |

Every prop of `HTMLAnchorAttributes` from `svelte/elements`.

### Sidebar.MenuSubItem

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLLIElement \| null` | `null` | bindable |
| `children` | `Snippet` |  |  |
| `class` | `string` |  |  |

Every prop of `HTMLAttributes<HTMLLIElement>` from `svelte/elements`.

### Sidebar.Rail

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `label` | `string` | `"Toggle Sidebar"` | The rail's name and hover tooltip, in the app's language. |
| `ref` | `HTMLButtonElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLButtonElement>` from `svelte/elements`.

### Sidebar.Separator

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` |  | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `Separator`.

### Sidebar.Trigger

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `onclick` | `(e: MouseEvent) => void` |  |  |
| `label` | `string` | `"Toggle Sidebar"` | What a screen reader calls the icon-only button, in the app's language. |
| `ref` |  | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `Button`.
