Playground

Navbar

A top bar with brand, links and an actions slot; links move into a drawer on small screens.

  • Built on native elements
  • A header (banner landmark) with the links in their own navigation landmark named by linksLabel; the current page has aria-current="page".
  • Below 800px a Menu button opens the links in a drawer: focus is trapped, Escape closes it and focus returns to the button.
  • Put it first in the page, before main, so a skip link can jump past it.
  • Styles in one file: 02-buttons.css

Import

import '@monoline/css';
import {Navbar} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add navbar

Usage

import {Button, Navbar} from '@monoline/react';

const links = [{label: 'Product', href: '#product', current: true}, {label: 'Pricing', href: '#pricing'}, {label: 'Docs', href: '#docs'}];

<Navbar brand="Acme" links={links} actions={<Button variant="solid" size="sm">Sign in</Button>} />

Examples

Narrow the window: the links move into a drawer behind the Menu button.

With a client router

renderLink receives each link's props: return your router's link. The demo uses a plain anchor to show the shape.

Props

NavbarProps

PropTypeDefaultDescription
brandReactNode–Your logo or name, at the start of the bar.
linksNavbarLink[][]Primary links, shown in the bar from 800px and in a drawer opened by a menu button below that. Leave out when the bar only holds actions.
linksLabelstring'Main'Names the links' navigation landmark. Default "Main".
renderLinkRenderLink–Renders each link, so a client router can handle the click. Default a plain `<a href>`.
leadingReactNode–Goes before the brand: put a `SidebarTrigger` here when the bar sits above a `Sidebar`.
actionsReactNode–The end of the bar: search, a command palette button, an account menu.
menuLabelstring'Menu'Text of the button that opens the links drawer on small screens. Default "Menu".
stickybooleanfalseKeeps the bar at the top while the page scrolls. Default false. `AppShell` already does this for its navbar.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-side="bottom"]drawer.css
[data-side="end"]drawer.css
[data-side="left"]drawer.css
[data-side="right"]drawer.css
[data-side="start"]drawer.css
[data-side="top"]drawer.css
[aria-current="page"]navbar.css
[data-sticky]navbar.css

CSS classes

ClassStylesheet
.btn02-buttons.css
.btn-block02-buttons.css
.btn-danger02-buttons.css
.btn-ghost02-buttons.css
.btn-lg02-buttons.css
.btn-line02-buttons.css
.btn-sm02-buttons.css
.btn-solid02-buttons.css
.commanddialog.css
.dialog-closedialog.css
.dialog-contentdialog.css
.dialog-descriptiondialog.css
.dialog-footerdialog.css
.dialog-headerdialog.css
.dialog-overlaydialog.css
.dialog-titledialog.css
.drawer-contentdialog.css
.drawer-contentdrawer.css
.navbarnavbar.css
.navbar-actionsnavbar.css
.navbar-brandnavbar.css
.navbar-drawernavbar.css
.navbar-linknavbar.css
.navbar-linksnavbar.css
.navbar-listnavbar.css
.navbar-menunavbar.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.btn {
  border-color: var(--accent);
}
.btn[data-side="bottom"] {
  background: var(--wash);
}

Accessibility

  • A header (banner landmark) with the links in their own navigation landmark named by linksLabel; the current page has aria-current="page".
  • Below 800px a Menu button opens the links in a drawer: focus is trapped, Escape closes it and focus returns to the button.
  • Put it first in the page, before main, so a skip link can jump past it.

Keyboard

KeysAction
EscapeCloses it and focus returns to the button