SpaceMIX v0.1.0

UI kit - Navigation

experimentalfor bothsince protocol 1

The @spacemix/ui navigation components - Tabs, Breadcrumbs, Pagination, NavList, Stepper, Accordion, Disclosure, BackLink and AnchorNav - with their props and keyboard behaviour.

Ways around a view: tabs, breadcrumbs, pages, a sub-nav, the steps of a flow, sections that open and close, and an "On this page" list. Source: packages/ui/src/navigation.tsx. The inline Link is on the Actions page.

None of these write location.hash: the shell and the frames route on the hash, so in-page jumps (AnchorNav) scroll instead. To move between pages of your view, call host.view.navigate from onChange (see View).

Every component takes the native props of its root element, className joined last and ref. The conventions apply.

Stability: experimental, every export on this page: new in this release, and names and props may still be adjusted before they are promised.

Tabs, TabList, Tab, TabPanel

Tabs that switch between panels of one view. Tabs holds the selection for its TabList, Tabs and TabPanels. The keyboard follows the WAI-ARIA tabs pattern: the arrow keys move between tabs, Home and End go to the ends, and Tab from the tab list lands in the panel (each TabPanel takes focus).

<Tabs defaultValue="open">
  <TabList aria-label="Tasks">
    <Tab value="open" count={3}>Open</Tab>
    <Tab value="done">Done</Tab>
  </TabList>
  <TabPanel value="open">…</TabPanel>
  <TabPanel value="done">…</TabPanel>
</Tabs>
Tabs prop Type Default What it does
value string none The selected tab's value (controlled).
defaultValue string the first tab that isn't disabled The starting tab when uncontrolled.
onChange (value: string) => void none Called with the newly selected tab's value.
variant "line" | "pill" "line" An underline under the selected tab (a page's sections), or a segmented look (switching a view in place).
size Size "md" "sm" is denser, "lg" taller.
orientation "horizontal" | "vertical" "horizontal" "vertical" stacks the tabs in a column beside the panels once the tabs are 768 px wide or more (a row above them when narrower, as on phones).
activation "automatic" | "manual" "automatic" "automatic" selects a tab as the arrow keys reach it; "manual" only moves focus, and Enter or Space selects. Use manual when a panel is slow to show.

TabList is the row of tabs; it scrolls sideways when they don't fit. Give it an aria-label. Its className goes on its root (the row with the bottom border), so margins, padding and border overrides apply to the whole bar; ref and the other props go to the tablist element.

Tab prop Type Default What it does
value string required Which panel it shows; matches a TabPanel's value.
icon ReactNode none A lucide icon before the label, sized for you.
count number none A count after the label (unread, results); 100 and up shows "99+".
TabPanel prop Type Default What it does
value string required The Tab it belongs to.
keepMounted boolean false Keeps it in the page (hidden) while another tab is selected, so its state and scroll position survive.

TabsProps, TabProps and TabPanelProps are the props types.

interface BreadcrumbItem {
  label: ReactNode;
  href?: string;                                          // makes it a link
  onClick?: (e: React.MouseEvent<HTMLElement>) => void;   // makes it a button, or runs alongside href (preventDefault to stay put)
  icon?: ReactNode;                                       // a lucide icon, sized for you
}

Where the current page sits in a hierarchy, with links back up. The last item is the current page, shown as text. The middle folds into a "…" button (that expands it) on phones and past maxItems. Its landmark is named "Breadcrumb" unless you pass an aria-label.

Prop Type Default What it does
items BreadcrumbItem[] required The trail, from the root to the current page.
maxItems number 4 From md: up, the most items shown before the middle ones fold. Phones always show the first and the last only.
separator ReactNode a chevron Between items.

BreadcrumbsProps is the props type.

Pagination, paginationRange

Moves through a list that comes in pages: previous and next, and page numbers with an ellipsis for the gaps. Pages count from 1. Its landmark is named "Pagination" unless you pass an aria-label.

Prop Type Default What it does
count number required The number of pages.
value number none The current page (controlled).
defaultValue number 1 The starting page when uncontrolled.
onChange (page: number) => void none Called with the page to show.
variant "full" | "compact" "full" "full" shows page numbers from md: up (the compact form on phones); "compact" always shows "Page 3 of 12" between the arrows.
siblings number 1 Pages on each side of the current one.
boundaries number 1 Pages always shown at each end.
disabled boolean false Turns every button off, while a page loads.
function paginationRange(page: number, count: number, siblings = 1, boundaries = 1): Array<number | "ellipsis">;

paginationRange returns the page numbers a pagination control shows for page of count: the first and last boundaries pages, siblings on each side of the current one, and "ellipsis" for each gap. For building a control of your own.

PaginationProps is the props type.

A vertical nav: rows with icons, counts and an active state, in sections, with groups that fold. It is the sub-nav of an extension with several pages; put it in a SidebarLayout, whose phone menu closes after a pick. Up and Down move between rows.

interface NavListItem {
  kind?: "item";
  value: string;          // what onChange gets and value matches; unique in the list
  label: string;
  icon?: ReactNode;       // a lucide icon, sized for you
  badge?: ReactNode;      // a number shows as a count pill ("99+" from 100), anything else as it is
  hint?: string;          // quiet text on the right, such as a shortcut
  href?: string;          // makes the row a link (it still calls onChange)
  disabled?: boolean;
  items?: NavListItem[];  // nested rows; the row then opens and closes them instead of being picked
  defaultOpen?: boolean;  // for a group: open at first; default open when it holds the selected row
}

interface NavListSection {
  kind: "section";
  label?: string;         // the small heading; leave out for a group with only a gap above it
  items: NavListItem[];
}

type NavListEntry = NavListItem | NavListSection;
Prop Type Default What it does
items NavListEntry[] required Rows and sections of rows.
value string none The selected row's value (controlled).
defaultValue string none The starting row when uncontrolled.
onChange (value: string) => void none Called with the picked row's value.
<SidebarLayout title="Mail" sidebar={<NavList items={[{ value: "inbox", label: "Inbox", icon: <Inbox />, badge: 4 }, { kind: "section", label: "Labels", items: labels }]} value={route} onChange={(r) => host.view.navigate(r)} />}>
  …
</SidebarLayout>

NavListProps is the props type.

Stepper, StepperStep, StepStatus

type StepStatus = "complete" | "current" | "upcoming" | "error";

interface StepperStep {
  label: ReactNode;
  description?: ReactNode;  // shown on the desktop and in vertical steppers
  status?: StepStatus;      // overrides the status that follows from value
}

The steps of a multi-step flow (a setup, an import, a checkout) and which one the person is on: complete, current, upcoming or with an error. Renders an <ol>.

Prop Type Default What it does
steps StepperStep[] required The steps.
value number none The current step's index, from 0 (controlled). Steps before it are complete, after it upcoming.
defaultValue number 0 The starting step when uncontrolled.
onChange (index: number) => void none With it, complete and errored steps are buttons that call it with their index, to go back.
orientation "horizontal" | "vertical" "horizontal" Across the top of a flow (phones show only the current step's label), or down the side.

StepperProps is the props type.

Accordion, AccordionItem

A stack of sections that open and close under their headings (an FAQ, a settings group, a long form): one open at a time, or several. Up, Down, Home and End move between the headings; Enter and Space open and close.

Accordion prop Type Default What it does
multiple boolean false Lets several items be open at once; otherwise opening one closes the other.
value string[] none The open items' values (controlled); one at most unless multiple.
defaultValue string[] [] The starting open items.
onChange (value: string[]) => void none Called with the open items' values.
collapsible boolean true Without multiple: allows closing the open item so none is open.
variant "bordered" | "separated" | "plain" "bordered" One box with rules between items, each item its own box, or rules only (for inside a panel).
AccordionItem prop Type Default What it does
value string required Identifies it in the Accordion's value.
title ReactNode required The heading that opens and closes it.
description ReactNode none A line under the title.
icon ReactNode none A lucide icon before the title, sized for you.
meta ReactNode none On the right of the heading, before the chevron: a count, a status.
disabled boolean false It can't be opened.
level 2 | 3 | 4 | 5 | 6 3 The heading's level in the page outline.

The open content fades and slides in (transform and opacity only) and appears at once under reduced motion. AccordionProps and AccordionItemProps are the props types.

Disclosure

One button that shows and hides the content below it: advanced options, the details of an error, "show more".

Prop Type Default What it does
title ReactNode required The button's text: what is hidden ("Advanced options", "Show 3 more").
open boolean none Whether it is open (controlled).
defaultOpen boolean false The starting state when uncontrolled.
onOpenChange (open: boolean) => void none Called when it opens or closes.
variant "plain" | "bordered" "plain" A quiet text button with a chevron (inside a form or list), or a box like an accordion item on its own.
icon ReactNode none A lucide icon before the title, "bordered" only.
disabled boolean false It can't be opened.

DisclosureProps is the props type.

A quiet "← Back" link to the page above, at the top of a detail page. With href it is a link; without one, a button that runs onClick. Its children are the label, default "Back"; name the place ("All invoices") when it isn't obvious. Takes the <a> props. BackLinkProps is the props type.

AnchorNav, AnchorNavItem

interface AnchorNavItem { id: string; label: ReactNode; level?: 1 | 2 | 3 }  // id: the element it jumps to; level indents sub-headings, default 1

"On this page": links to the sections of a long page that scroll to them (without touching the address) and mark the one being read.

Prop Type Default What it does
items AnchorNavItem[] required The headings.
title ReactNode "On this page" The heading above the list; null for none.
value string none The id of the section shown as current (controlled). Left out, it follows the scroll position.
onChange (id: string) => void none Called with a section's id when it becomes current, by scrolling or a click.
root HTMLElement | null the nearest scrolling parent of the first heading The element that scrolls (a Page body, a ScrollArea).
offset number 16 Space kept above a heading when jumping to it and when deciding which is current, in px (for a sticky header).

AnchorNavProps is the props type.

This page as markdown · All pages as one file