@molecule/app-sidebar-layout-react
Feature · sidebar-layout · App (browser) · v4.2.2 · Apache-2.0
Vertical sidebar app shell: brand block + vertical NavLinks + user-menu slot, with a router outlet for nested routes
npm install @molecule/app-sidebar-layout-reactHow it works
@molecule/app-sidebar-layout-react is a ready-made sidebar-layout feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { SidebarLayout } from '@molecule/app-sidebar-layout-react'
import type { SidebarNavItem } from '@molecule/app-sidebar-layout-react'
const NAV: SidebarNavItem[] = [
{ key: 'dashboard', to: '/dashboard', icon: 'dashboard', label: 'Dashboard' },
{ key: 'projects', to: '/projects', icon: 'folder', label: 'Projects' },
{ key: 'settings', to: '/settings', icon: 'settings', label: 'Settings' },
]
function AppShell() {
return <SidebarLayout appName="Acme App" navItems={NAV} />
}Works with: @molecule/app-react, @molecule/app-ui, @molecule/app-ui-react
Live demos
Running apps built with Molecule that install this package — open the app or study the template.
Reference
Vertical sidebar app shell layout.
Exports <SidebarLayout> plus the SidebarLayoutProps and
SidebarNavItem types — fixed-width left sidebar with brand link,
vertical nav links, and bottom user-menu / theme-toggle slots; the main
area on the right scrolls and renders React Router's <Outlet /> for
nested routes.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { SidebarLayout } from '@molecule/app-sidebar-layout-react'
import type { SidebarNavItem } from '@molecule/app-sidebar-layout-react'
const NAV: SidebarNavItem[] = [
{ key: 'dashboard', to: '/dashboard', icon: 'dashboard', label: 'Dashboard' },
{ key: 'projects', to: '/projects', icon: 'folder', label: 'Projects' },
{ key: 'settings', to: '/settings', icon: 'settings', label: 'Settings' },
]
function AppShell() {
return <SidebarLayout appName="Acme App" navItems={NAV} />
}
Mount it as a LAYOUT ROUTE so child routes render in the main area:
a parent route with element={<AppShell />} and your pages as child
routes. Without children it renders <RoutedView /> from
@molecule/app-react (the matched child route, under any routing bond);
pass the page as children where the router hands it over that way.
Type
feature
Installation
npm install @molecule/app-sidebar-layout-react @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
npm install -D @types/react
API
Interfaces
SidebarNavItem
Describes a single item in the sidebar's vertical navigation list.
interface SidebarNavItem {
/** Route path the link goes to. */
to: string
/** Stable key — used for React keys and i18n key suffix. */
key: string
/** Material symbol icon name. */
icon?: string
/** Visible label. Apps that route this through `t(...)` should pass the resolved string. */
label: string
}
SidebarLayoutProps
Props accepted by the SidebarLayout component.
interface SidebarLayoutProps {
/** Brand text shown at the top of the sidebar (typically the app name). */
appName: string
/** Path the brand link navigates to. Defaults to `'/'`. */
logoTo?: string
/** Vertical nav items rendered in the sidebar. */
navItems: ReadonlyArray<SidebarNavItem>
/** Slot rendered at the bottom of the sidebar (typically a `<UserMenu />`). */
userMenu?: ReactNode
/** Optional slot rendered next to the user menu (typically a `<ThemeToggle />`). */
themeToggle?: ReactNode
/**
* Aria-label for the primary <nav>. Overrides the translated default
* (`sidebarLayout.aria.primaryNavigation`, English `'Primary navigation'`);
* prop > `t()` > default.
*/
navAriaLabel?: string
/**
* Sidebar width — a stack-agnostic preset (`'sm'` | `'md'` | `'lg'`) or an
* exact pixel `number`. Applied via inline style so no Tailwind width utility
* couples consumers to the styling library. Defaults to `'md'` (240px).
*/
sidebarWidth?: SidebarWidth
/**
* Legacy sidebar-width prop retained only for backward compatibility.
*
* @deprecated Use `SidebarLayoutProps.sidebarWidth` instead. A raw
* Tailwind width utility (`'w-60'`, `'w-64'`) coupled consumers to Tailwind.
* Still accepted for backward compatibility: a `w-<n>` value is PARSED to a
* pixel width and applied via inline style (never re-emitted as a class), so
* old callers keep working without reintroducing the coupling. `sidebarWidth`
* takes precedence when both are supplied.
*/
sidebarWidthClass?: string
/** Extra classes on the outer wrapper. */
className?: string
/** `data-mol-id` for AI-agent selectors. */
dataMolId?: string
/**
* The page body, rendered in the `<main>`. Without it the layout renders
* `<RoutedView />`: the matched child route, through whichever routing bond
* the app wired. That throws when the routing bond has no routed view
* (Next.js gives a layout its page as `children`): pass the page then.
*/
children?: ReactNode
}
Types
SidebarWidth
Semantic sidebar width. Mapped to a fixed pixel width internally and applied via inline style (a width is one of the "specific values" a styling-agnostic ClassMap cannot express as a swappable token) so the sidebar renders the same regardless of which ClassMap bond is active — no Tailwind width utility leaks into consumer code.
sm→ 208px,md→ 240px (default),lg→ 256px.- Pass a raw
numberfor an exact pixel width.
type SidebarWidth = 'sm' | 'md' | 'lg' | number
Functions
SidebarLayout(props)
Vertical sidebar shell with brand + vertical nav + bottom user-menu slot.
function SidebarLayout({
appName,
logoTo = '/',
navItems,
userMenu: userMenuProp,
themeToggle: themeToggleProp,
navAriaLabel,
sidebarWidth,
sidebarWidthClass,
className,
dataMolId,
children: childrenProp,
}: SidebarLayoutProps): ReactElement
props— Component props.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-react^4.13.0 || ^5.0.0@molecule/app-ui^1.6.1@molecule/app-ui-react^4.4.0react^18.0.0 || ^19.0.0
Runtime Dependencies
-
@molecule/app-react -
@molecule/app-ui -
@molecule/app-ui-react -
react -
Router required: reads the location through
@molecule/app-reactand throws an error naming the fix without the router component of the app's routing bond above it (or, given no children, under a bond with no routed view). -
Fully ClassMap-driven: every layout/surface/border/text/state class is resolved through
getClassMap()(cm.pageShell,cm.page,cm.surface,cm.borderR,cm.bgPrimarySubtle/cm.textPrimaryfor the active item,cm.textMuted/cm.linkfor the rest, …), so swapping the ClassMap bond restyles the whole shell — no raw Tailwind/Material-3 utility class is baked in. The sidebar WIDTH is the one "specific value" a styling-agnostic ClassMap can't express, so it is applied via inline style: use the stack-agnosticsidebarWidthprop ('sm'|'md'|'lg'|pixelnumber), NOT a Tailwind width utility. The oldsidebarWidthClassprop is@deprecated— still accepted, but itsw-<n>value is parsed to pixels (never re-emitted as a class). -
iconvalues are Material Symbols ligature names rendered with thematerial-symbols-outlinedfont class — the one documented icon-font exception (a font ligature the consumer supplies as data, not a hardcoded chrome glyph). Without the Material Symbols font loaded, the raw icon NAME shows as text — omiticonwhen the font is not shipped. -
Active-nav highlighting picks the longest prefix-match of the current path; same-path clicks get a
#topfragment appended (same behavior as@molecule/app-safe-link-react). -
navAriaLabeloverrides the translated nav region name; without it the label comes fromt('sidebarLayout.aria.primaryNavigation')(English default'Primary navigation'), so it follows a locale switch through its companion locale bond (@molecule/app-locales-sidebar-layout). Nav itemlabels stay plain caller strings — translate them upstream. -
Requires a bonded ClassMap. Sibling:
@molecule/app-shell-layout-reactis the top header/footer shell (router-free).
Translations
Translation strings are provided by @molecule/app-locales-sidebar-layout.