Inspector
The settings panel beside a canvas: a rail of icons, each opening a page of titled sections.
Demo
Usage
import { GridIcon, Inspector, Input, PencilIcon, Segmented, SettingsIcon, Switch } from '@tuttn/slant'
const pages = [
{ value: 'node', label: 'Node', icon: <SettingsIcon />, content: <>
<Inspector.Section title="Identity">
<Inspector.Row title="Name" htmlFor="node-name"><Input id="node-name" defaultValue="Parse" /></Inspector.Row>
<Inspector.Row title="Kind"><Segmented size="sm" options={kinds} defaultValue="step" label="Kind" /></Inspector.Row>
</Inspector.Section>
<Inspector.Section title="Run" actions={<Switch size="sm" defaultChecked aria-label="Run this step" />}>
<Inspector.Row title="Timeout" htmlFor="node-timeout" hint="Seconds before the step fails.">
<Input id="node-timeout" type="number" mono defaultValue={30} />
</Inspector.Row>
</Inspector.Section>
<Inspector.Section title="Advanced" collapsible defaultOpen={false}>…</Inspector.Section>
</> },
{ value: 'style', label: 'Style', icon: <PencilIcon />, content: <StyleSections /> },
{ value: 'layout', label: 'Layout', icon: <GridIcon />, content: <LayoutSections />, title: 'Layout and size' },
] as const
// Uncontrolled: starts at defaultValue (the first enabled page when omitted).
<Inspector pages={pages} defaultValue="node" label="Node settings" />
// Controlled: you hold the open page.
<Inspector pages={pages} value={page} onValueChange={setPage} label="Node settings" />
// Give it the canvas's height and a long page scrolls inside it; plain drops
// the frame to fill a region of your own.
<Inspector pages={pages} variant="plain" style={{ blockSize: 480 }} />
// A section open or closed under your control.
<Inspector.Section title="Advanced" collapsible open={open} onOpenChange={setOpen}>…</Inspector.Section>Props
| Prop | Type | Default | Description |
|---|---|---|---|
pages | readonly InspectorPage<T>[] | — | The pages, in rail order. `T` is inferred from their values. |
value | T | — | The open page, when controlled. A value that names no page opens the first enabled one. |
defaultValue | T | the first enabled page | The page open first, when uncontrolled. |
onValueChange | (value: T) => void | — | Called with the page's value when the user opens another page. |
label | string | messages.inspector ("Inspector") | The rail's accessible name. |
headingLevel | 2 | 3 | 4 | 5 | 3 | The page title's heading level; section titles sit one level deeper. |
variant | 'framed' | 'plain' | 'framed' | `framed` draws a hairline border and radius around a surface; `plain` has neither, to fill a region such as a Workbench side. |
Inspector.Section title | ReactNode | — | The section's title: a heading one level under the page title (4 outside an Inspector), and the toggle's text when collapsible. |
Inspector.Section actions | ReactNode | — | Controls at the end of the title row, such as a Switch that turns the section on or a Reset button. |
Inspector.Section collapsible | boolean | — | Puts a button with aria-expanded in the heading; the body is hidden while closed. |
Inspector.Section open | boolean | — | Whether a collapsible section is open, when controlled. |
Inspector.Section defaultOpen | boolean | true | Whether a collapsible section starts open, when uncontrolled. |
Inspector.Section onOpenChange | (open: boolean) => void | — | Called with the requested state when the title button is pressed. |
Inspector.Row title | ReactNode | — | The setting's visible name, in the first column. |
Inspector.Row htmlFor | string | — | The id of the control the title names: the title becomes a <label for>, which also names the control for screen readers. |
Inspector.Row hint | ReactNode | — | A short note under the control, in muted small text. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style, other attributes and the ref go on each part's own element: the root (Tabs' root div), the section's group div and the row's div. |
A page is { value, label, icon, content, title?, disabled? }; the values type value and onValueChange. The rail is vertical Tabs underneath, so it keeps their keyboard: the rail is one stop in the tab order, Up and Down move along it and open each page as they go, Home and End jump to the first and last, and disabled pages are skipped. Tab goes on into the open page. A click on an icon opens its page.
A screen reader hears the rail as a tab list named by label ("Inspector" by default), each icon as a tab named by its page's label, and the page as a tab panel with that name. The page title is a heading at headingLevel (3 by default) and each section title one level deeper, so the inspector sits in the page's outline; each section is a group named by its title. A collapsible section's title is a button that says whether it is expanded; Enter, Space or a click opens and closes it.
Every page stays mounted, so an edited field keeps its value across a page switch. Give the inspector the height of the canvas beside it and a long page scrolls inside it, under its title. Put a page's content in Inspector.Sections: they carry the padding and the hairlines between them. In a row, a control keeps its own width in the second column and an Input fills it; a Slider, which brings its own label and readout, sits in a section on its own line.
The selected icon sits on the selection pill while a bar slides down the rail's edge to it; the page rises in, and so does a section when it is opened. With reduced motion the bar, the page and the section appear in place.