suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Patterns19
  • Overview
  • Action Bar
  • Action Menu
  • App Shell
  • Command Palette
  • Confirm
  • Context Actions
  • Date Picker
  • Flyout
  • Modal
  • Navbar
  • Paged List
  • Panel
  • Picker
  • Preview
  • Search Picker
  • Segment Picker
  • Split View
  • Table List
  • Trail

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.

import {
  BookOpenIcon,
  ChartLineIcon,
  CodeIcon,
  LifebuoyIcon,
  LightningIcon,
  ShieldCheckIcon,
} from "@phosphor-icons/react"
import { Navbar, type NavbarItem } from "@/components/patterns/navbar"

const items: NavbarItem[] = [
  {
    label: "Products",
    items: [
      {
        label: "Analytics",

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

$ pnpm dlx shadcn@latest add @esuiss/navbar

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add patterns navbar
  1. Add the cn helper.

  2. Add the pieces it builds on: Fullscreen Menu, Navigation Menu, use-mobile.

  3. Copy and paste the following code into your project.

components/patterns/navbar.tsx
"use client"

import * as React from "react"
import {
  FullscreenMenu,
  FullscreenMenuContent,
  FullscreenMenuGroup,
  FullscreenMenuLabel,
  FullscreenMenuLink,
  FullscreenMenuTitle,
  FullscreenMenuTrigger,
} from "@/components/ui/fullscreen-menu"
import {
  NavigationMenu,
  NavigationMenuContent,
  NavigationMenuItem,
  1. Update the import paths to match your project setup.

Usage

import { Navbar } from "@/components/patterns/navbar"
<div className="min-h-96">
  <Navbar items={items} brand={brand} />
</div>

Examples

With actions

Adds a Sign in button at the end of the header with actions.

import {
  BookOpenIcon,
  ChartLineIcon,
  CodeIcon,
  LifebuoyIcon,
  LightningIcon,
  ShieldCheckIcon,
} from "@phosphor-icons/react"
import { Navbar, type NavbarItem } from "@/components/patterns/navbar"
import { Button } from "@/components/ui/button"

const items: NavbarItem[] = [
  {
    label: "Products",
    items: [
      {

Links only

Uses only plain links and marks the current page with active.

import { Navbar } from "@/components/patterns/navbar"

export default function NavbarLinksOnly() {
  return (
    <div className="min-h-96">
      <Navbar
        items={[
          { label: "Overview", href: "#overview", active: true },
          { label: "Customers", href: "#customers" },
          { label: "Changelog", href: "#changelog" },
          { label: "Blog", href: "#blog" },
        ]}
        brand={<span className="text-base font-semibold">Acme</span>}
      />
    </div>
  )

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.

import { Navbar } from "@/components/patterns/navbar"
import { Button } from "@/components/ui/button"

export default function NavbarCrowded() {
  return (
    <div className="min-h-96">
      <div data-testid="frame" className="w-160 max-w-full">
        <Navbar
          items={[
            "Store",
            "Laptop",
            "Tablet",
            "Phone",
            "Watch",
            "Headphones",
            "Speakers",

With close label

Labels the fullscreen menu's close button Done with closeLabel.

import {
  BookOpenIcon,
  ChartLineIcon,
  CodeIcon,
  LifebuoyIcon,
  LightningIcon,
  ShieldCheckIcon,
} from "@phosphor-icons/react"
import { Navbar, type NavbarItem } from "@/components/patterns/navbar"

const items: NavbarItem[] = [
  {
    label: "Products",
    items: [
      {
        label: "Analytics",

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.

import { Navbar } from "@/components/patterns/navbar"

export default function NavbarMegaPanel() {
  return (
    <div className="min-h-96">
      <Navbar
        items={[
          {
            label: "Products",
            columns: [
              {
                label: "Explore",
                featured: true,
                links: [
                  { label: "Analytics", href: "#analytics" },
                  { label: "Automations", href: "#automations" },

Accessibility

  • Group and mega triggers are buttons with aria-expanded reflecting their state, and Escape closes an open dropdown.
  • Links marked active have aria-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.

PropTypeDefault
itemsNavbarItem[]Required
brandReact.ReactNode-
actionsReact.ReactNode-
menuLabelstring"Menu"
closeLabelstring-
layout"popover" | "panel""popover"
PropTypeDefault
renderReact.ReactElementA plain a
PropTypeDefault
render(props: React.ComponentProps<"a">) => React.ReactNodeA 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.

NextPaged ListPreviousModal

On this page

  1. 01Installation
  2. 02Usage
  3. 03Examples
    • With actions
    • Links only
    • Crowded
    • With close label
    • Mega panel
  4. 04Accessibility
  5. 05API Reference
    • Navbar