Skip to content

Nav

A set of links that marks the current page.

import { Nav, type NavItem } from '@/design-system';

Examples

Variants

'use client';

import { useState } from 'react';
import { Nav } from '@/design-system';

const ITEMS = [
  { href: '#overview', label: 'Overview' },
  { href: '#customers', label: 'Customers' },
  { href: '#settings', label: 'Settings' },
];

export default function NavVariants() {
  const [current, setCurrent] = useState('#overview');

  return (
    // The click handler stands in for a router, so the example stays put.
    <div
      className="space-y-6"
      onClick={event => {
        const link = (event.target as Element).closest('a');
        if (!link) return;
        event.preventDefault();
        setCurrent(link.getAttribute('href')!);
      }}
    >
      {(['plain', 'underline', 'pill'] as const).map(variant => (
        <Nav
          key={variant}
          label={`${variant} example`}
          variant={variant}
          current={current}
          items={ITEMS}
        />
      ))}
    </div>
  );
}

With a router

Pass the router’s link and the current path. This one is a vertical sidebar with icons.

'use client';

import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { Nav } from '@/design-system';

export default function NavRouter() {
  return (
    <Nav
      label="Documentation example"
      variant="pill"
      vertical
      linkAs={Link}
      current={usePathname()}
      items={[
        { href: '/design-system/', label: 'Introduction', icon: '◆' },
        { href: '/design-system/nav/', label: 'Nav', icon: '◇' },
      ]}
    />
  );
}

How it works

  • The current link gets aria-current="page", and the styles follow that attribute.
  • The match is exact, so a parent link is not marked on its child pages.
  • Nav has no tie to Next.js. A server component cannot pass linkAs to a client component, but Nav itself runs in either.

Props

Nav

Nav takes only these props.

Nav props
PropTypeDefaultDescription
labelstringrequiredNames the navigation for screen readers.
itemsNavItem[]requiredThe links, in order.
currentstring—The current path. The matching link is marked; a trailing slash is ignored.
variant'plain' | 'underline' | 'pill''plain'The look of the links.
verticalbooleanfalseStacks the links from 48rem wide. Below that they stay in a row.
linkAsElementType'a'A link component that accepts href, className, aria-current and children.
classNamestring—Extra classes, for spacing or width. Utility classes override the component’s own styles.

NavItem

NavItem props
PropTypeDefaultDescription
hrefstringrequiredWhere the link goes. Each must be different.
labelstringrequiredThe link text.
iconReactNode—Shown before the label. Hide decorative icons from screen readers.

Tokens

Tokens
TokenDefaultSets
--nav-gap1.5rem, or 0.25rem for pillsSpace between links
--nav-radius--radius-controlPill corner radius
--nav-font-sizeinherited, or 0.875rem for pillsText size