suiss/ui · Pattern
Navbar
A site header that renders a navigation menu on wide screens and a fullscreen menu when space runs out.
Navbar is an open-source pattern from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Navbar builds a header from an items array. On wide screens it renders a NavigationMenu: plain links appear inline, groups open a dropdown of links with optional icons and descriptions, and mega items open multi-column panels. The brand sits at the start and actions at the end.
The navbar switches to a compact layout below the 48rem breakpoint, and also on wider screens whenever its contents overflow the header; it measures itself with a ResizeObserver and returns to the full menu once there is room again. In the compact layout the items move into a FullscreenMenu opened by a menu button, with plain links in the first group and each group or mega column as a labelled section. Use it as the primary navigation of a marketing site or documentation site.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
-
Add the
cnhelper. -
Add the pieces it builds on: Fullscreen Menu, Navigation Menu,
use-mobile. -
Copy the source into
components/patterns/navbar.tsx:
- Update the import paths to match your project.
Usage
Each NavbarItem is one of three shapes: a link with label and href (plus optional description, icon and active), a group with label and items, or a mega item with label and columns. Each column has a label, links and an optional featured flag that sets its links in a large type size. Pass render to route links through your framework's link component; it receives href and the link content.
Examples
With actions
Adds a Sign in button at the end of the header with actions.
Links only
Uses only plain links and marks the current page with active.
Crowded
Shows nine links in a narrow frame, folding them into the menu until the frame is wide enough.
With close label
Labels the fullscreen menu's close button Done with closeLabel.
Mega panel
Uses layout="panel" with a mega item whose columns open in a full-width panel.
API Reference
Navbar
The header that renders the brand, navigation items and actions.
| Prop | Type | Default | Description |
|---|---|---|---|
items | NavbarItem[] | Required | The navigation items: links, groups of links, or mega items with columns. |
brand | React.ReactNode | - | Content shown at the start of the header, such as a logo. |
actions | React.ReactNode | - | Content shown at the end of the header, such as a sign-in button; it stays visible in the compact layout. |
menuLabel | string | "Menu" | Accessible label of the compact menu button and title of the fullscreen menu. |
closeLabel | string | - | Text for the fullscreen menu's close button. |
layout | "popover" | "panel" | "popover" | With popover, dropdowns float beneath their trigger; with panel, they open as a full-width panel anchored to the header. |
render | React.ReactElement | <NavbarAnchor /> | The element used for every link, defaulting to a plain anchor; replace it with your router's link component. |
Also accepts the props of React.ComponentProps<"header">.
Accessibility
- Group and mega triggers are buttons with
aria-expandedreflecting their state, andEscapecloses an open dropdown. - Links marked
activehavearia-current="page". - In the compact layout, the menu button is labelled by
menuLabel.
Notes
The header carries data-slot="navbar", data-layout, and data-compact while the fullscreen menu is in use. The brand and actions wrappers use data-slot="navbar-brand" and data-slot="navbar-actions", and mega columns use data-slot="navbar-column" with data-featured. With layout="panel" the header gains relative positioning and z-50 so the panel can anchor to it.