# Sidebar

> Bordered navigation sidebar with sections, icons, counts and an accent bar on the active item.

Status: stable. Category: Patterns.

```ts
import { Sidebar, SidebarHeader, SidebarContent, SidebarSection, SidebarItem, SidebarFooter } from '@glyphui/ui'
```

Exports: `Sidebar`, `SidebarHeader`, `SidebarContent`, `SidebarSection`, `SidebarItem`, `SidebarFooter`, `SidebarTrigger`, `sidebarStyles`.

## Notes

- SidebarItem renders a link through GlyphProvider linkComponent when href is set, otherwise a button.
- The active item gets aria-current="page".

## SidebarItem props

| Prop | Type | Default | Description |
|---|---|---|---|
| `active` | `boolean` |  | Marks the current page. Computed from the provider's `router` when not set. |
| `badge` | `ReactNode` |  | Count or short status shown at the end. |
| `className` | `string` |  |  |
| `end` | `boolean` |  | With automatic matching, only the exact path is active (not its children). |
| `href` | `string` |  | Renders a link through the provider's `linkComponent`. Without it, renders a button. |
| `icon` | `ReactNode` |  |  |
| `onClick` | `((event: MouseEvent<HTMLElement, MouseEvent>) => void)` |  |  |

## Example: Sections and footer

```tsx
import {
  AppShell,
  Avatar,
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarHeader,
  SidebarItem,
  SidebarSection,
  Text,
} from '@glyphui/ui'
import { CircleDot, Inbox, Layers, Users } from 'lucide-react'
import { useState } from 'react'

export default function Example() {
  const [active, setActive] = useState('issues')
  const item = (id: string) => ({ active: active === id, onClick: () => setActive(id) })
  return (
    <div className="h-[26rem] overflow-hidden rounded-lg border border-border">
      <AppShell
        layout="embedded"
        sidebar={
          <Sidebar>
            <SidebarHeader>
              <span className="text-small font-semibold">Acme Inc.</span>
            </SidebarHeader>
            <SidebarContent>
              <SidebarSection>
                <SidebarItem icon={<Inbox />} badge={3} {...item('inbox')}>
                  Inbox
                </SidebarItem>
                <SidebarItem icon={<CircleDot />} badge={12} {...item('issues')}>
                  Issues
                </SidebarItem>
                <SidebarItem icon={<Layers />} {...item('views')}>
                  Views
                </SidebarItem>
              </SidebarSection>
              <SidebarSection label="Teams">
                <SidebarItem icon={<Users />} {...item('design')}>
                  Design
                </SidebarItem>
                <SidebarItem icon={<Users />} {...item('engineering')}>
                  Engineering
                </SidebarItem>
              </SidebarSection>
            </SidebarContent>
            <SidebarFooter>
              <Avatar name="Ada Lovelace" size="sm" />
              <span className="truncate text-small font-medium">Ada Lovelace</span>
            </SidebarFooter>
          </Sidebar>
        }
      >
        <div className="p-5">
          <Text tone="muted">Selected: {active}</Text>
        </div>
      </AppShell>
    </div>
  )
}
```

## Example: Collapsed rail

Labels become tooltips when the sidebar is collapsed.

```tsx
import { AppShell, Sidebar, SidebarContent, SidebarItem, SidebarTrigger, Text } from '@glyphui/ui'
import { CircleDot, Inbox, SquareKanban } from 'lucide-react'

export default function Example() {
  return (
    <div className="h-72 overflow-hidden rounded-lg border border-border">
      <AppShell
        layout="embedded"
        defaultCollapsed
        sidebar={
          <Sidebar>
            <SidebarContent>
              <SidebarItem icon={<Inbox />} badge={3}>
                Inbox
              </SidebarItem>
              <SidebarItem icon={<CircleDot />} active>
                Issues
              </SidebarItem>
              <SidebarItem icon={<SquareKanban />}>Projects</SidebarItem>
            </SidebarContent>
          </Sidebar>
        }
      >
        <div className="flex items-center gap-2 p-4">
          <SidebarTrigger />
          <Text size="small" tone="muted">
            Toggle the rail
          </Text>
        </div>
      </AppShell>
    </div>
  )
}
```

Live page: https://glyphui.xyz/components/sidebar
