Skip to main content

Side Navigation Block

SideNavigation is a collapsible side menu built on MUI Stack (component="aside"), with optional floating overlay mode and data-driven links.

Installation

npm install @nodeblocks/frontend-side-navigation-block

What You Need

ItemWhy it matters
linksNavigation items (href, optional text, icon, isActive, unreadCount)
header (optional)Top link with optional icon and label
isMenuOpen / setIsMenuOpen (optional)Control open state together; omit both to use internal state (starts closed)
isFloating (optional)Floating drawer with portal, backdrop, and close button (false by default)
Controlled open state

Pass isMenuOpen and setIsMenuOpen together when you control the menu from the parent. If you omit both, the block keeps its own state (closed until the menu button is clicked).

Live examples

Examples use inline mode (isFloating={false}) and start with the menu open so the sidebar is visible in the doc preview. Use isFloating for a drawer with portal and backdrop (see Storybook).

Code Examples

Live Editor
function Example() {
  const [isMenuOpen, setIsMenuOpen] = React.useState(true);

  return (
    <div style={{ minHeight: 320 }}>
      <SideNavigation
        isFloating={false}
        isMenuOpen={isMenuOpen}
        setIsMenuOpen={setIsMenuOpen}
        header={{ icon: HomeOutlined, text: 'Home', href: '#home' }}
        links={[
          { icon: DashboardOutlined, text: 'Dashboard', href: '#dashboard' },
          { icon: ShoppingCartOutlined, text: 'Products', href: '#products' },
          { icon: SettingsOutlined, text: 'Settings', href: '#settings' },
        ]}
      />
    </div>
  );
}
Result
Loading...

Important Props

Core Props

PropTypeRequiredDefaultDescription
links{ icon?: SvgIconComponent; text?: ReactNode; href: string; isActive?: boolean; unreadCount?: number }[]Yes-Navigation link items
header{ icon?: SvgIconComponent; text?: ReactNode; href: string }NoundefinedOptional header link above links
isFloatingbooleanNofalseWhen true, open menu uses a portal, backdrop, and close button
isMenuOpenbooleanNointernal falseWhether the menu panel is open
setIsMenuOpen(open: boolean) => voidNointernal setterPass with isMenuOpen for controlled usage

Content Props

Set links and header on the root. Subcomponents read them from context unless you override a block locally.

ComponentPropTypeRequiredDefaultDescription
LinkschildrenReactNodeNoRenders header + linksReplaces the default header and link list
LinksformatTextForUnreadCount(unreadCount: number) => number | stringNo99... when count > 99, else countBadge text for unreadCount
MenuButtonchildrenReactNodeNoMenu / MenuOpen iconToggle button content
MenuButtononClickReact.MouseEventHandlerNotoggles isMenuOpenCustom click handler
OverlayonClick() => voidNo() => setIsMenuOpen(false)Backdrop click (floating mode)
CloseButtonchildrenReactNodeNoClose iconClose control inside the floating panel
OpenMenucontainerPortalProps['container']Nodocument.bodyPortal target when isFloating

Links, MenuButton, Overlay, CloseButton, and OpenMenu are SideNavigation.Links, etc. Link icon values use MUI SvgIconComponent (e.g. HomeOutlined).

Layout and Composition Props

PropTypeRequiredDefaultDescription
childrenBlocksOverride | ReactNodeNoundefinedCompound subcomponents or function override returning blocks and blockOrder
classNamestringNoundefinedClass on root aside (nbb-side-navigation applied by default)
sxSxPropsNoundefinedMUI system styles for the root aside

SideNavigation inherits StackProps (except children). Root uses component="aside", maxWidth: 300, direction="column". Root-level render order is menuButton, then openMenu; defaultBlockOrder is menuButton, openMenu, overlay, closeButton, links.

Default UI Blocks

BlockBuilt onNotes
SideNavigation (root)Stack (component="aside")maxWidth: 300; renders menuButton + openMenu by default
SideNavigation.MenuButtonIconButton + SvgIconToggles menu; Menu icon by default, MenuOpen when inline and open
SideNavigation.OpenMenuBox + PortalFloating: portal with Overlay, panel, CloseButton, Links; inline: Links only
SideNavigation.OverlayBoxBackdrop inside floating openMenu when open
SideNavigation.CloseButtonIconButtonInside floating panel (Close icon); closes menu
SideNavigation.LinksStack (component="nav") + LinkDefault header/link list; text and unread counts show when open

TypeScript

import { SideNavigation } from '@nodeblocks/frontend-side-navigation-block';
import { DashboardOutlined, HomeOutlined } from '@mui/icons-material';
import type { SvgIconComponent } from '@mui/icons-material';
import type { ReactNode } from 'react';

type NavLink = {
icon?: SvgIconComponent;
text?: ReactNode;
href: string;
isActive?: boolean;
unreadCount?: number;
};

const links: NavLink[] = [
{ icon: DashboardOutlined, text: 'Dashboard', href: '/dashboard', isActive: true },
];

<SideNavigation
header={{ icon: HomeOutlined, text: 'Home', href: '/home' }}
links={links}
/>;