SpaceMIX v0.1.0

UI kit - Layout

experimentalfor bothsince protocol 1

The @spacemix/ui layout components - page shell, sections, containers, stacks, grids, toolbars, dividers, scroll areas, split panes, list-detail, sidebar layout, side panels and surfaces - with their props.

The boxes a view is built from: the page shell, sections, stacks and grids, toolbars, scroll areas, split panes and the responsive master-detail and sidebar layouts. Source: packages/ui/src/layout.tsx. PageHeader is on the kit's main page.

Everything here works at phone width (below md:, 768 px) as well as on the desktop: panes stack, sidebars fold behind a toggle, and nothing has a fixed width that could overflow. SplitView, ListDetail and SidebarLayout are container queries (@container, switching at 768 px of their own width), so one in a narrow pane shows its phone form on a wide screen too.

Every component takes the native props of its root element (ComponentProps<"div"> unless a section says otherwise), 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.

Gap

type Gap = 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12;

The spacing steps the layout components take for gap, on the Tailwind scale (1 = 4 px): gap={3} is gap-3, 12 px.

Page

The shell of an extension page: a header and toolbar that stay put, a body that scrolls on its own, and an optional footer pinned to the bottom. It fills its parent (h-full), so it is the root of a view.

Prop Type Default What it does
header ReactNode none Above everything, not scrolling: usually a PageHeader.
toolbar ReactNode none Under the header, not scrolling: a Toolbar, Tabs or filters. Gets the page's side padding and a bottom border.
footer ReactNode none Pinned to the bottom, not scrolling: a form's actions or a status line. Stays on screen on phones (it clears the home indicator).
size ContainerProps["size"] "full" The content's widest width, as Container's size.
padded boolean true Pads the body with the page's side and bottom padding. Turn off for a body that is a SplitView or ListDetail edge to edge.
bodyRef Ref<HTMLDivElement> none The scrolling body element, to restore or reset its scroll position.
<Page header={<PageHeader title="Invoices" />} toolbar={<Toolbar end={<Button variant="primary">New</Button>}><SearchField /></Toolbar>}>
  <Table columns={columns} rows={invoices} />
</Page>

PageProps is the props type.

Section

A titled block of a page, the way Settings groups its options: heading, a one-line description, actions on the right, then the content. Renders a <section>.

Prop Type Default What it does
title ReactNode none The section's heading.
description ReactNode none One line under the heading on what the section is for.
actions ReactNode none Buttons on the heading's right; they wrap under it on a narrow screen.
level 2 | 3 | 4 2 The heading level, so sections nest in the page's outline.
divided boolean false A rule and space above, to separate it from the section before.

SectionProps is the props type.

Container

Keeps a page's content at a readable width with the app's side padding.

Prop Type Default What it does
size "sm" | "md" | "lg" | "xl" | "full" "lg" The widest the content gets: sm 576 px (a form), md 672 px (reading), lg 896 px (settings, most pages), xl 1152 px (tables, dashboards), full no limit.
padded boolean true The page's side padding (16 px on phones, 40 px from md: up), the same as PageHeader.
center boolean true Centres it in the space it has; false keeps it on the left like the app's own pages.

ContainerProps is the props type.

Stack, HStack, VStack

Stack lays its children out in a row or a column with even gaps: the building block of every arrangement that isn't a grid. HStack is a row with its children centred vertically (icon and label rows, button groups, a header's actions), default gap 2. VStack is a column (a form, the blocks of a section), default gap 3. Both take Stack's props without direction.

Prop Type Default What it does
direction "row" | "column" | "responsive" "column" "responsive" is a column on phones and a row from md: up.
gap Gap 3 (12 px) Space between children.
align "start" | "center" | "end" | "stretch" | "baseline" "stretch" for columns, "center" for rows Cross-axis alignment (align-items).
justify "start" | "center" | "end" | "between" | "around" | "evenly" "start" Main-axis distribution (justify-content).
wrap boolean false Lets children wrap onto more lines.
inline boolean false inline-flex instead of flex.
as "div" | "section" | "article" | "aside" | "header" | "footer" | "main" | "nav" | "ul" | "ol" | "li" | "form" | "fieldset" | "span" "div" The element to render, so a stack can be a list or a landmark.

StackProps is the props type.

Grid

A responsive grid of cards, tiles or fields: a fixed column count that drops to phoneColumns on phones, or as many columns of at least minColumnWidth as fit.

Prop Type Default What it does
columns 1 | 2 | 3 | 4 | 5 | 6 | 12 2 Columns from md: up.
phoneColumns 1 | 2 | 3 | 4 1 Columns below md:, with columns.
minColumnWidth number | string none Fits as many columns as there is room for, each at least this wide (px or any CSS length); overrides columns. Never wider than the grid, so a phone gets one column.
gap Gap 4 (16 px) Space between cells.
align "start" | "center" | "end" | "stretch" "stretch" Vertical alignment of cells in a row; "stretch" makes a row's cells the same height.
as as Stack "div" The element to render.

GridProps is the props type.

Toolbar

A strip of controls over a list or editor: filters and search on the left (the children), actions on the right (end), wrapping or scrolling when space runs out. It is a layout, not an ARIA toolbar; pass role="toolbar" and an aria-label when its controls are only buttons.

Prop Type Default What it does
end ReactNode none The group on the right.
overflow "wrap" | "scroll" "wrap" Wraps onto another line, or scrolls sideways in one line, when the controls don't fit.
bordered boolean false A bottom border, for a toolbar on its own (a Page's toolbar slot draws one already).

ToolbarProps is the props type.

Divider

A thin rule between groups of content or controls, optionally with a label in it.

Prop Type Default What it does
orientation "horizontal" | "vertical" "horizontal" Across its parent, or between items in a row (stretching to the row's height).
label ReactNode none Text in the line ("or", "Older", a date). Horizontal only.
align "start" | "center" | "end" "center" Where the label sits.
strong boolean false border-strong instead of border, for a divider that has to read on surface.

DividerProps is the props type.

Spacer

function Spacer(props: ComponentProps<"div"> & { space?: Gap }): JSX.Element;

Empty space in a Stack or Toolbar. With no space it takes all the free room, pushing what follows to the far end; with space (a Gap, as on Stack's gap) it is a fixed gap.

ScrollArea

A scroll container with the app's thin scrollbar, keyboard scrolling (it takes focus, tabIndex 0 by default) and optional fading edges that show there is more. Give it a height (max-h-64, flex-1 min-h-0) to scroll.

Prop Type Default What it does
orientation "vertical" | "horizontal" | "both" "vertical" Which way it scrolls.
fade boolean false Fades the content out at an edge while there is more to scroll that way.
hideScrollbar boolean false Hides the scrollbar; it still scrolls by wheel, touch and keyboard.

ScrollAreaProps is the props type.

SplitView

Two panes with a handle between them that resizes by drag or keyboard, stacking on phones: an editor and its preview, a list and an inspector. The handle is a focusable separator: the arrow keys move it by step (Shift moves 4 times as far), Home and End go to min and max, and a double-click resets it to defaultValue.

Prop Type Default What it does
start ReactNode required The first pane: left, or top with orientation="vertical".
end ReactNode required The second pane: right, or bottom.
orientation "horizontal" | "vertical" "horizontal" Side by side, or one above the other.
value number none The first pane's size in percent of the whole (controlled).
defaultValue number 50 The starting size when uncontrolled, and what a double-click resets to.
onChange (value: number) => void none Called with the new size in percent while dragging or on arrow keys.
min number 20 The smallest the first pane gets, in percent.
max number 80 The largest the first pane gets, in percent.
step number 5 Percent per arrow key press.
stackOnPhone boolean true Side-by-side panes stack, start above end, on phones (horizontal only).
handleLabel string "Resize" The handle's accessible name.

SplitViewProps is the props type.

ListDetail

Master and detail: a list on the left and the selected item on the right, and on phones one at a time, with a back bar to return to the list.

Prop Type Default What it does
list ReactNode required The list (master) pane.
detail ReactNode required The detail of the selected item.
open boolean none Whether an item is open. On phones this shows detail (with a back bar) instead of list; on the desktop both show and placeholder stands in while closed.
defaultOpen boolean false The starting state when uncontrolled.
onOpenChange (open: boolean) => void none Called with false when the back bar's button is pressed.
placeholder ReactNode none Shown in the detail pane on the desktop while nothing is open: usually an EmptyState.
detailTitle ReactNode none The title in the phone back bar, normally the open item's name.
backLabel string "Back" The back button's label.
detailActions ReactNode none Actions on the right of the phone back bar.
listWidth "sm" | "md" | "lg" "md" The list pane's width once the layout is 768 px wide or more: 256, 320 or 384 px.
listLabel string none The list pane's accessible name.

ListDetailProps is the props type.

SidebarLayout, useSidebarLayout

An extension with its own sub-nav: a sidebar column beside the content on the desktop, folded into a menu bar over the content on phones. The phone menu closes when a NavList item is picked.

Prop Type Default What it does
sidebar ReactNode required The sub-nav: usually a NavList.
title ReactNode none Above the sidebar on the desktop and in the phone bar: the extension's or section's name.
label string "Sections" The nav landmark's accessible name.
sidebarFooter ReactNode none Pinned below the sidebar's list: an account row, a settings link.
current ReactNode none In the phone bar, a label for what is open now ("Inbox"), beside the menu button.
width "sm" | "md" | "lg" "md" The sidebar's width once the layout is 768 px wide or more: 192, 224 or 256 px.
open boolean none Whether the phone menu is open (controlled). The desktop always shows the sidebar.
defaultOpen boolean false The phone menu's starting state when uncontrolled.
onOpenChange (open: boolean) => void none Called when the phone menu opens or closes.
function useSidebarLayout(): { open: boolean; setOpen: (open: boolean) => void; close: () => void } | null;

useSidebarLayout returns the surrounding SidebarLayout's phone menu state, or null outside one. open is always false on the desktop. Call close() after navigating from a control that isn't a NavList.

SidebarLayoutProps is the props type.

SidePanel

A panel beside the content for the details or settings of what is selected (an inspector): a header with a close button, a body that scrolls, a footer. Full width under the content on phones. Renders an <aside>.

Prop Type Default What it does
title ReactNode none The panel's heading.
description ReactNode none One line under the title.
actions ReactNode none Buttons in the header, before the close button.
onClose () => void none Shows a close button in the header that calls this.
closeLabel string "Close" The close button's accessible name.
footer ReactNode none Pinned to the bottom of the panel: its actions.
side "start" | "end" "end" Which edge of the content it sits on, for its border.
width "sm" | "md" | "lg" "md" Its width from md: up: 288, 320 or 384 px.

SidePanelProps is the props type. For a panel that slides over the page, use Drawer.

Panel

A plain surface to group content on: a box with the app's border and radius. For a card with a header and footer use Card; this is the bare surface.

Prop Type Default What it does
variant "surface" | "elevated" | "bordered" "surface" A raised card on the page's bg; one step up with a shadow, for something above other surfaces; or a border on whatever is behind, no fill.
padding "none" | "sm" | "md" | "lg" "md" Inner padding: 0, 12, 16 or 24 px.
radius "md" | "lg" | "xl" "lg" Corner radius.
as as Stack "div" The element to render.

PanelProps is the props type.

Inset

function Inset(props: ComponentProps<"div"> & { padding?: "none" | "sm" | "md" | "lg"; radius?: "md" | "lg" | "xl"; dashed?: boolean }): JSX.Element;

A recessed well inside a surface: a code sample, a preview, a nested group of options, a drop zone. The opposite of Panel: it sits lower than what is around it. padding defaults to "md", radius to "md", dashed (a dashed border) to false.

AspectRatio

function AspectRatio(props: ComponentProps<"div"> & { ratio?: number }): JSX.Element;

Keeps its content at a fixed width-to-height ratio (an image, a video, a map or a chart) at any width; children fill it. ratio defaults to 16 / 9.

Center

function Center(props: Omit<ComponentProps<"div">, "ref"> & { fill?: boolean; inline?: boolean; as?: BoxTag; ref?: Ref<HTMLElement> }): JSX.Element;

Centres its content both ways: a spinner in a pane, an icon in a tile, a message in an empty area. Give it a size, or fill (default false) to fill its parent. inline (default false) renders an inline-flex <span>, so it fits inside text and buttons. as picks the element instead (the same tags as Stack's as; default "div", or "span" with inline), and ref goes to that element.

VisuallyHidden

function VisuallyHidden(props: ComponentProps<"span"> & { focusable?: boolean }): JSX.Element;

Text for screen readers only: a label for an icon, context a sighted reader gets from the layout. With focusable (default false) it shows while it has focus, for a "Skip to content" link.

This page as markdown · All pages as one file