Navbar
A top bar with brand, links and an actions slot; links move into a drawer on small screens.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsbeta
- 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
Brand, links and actions
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
| Prop | Type | Default | Description |
|---|---|---|---|
brand | ReactNode | – | Your logo or name, at the start of the bar. |
links | NavbarLink[] | [] | 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. |
linksLabel | string | 'Main' | Names the links' navigation landmark. Default "Main". |
renderLink | RenderLink | – | Renders each link, so a client router can handle the click. Default a plain `<a href>`. |
leading | ReactNode | – | Goes before the brand: put a `SidebarTrigger` here when the bar sits above a `Sidebar`. |
actions | ReactNode | – | The end of the bar: search, a command palette button, an account menu. |
menuLabel | string | 'Menu' | Text of the button that opens the links drawer on small screens. Default "Menu". |
sticky | boolean | false | Keeps 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.
| Attribute | Stylesheet |
|---|---|
[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
| Class | Stylesheet |
|---|---|
.btn | 02-buttons.css |
.btn-block | 02-buttons.css |
.btn-danger | 02-buttons.css |
.btn-ghost | 02-buttons.css |
.btn-lg | 02-buttons.css |
.btn-line | 02-buttons.css |
.btn-sm | 02-buttons.css |
.btn-solid | 02-buttons.css |
.command | dialog.css |
.dialog-close | dialog.css |
.dialog-content | dialog.css |
.dialog-description | dialog.css |
.dialog-footer | dialog.css |
.dialog-header | dialog.css |
.dialog-overlay | dialog.css |
.dialog-title | dialog.css |
.drawer-content | dialog.css |
.drawer-content | drawer.css |
.navbar | navbar.css |
.navbar-actions | navbar.css |
.navbar-brand | navbar.css |
.navbar-drawer | navbar.css |
.navbar-link | navbar.css |
.navbar-links | navbar.css |
.navbar-list | navbar.css |
.navbar-menu | navbar.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
| Keys | Action |
|---|---|
| Escape | Closes it and focus returns to the button |