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 with the brand at the start and actions at the end. When space runs out, the items move into a FullscreenMenu opened by a menu button.
Use it as the primary navigation of a marketing site or documentation site.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Add the pieces it builds on: Fullscreen Menu, Navigation Menu,
use-mobile. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
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. The navbar measures itself with a ResizeObserver and folds the links into the fullscreen menu whenever they overflow the header, then returns to the full menu once there is room again.
With close label
Labels the fullscreen menu's close button Done with closeLabel.
Mega panel
Set layout="panel" so a mega item's columns open in a full-width panel anchored to the header instead of a dropdown beneath the trigger.
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.
API Reference
Navbar
The header that renders the brand, navigation items and actions.
| Prop | Type | Default |
|---|---|---|
items | NavbarItem[] | Required |
brand | React.ReactNode | - |
actions | React.ReactNode | - |
menuLabel | string | "Menu" |
closeLabel | string | - |
layout | "popover" | "panel" | "popover" |
| Prop | Type | Default |
|---|---|---|
render | React.ReactElement | A plain a |
| Prop | Type | Default |
|---|---|---|
render | (props: React.ComponentProps<"a">) => React.ReactNode | A plain a |
Also accepts the props of React.ComponentProps<"header">.
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.
The navbar switches to the compact layout below the 48rem breakpoint, and on wider screens whenever its contents overflow. There, plain links form the first group and each group or mega column becomes a labelled section. actions stay visible in the compact layout. menuLabel labels the menu button and titles the fullscreen menu, and closeLabel sets the text of its close button.
Replace render with your router's link component to route every link through it; it receives href and the link content.
Pass a render function that returns your router's link component; it receives the link props, including href and the link content.
The header sets data-slot="navbar", data-layout, and data-compact while the fullscreen menu is in use. Each part sets a data-slot, such as navbar-brand or navbar-column, for styling, and featured columns set data-featured. With layout="panel" the header gains relative positioning and z-50 so the panel can anchor to it.