SidebarNav

A composable sidebar navigation with sections, active state and framework-agnostic link rendering.

Basic

SidebarNav renders a vertical nav from a sections array. Pass pathname to highlight the active item.

const sections = [
{
  label: 'Main',
  items: [
    { label: 'Dashboard', href: '/dashboard' },
    { label: 'Analytics', href: '/dashboard/analytics' },
  ],
},
{
  label: 'Settings',
  items: [
    { label: 'Settings', href: '/dashboard/settings' },
  ],
},
];

<SidebarNav sections={sections} pathname="/dashboard" />

With logo and title

Pass logo and title to render a branded header above the nav sections.

<SidebarNav
sections={sections}
pathname="/dashboard"
logo={<img src="/logo.svg" width={24} height={24} alt="" />}
title="My App"
titleHref="/"
/>

With Next.js Link

Pass linkComponent={Link} to enable client-side navigation. Any component that accepts an href prop works.

import Link from 'next/link';

<SidebarNav
sections={sections}
pathname={pathname}
linkComponent={Link}
title="My App"
/>

Collapsible sections

Set collapsible on a section to let users expand and collapse it. Use defaultCollapsed to start it closed.

const sections = [
{
  label: 'Main',
  items: [
    { label: 'Dashboard', href: '/dashboard' },
  ],
},
{
  label: 'Advanced',
  collapsible: true,
  defaultCollapsed: true,
  items: [
    { label: 'API keys', href: '/dashboard/api-keys' },
    { label: 'Webhooks', href: '/dashboard/webhooks' },
  ],
},
];

<SidebarNav sections={sections} pathname={pathname} />

Props

SidebarNav

PropTypeDefaultDescription
sectionsSidebarNavSection[]Array of section groups, each with a label and items
pathnamestringCurrent URL path used to highlight the active item
titlestringBrand name rendered in the sidebar header
titleHrefstring'/'Link target for the logo/title area
logoReactNodeLogo element rendered before the title
linkComponentElementType'a'Component used to render links — pass Link from Next.js for client-side routing
classNamestringAdditional Tailwind classes on the nav element

SidebarNavSection

PropTypeDefaultDescription
labelstringSection heading text
itemsSidebarNavItem[]Nav items belonging to this section
collapsiblebooleanAllows the section to be toggled open and closed
defaultCollapsedbooleanWhen collapsible is true, starts the section collapsed

SidebarNavItem

PropTypeDefaultDescription
labelstringDisplay text for the nav item
hrefstringLink destination, compared against pathname to determine active state