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
linkAsto a client component, but Nav itself runs in either.
Props
Nav
Nav takes only these props.
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | required | Names the navigation for screen readers. |
items | NavItem[] | required | The links, in order. |
current | string | — | The current path. The matching link is marked; a trailing slash is ignored. |
variant | 'plain' | 'underline' | 'pill' | 'plain' | The look of the links. |
vertical | boolean | false | Stacks the links from 48rem wide. Below that they stay in a row. |
linkAs | ElementType | 'a' | A link component that accepts href, className, aria-current and children. |
className | string | — | Extra classes, for spacing or width. Utility classes override the component’s own styles. |
NavItem
| Prop | Type | Default | Description |
|---|---|---|---|
href | string | required | Where the link goes. Each must be different. |
label | string | required | The link text. |
icon | ReactNode | — | Shown before the label. Hide decorative icons from screen readers. |
Tokens
| Token | Default | Sets |
|---|---|---|
--nav-gap | 1.5rem, or 0.25rem for pills | Space between links |
--nav-radius | --radius-control | Pill corner radius |
--nav-font-size | inherited, or 0.875rem for pills | Text size |