Skip to content
Get started

Components

SiteNavbar

Unstable: a website's main navigation, the brand, the links and the actions, as a full-width bar or a floating glass pill; below 768 px the links fold into a menu. Import it from @nizivo/react/unstable/site-navbar.

Server component, no client JSUnstable

Examples

Basic

Two styles: the full-width bar, and the floating pill for over a hero.

import type { JSX } from 'react';
import { Button } from '@nizivo/react/button';
import { Link } from '@nizivo/react/unstable/link';
import { SiteNavbar } from '@nizivo/react/unstable/site-navbar';

const LINKS = [
  { label: 'Product', href: '/product/' },
  { label: 'Components', href: '/docs/components/', current: true },
  { label: 'Docs', href: '/docs/' },
  { label: 'Pricing', href: '/pricing/' },
];

export function SiteNavbarExample(): JSX.Element {
  return (
    <div style={{ display: 'grid', gap: 24, inlineSize: 960 }}>
      <SiteNavbar
        brand={<Link href="/">Nizivo</Link>}
        links={LINKS}
        actions={
          <>
            <Button variant="tertiary">Sign in</Button>
            <Button variant="primary">Get started</Button>
          </>
        }
      />
      <SiteNavbar
        variant="floating"
        brand={<Link href="/">Nizivo</Link>}
        links={LINKS}
        actions={<Button variant="primary">Get started</Button>}
      />
    </div>
  );
}

Import

import { SiteNavbar } from '@nizivo/react/unstable/site-navbar';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/site-navbar.css';

Static or interactive

Server. No client JavaScript: the narrow menu is a native <details> disclosure. How to choose.

Use

It is a <header> holding a <nav> named "Main". links (a label, an href, and current for the page you are on, which gets aria-current="page") sit between brand and actions. variant is bar, full width with a rule under it, or floating, a glass pill for over a hero. Below 768 px the links move into a menu button named "Menu" whose panel opens under the bar.

Props

Server component Renders data-slot="site-navbar" with the class nz-site-navbar. Props: SiteNavbarProps. Source: src/unstable/site-navbar/site-navbar.tsx.

NameTypeDefaultDescription
actionsReactNode–

At the end: Sign in, Get started.

brandReactNode–

The logo, as a link home.

labelsPartial<SiteNavbarLabels>–
linksrequiredreadonly SiteNavbarLink[]–
renderRenderProp<Record<string, never>>–

Must render a <header>.

variant"bar" | "floating"'bar'

The look: a full-width bar or a floating one.

  • Also takes every attribute of <header> except children. (Omit<ComponentPropsWithRef<"header">, "children">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

SiteNavbarLabels type

import type { SiteNavbarLabels } from '@nizivo/react/unstable/site-navbar'

SiteNavbar's own strings (§16.4): serialisable, English defaults.

NameTypeDefaultDescription
labelrequiredstring'Main'

The nav's name.

menurequiredstring'Menu'

The menu button's name, below 768 px.

SiteNavbarLink type

import type { SiteNavbarLink } from '@nizivo/react/unstable/site-navbar'

One link.

NameTypeDefaultDescription
currentboolean–

The page this link goes to is the current one.

hrefrequiredstring–
labelrequiredReactNode–
SiteNavbarProps type

import type { SiteNavbarProps } from '@nizivo/react/unstable/site-navbar'

The props of SiteNavbar, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
site-navbar
.nz-site-navbar
SiteNavbar
root (takes render)
  • data-variant: "bar""floating" ← variant
    The variant prop; values in each component manifest
site-navbar-link
.nz-site-navbar-link
SiteNavbar
inner element (CSS only); interactive, focus: self
none
site-navbar-menu
.nz-site-navbar-menu
SiteNavbar
inner element (CSS only); interactive, focus: self
none

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

This stylesheet reads no public hook.

Layers: nz.components. Classes: .nz-site-navbar, .nz-site-navbar-actions, .nz-site-navbar-brand, .nz-site-navbar-link, .nz-site-navbar-links, .nz-site-navbar-menu, .nz-site-navbar-narrow, .nz-site-navbar-panel, .nz-site-navbar-wide.

Tokens this stylesheet reads (19)

--nz-bg-surface, --nz-border-subtle, --nz-border-width-default, --nz-elevation-2, --nz-font-label-m, --nz-radius-full, --nz-radius-md, --nz-radius-xs, --nz-size-icon-md, --nz-space-1, --nz-space-10, --nz-space-2, --nz-space-3, --nz-space-4, --nz-space-5, --nz-space-6, --nz-space-8, --nz-text-primary, --nz-text-secondary

Accessibility

These parts are interactive. Each gets the focus outline and touch-action rule from @nizivo/react/css/base.css (the nz.base layer), so the floor survives a restyle:

  • site-navbar-link: draws the focus outline itself on keyboard focus.
  • site-navbar-menu: draws the focus outline itself on keyboard focus.

Keyboard

To be written.

On this page