4.2.0
Core

Sidebar

The collapsible rail system โ€” a rail the reader opens and closes, assembled part by part rather than handed a list.

Default

The whole anatomy in one rail โ€” header, eyebrow-labelled groups, a group action, a badge, a submenu, a footer โ€” beside the main column it pushes. `collapsible="icon"` keeps the rail on screen as a 3rem strip, so the trigger, the rail edge and Cmd-B all lead somewhere; each item's tooltip is then the only name it has, which is why they are declared rather than optional.

Overview

The rail scrolls on its own; this column scrolls independently. Selected is brand-soft, hover is the accent tint โ€” two states you can tell apart, which upstream's single fill could not.

Usage

import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarGroupAction,
  SidebarGroupContent,
  SidebarGroupLabel,
  SidebarHeader,
  SidebarInput,
  SidebarInset,
  SidebarMenu,
  SidebarMenuAction,
  SidebarMenuBadge,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarMenuSkeleton,
  SidebarMenuSub,
  SidebarMenuSubButton,
  SidebarMenuSubItem,
  SidebarProvider,
  SidebarRail,
  SidebarSeparator,
  SidebarTrigger,
  useSidebar,
} from '@oceanic-hub/brand-system'
<SidebarProvider>
  <Sidebar>
    <SidebarHeader>
      <SidebarInput>โ€ฆ</SidebarInput>
    </SidebarHeader>
    <SidebarSeparator>โ€ฆ</SidebarSeparator>
    <SidebarContent>
      <SidebarGroup>
        <SidebarGroupLabel>โ€ฆ</SidebarGroupLabel>
        <SidebarGroupAction>โ€ฆ</SidebarGroupAction>
        <SidebarGroupContent>
          <SidebarMenu>
            <SidebarMenuItem>
              <SidebarMenuButton>โ€ฆ</SidebarMenuButton>
              <SidebarMenuBadge>โ€ฆ</SidebarMenuBadge>
              <SidebarMenuSub>
                <SidebarMenuSubItem>
                  <SidebarMenuSubButton>โ€ฆ</SidebarMenuSubButton>
                </SidebarMenuSubItem>
              </SidebarMenuSub>
            </SidebarMenuItem>
          </SidebarMenu>
        </SidebarGroupContent>
      </SidebarGroup>
    </SidebarContent>
    <SidebarFooter>
      <SidebarMenu>
        <SidebarMenuItem>
          <SidebarMenuButton>โ€ฆ</SidebarMenuButton>
        </SidebarMenuItem>
      </SidebarMenu>
    </SidebarFooter>
    <SidebarRail>โ€ฆ</SidebarRail>
  </Sidebar>
  <SidebarInset>
    <SidebarTrigger>โ€ฆ</SidebarTrigger>
  </SidebarInset>
</SidebarProvider>

Composition

Use the following composition to build a Sidebar:

SidebarProvider
โ”œโ”€โ”€ Sidebar
โ”‚   โ”œโ”€โ”€ SidebarHeader
โ”‚   โ”‚   โ””โ”€โ”€ SidebarInput
โ”‚   โ”œโ”€โ”€ SidebarSeparator
โ”‚   โ”œโ”€โ”€ SidebarContent
โ”‚   โ”‚   โ””โ”€โ”€ SidebarGroup ร—2
โ”‚   โ”‚       โ”œโ”€โ”€ SidebarGroupLabel
โ”‚   โ”‚       โ”œโ”€โ”€ SidebarGroupAction
โ”‚   โ”‚       โ””โ”€โ”€ SidebarGroupContent
โ”‚   โ”‚           โ””โ”€โ”€ SidebarMenu
โ”‚   โ”‚               โ””โ”€โ”€ SidebarMenuItem ร—3
โ”‚   โ”‚                   โ”œโ”€โ”€ SidebarMenuButton
โ”‚   โ”‚                   โ”œโ”€โ”€ SidebarMenuBadge
โ”‚   โ”‚                   โ”œโ”€โ”€ SidebarMenuSub
โ”‚   โ”‚                   โ”‚   โ””โ”€โ”€ SidebarMenuSubItem ร—2
โ”‚   โ”‚                   โ”‚       โ””โ”€โ”€ SidebarMenuSubButton
โ”‚   โ”‚                   โ””โ”€โ”€ SidebarMenuSkeleton
โ”‚   โ”œโ”€โ”€ SidebarFooter
โ”‚   โ”‚   โ””โ”€โ”€ SidebarMenu
โ”‚   โ”‚       โ””โ”€โ”€ SidebarMenuItem
โ”‚   โ”‚           โ””โ”€โ”€ SidebarMenuButton
โ”‚   โ””โ”€โ”€ SidebarRail
โ””โ”€โ”€ SidebarInset
    โ””โ”€โ”€ SidebarTrigger

A list of links is WorkspaceNav. A rail the user operates is this. Three components answer three questions and all three ship: AppShell is a layout FRAME, a nav slot beside a column that scrolls on its own, with no state and no opinion about what goes in the slot; WorkspaceNav is Oceanic's OPINIONATED rail, driven by data โ€” you hand it sections and items and it renders the whole thing, which is most products most of the time; this is a rail SYSTEM, driven by composition, and it brings what neither of the others has and neither could grow without becoming this: a provider, an open state with a keyboard shortcut, an icon-only collapsed mode, a mobile sheet, a rail edge that toggles it, groups with their own actions, submenus and loading skeletons. Reach for it when the rail has STATE and STRUCTURE โ€” nested sections, per-item actions, a collapse the reader controls and the app remembers. Reaching for it to render five links means adopting a provider and twenty-odd parts to avoid writing an array. They compose (provider + rail + inset replaces AppShell outright, since it brings its own frame); what you must not do is nest them, because two rails is two theories of "you are here".

Persistence is the host's half of the deal. The provider writes sidebar_state on every toggle and never reads it โ€” a read on mount would render the wrong rail and then jump โ€” so the host reads that cookie where it can (a server component, middleware, a loader) and passes the answer as defaultOpen. A host that never reads it gets a rail that resets on every reload, and no error anywhere saying why.

If it can collapse to icons, every item needs its tooltip. In the collapsed rail an item has no visible label at all, so the tooltip is not a nicety โ€” it is the only name the thing has, which is why the provider drops the tooltip delay to zero against this package's 200ms house default. A menu button with no tooltip becomes an anonymous glyph the moment a reader collapses the rail.

Selected is not hover here, and that is deliberate. Upstream paints data-[active=true] and :hover with the same fill, so the item you are on and the item under your pointer are indistinguishable; ours paints selection brand-soft with a brand label, which is what WorkspaceNav already does โ€” two rails in one product that disagree about "you are here" is worse than either choice. The other divergences are the doctrine's: floating and inset lift with a 1px hairline rather than a shadow, the group label takes the house eyebrow instead of a fourth kind of heading, and the whole colour layer is substituted, because none of upstream's sidebar-*, accent, muted or secondary names exists in this theme and pasting them ships a rail with no hover state at all, on a green build.

SidebarRail is not a drag handle, whatever the cursor suggests. It is a rail edge that toggles the sidebar on click โ€” it wears a resize cursor but nothing drags, the width is fixed, and it is not keyboard-reachable (tabIndex={-1}), which is why the trigger and the shortcut are the two routes that have to work.

Two things no demo on this page can show. Below 768px the rail becomes a Sheet โ€” the same parts, rendered as an off-canvas panel with its own open state, which is why the mobile rail ignores defaultOpen and always starts closed. And RTL is not supported: upstream's page carries an RTL section and a changelog entry for it, nothing in this package has ever been laid out or measured right-to-left, and the refusal is written down in pairings.json under direction rather than left to be discovered. One number is flagged rather than fixed: the dense row sizes are 28px, under the 32px touch floor Button pins, kept because the nested sub-button is that height too and shipping one while refusing the other would be incoherent.

Slid away

collapsible="offcanvas" is what you get by default, and it takes the rail off the surface entirely rather than shrinking it โ€” reach for it when the main column is the work (a document, a canvas, a long table) and the nav is somewhere you visit. This one starts closed, which is the state worth seeing: nothing but the trigger, and Cmd-B brings the rail back.

Run 4181

Open the rail from the trigger, the keyboard shortcut, or the rail edge at the left. Nothing here reserves a column for it while it is away.

A rail that never collapses

collapsible="none" is a different render path, not a locked one: no fixed positioning, no spacer column, no mobile sheet, and none of the provider's state reaches it. Reach for it when the nav is the point โ€” a settings screen, an admin console โ€” and a rail a user can lose is a support ticket. The provider is still required, because the parts read it.

Settings
Workspace

Members

No trigger and no rail handle, because there is nothing to toggle. The provider is still listening for Cmd-B; this rail simply never reads the state it flips.

Floating

variant="floating" lifts the rail off the canvas: air on all four sides and its own bounded card. Reach for it when the rail is one panel among several rather than the edge of the app. Upstream lifts it with a shadow; here it is the 1px hairline the whole system uses for elevation, so a floating rail and a card read as the same kind of thing.

Overview

Inset

variant="inset" lifts the MAIN COLUMN instead of the rail: the canvas darkens behind it and the content sits in its own bounded panel. Reach for it when the page beneath is a workspace rather than a document. It only reads as inset if SidebarInset is the sibling right after Sidebar โ€” the margin and the boundary are drawn by the rail's own peer selectors.

Overview

The panel keeps its corner and its boundary whether the rail is open or collapsed.

On the right

side="right" anchors the rail to the other edge, and everything that has a direction follows it: the border moves to the left face, the rail edge swaps sides and its resize cursor flips. Reach for it for a secondary rail โ€” properties, an activity log, an assistant โ€” with the primary nav still on the left. Two rails on the same side is one rail too many.

Run 4181

The main column comes first in the markup here; the rail is the panel it opens.

Controlled

Hand the provider open and onOpenChange and the host owns the state โ€” a URL parameter, a saved preference, a rail that opens itself when a job fails. The trigger, the rail edge and Cmd-B all still work; they call onOpenChange instead of setting anything themselves. Reach for this when something other than the user has to be able to open the rail.

open โ€” true
Overview

Loading

SidebarMenuSkeleton holds the rail's shape while the nav is still being fetched โ€” reach for it when the item list comes from the server, so the rail does not appear a second time in a different size once it arrives.

Pipeline

API Reference

See the Sidebar API page for every prop of every part, with types, defaults and the contract that pins them. It also documents useSidebar and sidebarMenuButtonVariants โ€” exported alongside the parts, and signatures rather than props.

On this page