A row of links between the pages of one section.
- 1.2 kB JS 2.6 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Installs in a fresh app
- Right-to-left
- 2 tests
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { RouteNav } from "./ui/uicontext/components/RouteNav.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ bar: { inlineSize: "min(100%, 40rem)", paddingBlockEnd: 8, borderBlockEndWidth: 1, borderBlockEndStyle: "solid", borderBlockEndColor: color.line },})// real links: the app's router follows them, and the current page is marked for screen readersexport const WorkspaceSettingsNav = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.bar)).children( RouteNav(h, { label: "Workspace settings", current: "members", items: [ { id: "general", label: "General", href: "#general" }, { id: "members", label: "Members", href: "#members" }, { id: "billing", label: "Billing", href: "#billing" }, { id: "connections", label: "Connections", href: "#connections" }, { id: "security", label: "Security", href: "#security" }, { id: "audit", label: "Audit log", href: "#audit" }, ], }), )When to use
A row of links between the pages of one section. Use Tabs instead when the panels change without a new address.
Usage
import { RouteNav } from "./ui/uicontext/components/RouteNav.ts"export const SettingsNav = <M>(h: Html.H<M>, current: string) => RouteNav(h, { label: "Settings", current, items: [ { id: "general", label: "General", href: "/settings" }, { id: "members", label: "Members", href: "/settings/members" }, { id: "billing", label: "Billing", href: "/settings/billing" }, ], })Examples
Narrower than its links
The row scrolls sideways instead of wrapping, and the current page scrolls into view.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { RouteNav } from "./ui/uicontext/components/RouteNav.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 18rem)" } })export const ProjectNav = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( RouteNav(h, { label: "Project", current: "updates", items: [ { id: "overview", label: "Overview", href: "#overview", glyph: "◎" }, { id: "issues", label: "Issues", href: "#issues", glyph: "◇" }, { id: "cycles", label: "Cycles", href: "#cycles", glyph: "↻" }, { id: "docs", label: "Documents", href: "#docs", glyph: "▤" }, { id: "updates", label: "Updates", href: "#updates", glyph: "✎" }, ], }), )API reference
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | The landmark's accessible name: "Settings". |
itemsrequired | RouteNavItem[] | The links, each with an id, a label, an href and an optional glyph. |
current | string | The id of the link to the page shown now, marked as the current page. |
style | Style | StyleX styles for the row. |
linkStyle | Style | Applied to every anchor after its default styles. |
currentStyle | Style | Applied last to the current anchor. |
glyphStyle | Style | StyleX styles for each link's glyph. |
Keyboard and accessibility
- A
navlandmark named by itslabel, holding real links; the current page isaria-current="page".
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/route-tabs