YuhuanStudioYunUIDocs
Patterns

Sidebar

App navigation sidebar with grouped sections, mobile drawer, and collapse.

The app navigation sidebar: a logo, grouped nav sections with active-state matching, a mobile drawer, desktop collapse, and a bottom footer slot. Routing flows through the injected Link adapter, or you can own navigation with onNavigate. Each nav item is plain data (label + href); an optional icon component can be added per item in app code.

The sidebar uses position: fixed, so previews place it inside a framed stage with a transform (which makes fixed descendants resolve against the frame instead of the viewport).

Import

tsx
1import { Sidebar } from "@yuhuanowo/yunui/patterns";

Basic

Collapsible

Pass collapsed plus onToggleCollapse to render the desktop collapse button and slide the sidebar off-canvas. Because that needs React state and a function prop, this example renders from a client wrapper.

Props

PropTypeDefaultDescription
appName*stringBrand name shown next to the logo.
ariaLabelstringMain navigationAccessible name for the Sidebar landmark.
childrenReactNodeReplaces generated sections with custom dynamic Sidebar content.
classNamestringAdditional shell classes.
closeLabelstringCloseAccessible label for the close/collapse buttons.
collapsedbooleanfalseDesktop collapse state (hides the sidebar off-canvas).
currentPathstringUsed to compute the active item.
footerReactNodeBottom-pinned slot (balance card, user card, etc.).
headerReactNodeReplaces the built-in logo row while retaining the Sidebar shell.
homeHrefstring/Where the logo links to.
isOpenbooleanfalseMobile drawer open state.
layout"fixed" | "inline"fixedFixed application rail or an in-flow shell owned by the host layout.
loadingbooleanfalseWhile true, the nav (and footer slot) render shimmer skeletons.
logoSrcstring/favicon.icoLogo image src.
onClose(() => void)Called to close the mobile drawer.
onNavigate((href: string) => void)Called when a nav item is clicked. When provided, default link navigation is prevented and the host owns routing (useful in SPAs / demos). When omitted, items navigate via the injected Link adapter.
onToggleCollapse(() => void)Called to toggle the desktop collapse state (also renders the collapse button when set).
role"navigation" | "complementary"navigationLandmark role for custom application layouts.
scrollStorageKeystringyunui-sidebar-scrollsessionStorage key for persisting nav scroll position across navigations.
sections*SidebarSection[]Grouped navigation sections.

On this page