Lay out a screen
By the end of this page the app shows a toolbar over two columns: the contacts on the left, and the selected contact’s details on the right.
Background
Section titled “Background”Built by hand, this screen is nested flex and grid boxes, each with its own padding and gap. TILE lays out a screen with a few components that own their spacing, so we rarely write padding or flex classes:
Panelis a frame with a header, a body that takes the remaining height, and an optional footer. Use it as the outer shell of a screen. Step 4 puts the screen in one.Toolbaris a row of controls and text. Use it in a panel’s header.Layout.Gridplaces its children in tracks, andLayout.Flexplaces them in a row or a stack. Both take their gaps from the theme’s scale. UseLayout.Gridwhen one track has a fixed size, as the list’s column does in step 4.ScrollAreascrolls its content with the theme’s scrollbar. Use it around content that can grow taller than its column, as the detail does in step 3.
Layout explains how a panel passes its height down to the part that scrolls.
-
Add the data. We keep the contacts in React state until the last page. Put their type and the starting list in
src/contacts.ts:import type * asSelect from '@dxos/react-ui/Select';import Selectexport typeContact = {type Contact = {id: string;name: string;email: string;role: string;}id: string;id: stringname: string;name: stringemail: string;email: stringrole: string;role: string};export constROLES:const ROLES: Select.Option[]Select.import SelectOption[] = [type Option = {value: string;label: string;disabled?: boolean;icon?: string;iconHue?: IconHue;}export Option{value: 'viewer',value: stringlabel: 'Viewer' },label: string{value: 'editor',value: stringlabel: 'Editor' },label: string{value: 'admin',value: stringlabel: 'Admin' },label: string];export constCONTACTS:const CONTACTS: Contact[]Contact[] = [type Contact = {id: string;name: string;email: string;role: string;}{id: 'ada',id: stringname: 'Ada Lovelace',name: stringemail: 'ada@example.com',email: stringrole: 'admin' },role: string{id: 'grace',id: stringname: 'Grace Hopper',name: stringemail: 'grace@example.com',email: stringrole: 'editor' },role: string{id: 'alan',id: stringname: 'Alan Turing',name: stringemail: 'alan@example.com',email: stringrole: 'viewer' },role: string{id: 'katherine',id: stringname: 'Katherine Johnson',name: stringemail: 'katherine@example.com',email: stringrole: 'editor' },role: string];ROLEShas the shape aSelecttakes for its options. The next page uses it. -
List the contacts.
Listboxdraws one row per item, with the label and a second line fromdescription. It handles selection, arrow keys and typeahead.Listbox.Viewportmakes the list scroll inside its column. Addsrc/layout/ContactsScreen.tsx:import * asListbox from '@dxos/react-ui/Listbox';import Listbox6 collapsed linesimport * asPanel from '@dxos/react-ui/Panel';import Panelimport * asScrollArea from '@dxos/react-ui/ScrollArea';import ScrollAreaimport * asStatus from '@dxos/react-ui/Status';import Statusimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbarimport * asTypography from '@dxos/react-ui/Typography';import Typographyimport { typeContact,type Contact = {id: string;name: string;email: string;role: string;}CONTACTS } from '../contacts.ts';const CONTACTS: Contact[]typeContactListProps = {type ContactListProps = {contacts: Contact[];selected?: string;onSelect: (id: string) => void;}contacts:contacts: Contact[]Contact[];type Contact = {id: string;name: string;email: string;role: string;}selected?: string;selected?: string | undefinedonSelect: (onSelect: (id: string) => voidid: string) => void;id: string};/** One row per contact; the list scrolls inside its own viewport. */export constContactList = ({const ContactList: ({ contacts, selected, onSelect }: ContactListProps) => React.JSX.ElementOne row per contact; the list scrolls inside its own viewport.
contacts,contacts: Contact[]selected,selected: string | undefinedonSelect }:onSelect: (id: string) => voidContactListProps) => {type ContactListProps = {contacts: Contact[];selected?: string;onSelect: (id: string) => void;}constitems =const items: {value: string;label: string;description: string;}[]contacts.contacts: Contact[]map((Array<Contact>.map<{value: string;label: string;description: string;}>(callbackfn: (value: Contact, index: number, array: Contact[]) => {value: string;label: string;description: string;}, thisArg?: any): {value: string;label: string;description: string;}[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
contact) => ({contact: Contactvalue:value: stringcontact.contact: Contactid,id: stringlabel:label: stringcontact.contact: Contactname,name: stringdescription:description: stringcontact.contact: Contactemail,email: string}));return (<Listbox.import ListboxRootconst Root: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "onSelect" | "defaultValue">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: readonly Listbox.Option[];selectionMode?: Listbox.SelectionMode;value?: string[];defaultValue?: string[];onValueChange?: (value: string[]) => void;highlightedValue?: string | null;onHighlightChange?: (value: string | null) => void;... 8 more ...;size?: Size;} & React.RefAttributes<...>>export RootArk listbox: single, multiple or no selection, with keyboard navigation, typeahead and
aria-selectedfrom zag. A flex column that caps itself at its parent's height, so a long list scrolls in its Content.items={items: readonly Listbox.Option[]items}const items: {value: string;label: string;description: string;}[]value={value?: string[] | undefinedselected ? [selected: string | undefinedselected] : []}selected: stringonValueChange={([onValueChange?: ((value: string[]) => void) | undefinedid]) =>id: stringid &&id: stringonSelect(onSelect: (id: string) => voidid)}>id: string<Listbox.import ListboxViewport>const Viewport: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {children: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ViewportA thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a fixed-height panel). Its
Contentis the scrolling element, so the thumb sits in the Content's end gutter. Omit it inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.<Listbox.import ListboxContentconst Content: React.ForwardRefExoticComponent<Omit<Layout.ContainerProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ContentThe listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root'svirtualwindowing over its direct children (the rows). Under aViewportit is the scrolling element (insetgutter by default); otherwise its host scrolls and the rows inherit the host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs aViewport.aria-label='Contacts'>"aria-label"?: string | undefinedDefines a string value that labels the current element.
{items.const items: {value: string;label: string;description: string;}[]map((Array<{ value: string; label: string; description: string; }>.map<React.JSX.Element>(callbackfn: (value: {value: string;label: string;description: string;}, index: number, array: {value: string;label: string;description: string;}[]) => React.JSX.Element, thisArg?: any): React.JSX.Element[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
item) => (item: {value: string;label: string;description: string;}<Listbox.import ListboxItemconst Item: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "children">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {item: Listbox.Option;current?: boolean;highlightOnHover?: boolean;children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ItemA row (
option) at least one block tall: without children, the option's icon, label and description; with them, the caller's parts, which the theme places by part (leading cells, text over description, then trailing cells) or, under Rootcolumns, in order across the shared tracks. Pointer presses on a row control stay with the control: they neither select the row nor take focus from the control.key={React.Attributes.key?: React.Key | null | undefineditem.item: {value: string;label: string;description: string;}value}value: stringitem={item: Listbox.Optionitem} />item: {value: string;label: string;description: string;}))}</Listbox.import ListboxContent>const Content: React.ForwardRefExoticComponent<Omit<Layout.ContainerProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ContentThe listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root'svirtualwindowing over its direct children (the rows). Under aViewportit is the scrolling element (insetgutter by default); otherwise its host scrolls and the rows inherit the host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs aViewport.</Listbox.import ListboxViewport>const Viewport: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {children: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ViewportA thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a fixed-height panel). Its
Contentis the scrolling element, so the thumb sits in the Content's end gutter. Omit it inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.</Listbox.import ListboxRoot>const Root: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "onSelect" | "defaultValue">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: readonly Listbox.Option[];selectionMode?: Listbox.SelectionMode;value?: string[];defaultValue?: string[];onValueChange?: (value: string[]) => void;highlightedValue?: string | null;onHighlightChange?: (value: string | null) => void;... 8 more ...;size?: Size;} & React.RefAttributes<...>>export RootArk listbox: single, multiple or no selection, with keyboard navigation, typeahead and
aria-selectedfrom zag. A flex column that caps itself at its parent's height, so a long list scrolls in its Content.);};valueis a list, because a listbox can allow several selections, soonValueChangetakes the first id. -
Show the selected contact.
Typography.Textwithtone='muted'reads as secondary text. When no contact is selected,Status.Emptyshows an icon and a hint in the middle of the column:import * asLayout from '@dxos/react-ui/Layout';import Layout2 collapsed linesimport * asListbox from '@dxos/react-ui/Listbox';import Listboximport * asPanel from '@dxos/react-ui/Panel';import Panelimport * asScrollArea from '@dxos/react-ui/ScrollArea';import ScrollAreaimport * asStatus from '@dxos/react-ui/Status';import Status1 collapsed lineimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbarimport * asTypography from '@dxos/react-ui/Typography';import Typographyimport { typeContact,type Contact = {id: string;name: string;email: string;role: string;}CONTACTS } from '../contacts.ts';const CONTACTS: Contact[]27 collapsed linestypeContactListProps = {type ContactListProps = {contacts: Contact[];selected?: string;onSelect: (id: string) => void;}contacts:contacts: Contact[]Contact[];type Contact = {id: string;name: string;email: string;role: string;}selected?: string;selected?: string | undefinedonSelect: (onSelect: (id: string) => voidid: string) => void;id: string};/** One row per contact; the list scrolls inside its own viewport. */export constContactList = ({const ContactList: ({ contacts, selected, onSelect }: ContactListProps) => React.JSX.ElementOne row per contact; the list scrolls inside its own viewport.
contacts,contacts: Contact[]selected,selected: string | undefinedonSelect }:onSelect: (id: string) => voidContactListProps) => {type ContactListProps = {contacts: Contact[];selected?: string;onSelect: (id: string) => void;}constitems =const items: {value: string;label: string;description: string;}[]contacts.contacts: Contact[]map((Array<Contact>.map<{value: string;label: string;description: string;}>(callbackfn: (value: Contact, index: number, array: Contact[]) => {value: string;label: string;description: string;}, thisArg?: any): {value: string;label: string;description: string;}[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
contact) => ({contact: Contactvalue:value: stringcontact.contact: Contactid,id: stringlabel:label: stringcontact.contact: Contactname,name: stringdescription:description: stringcontact.contact: Contactemail,email: string}));return (<Listbox.import ListboxRootconst Root: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "onSelect" | "defaultValue">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: readonly Listbox.Option[];selectionMode?: Listbox.SelectionMode;value?: string[];defaultValue?: string[];onValueChange?: (value: string[]) => void;highlightedValue?: string | null;onHighlightChange?: (value: string | null) => void;... 8 more ...;size?: Size;} & React.RefAttributes<...>>export RootArk listbox: single, multiple or no selection, with keyboard navigation, typeahead and
aria-selectedfrom zag. A flex column that caps itself at its parent's height, so a long list scrolls in its Content.items={items: readonly Listbox.Option[]items}const items: {value: string;label: string;description: string;}[]value={value?: string[] | undefinedselected ? [selected: string | undefinedselected] : []}selected: stringonValueChange={([onValueChange?: ((value: string[]) => void) | undefinedid]) =>id: stringid &&id: stringonSelect(onSelect: (id: string) => voidid)}>id: string<Listbox.import ListboxViewport>const Viewport: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {children: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ViewportA thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a fixed-height panel). Its
Contentis the scrolling element, so the thumb sits in the Content's end gutter. Omit it inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.<Listbox.import ListboxContentconst Content: React.ForwardRefExoticComponent<Omit<Layout.ContainerProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ContentThe listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root'svirtualwindowing over its direct children (the rows). Under aViewportit is the scrolling element (insetgutter by default); otherwise its host scrolls and the rows inherit the host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs aViewport.aria-label='Contacts'>"aria-label"?: string | undefinedDefines a string value that labels the current element.
{items.const items: {value: string;label: string;description: string;}[]map((Array<{ value: string; label: string; description: string; }>.map<React.JSX.Element>(callbackfn: (value: {value: string;label: string;description: string;}, index: number, array: {value: string;label: string;description: string;}[]) => React.JSX.Element, thisArg?: any): React.JSX.Element[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
item) => (item: {value: string;label: string;description: string;}<Listbox.import ListboxItemconst Item: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "children">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {item: Listbox.Option;current?: boolean;highlightOnHover?: boolean;children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ItemA row (
option) at least one block tall: without children, the option's icon, label and description; with them, the caller's parts, which the theme places by part (leading cells, text over description, then trailing cells) or, under Rootcolumns, in order across the shared tracks. Pointer presses on a row control stay with the control: they neither select the row nor take focus from the control.key={React.Attributes.key?: React.Key | null | undefineditem.item: {value: string;label: string;description: string;}value}value: stringitem={item: Listbox.Optionitem} />item: {value: string;label: string;description: string;}))}</Listbox.import ListboxContent>const Content: React.ForwardRefExoticComponent<Omit<Layout.ContainerProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ContentThe listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root'svirtualwindowing over its direct children (the rows). Under aViewportit is the scrolling element (insetgutter by default); otherwise its host scrolls and the rows inherit the host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs aViewport.</Listbox.import ListboxViewport>const Viewport: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {children: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ViewportA thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a fixed-height panel). Its
Contentis the scrolling element, so the thumb sits in the Content's end gutter. Omit it inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.</Listbox.import ListboxRoot>const Root: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "onSelect" | "defaultValue">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: readonly Listbox.Option[];selectionMode?: Listbox.SelectionMode;value?: string[];defaultValue?: string[];onValueChange?: (value: string[]) => void;highlightedValue?: string | null;onHighlightChange?: (value: string | null) => void;... 8 more ...;size?: Size;} & React.RefAttributes<...>>export RootArk listbox: single, multiple or no selection, with keyboard navigation, typeahead and
aria-selectedfrom zag. A flex column that caps itself at its parent's height, so a long list scrolls in its Content.);};/** The selected contact's fields, or a hint when nothing is selected. */export constContactDetail = ({const ContactDetail: ({ contact }: {contact?: Contact;}) => React.JSX.ElementThe selected contact's fields, or a hint when nothing is selected.
contact }: {contact: Contact | undefinedcontact?:contact?: Contact | undefinedContact }) =>type Contact = {id: string;name: string;email: string;role: string;}contact ? (contact: Contact | undefined<ScrollArea.import ScrollAreaRoot>const Root: React.ForwardRefExoticComponent<Omit<ScrollArea.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export RootNon-scrolling frame: hosts the overlay thumbs and is the query container for its content.
<ScrollArea.import ScrollAreaViewportconst Viewport: React.ForwardRefExoticComponent<Omit<ScrollArea.ViewportProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ViewportThe scrolling element; under
asChildit is the child (e.g. a Container) itself.asChild>asChild?: boolean | undefined<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>One-axis layout box: the primitive that replaces hand-written
flex …wrapper divs.gapis restricted to the named steps of the theme spacing ramp (seeGap
), which is the point of the prop — an off-ramp
gap-2/gap-3literal in a container is the drift it prevents. Anything the props don't cover (padding, sizing, overflow, colour) goes throughclassNames; the component deliberately grows no padding or colour props, since components own their own spacing.There is no implicit
align. Row-centering is the common case, but defaulting it would silently restyle any consumer relying on the CSSstretchinitial value.Use
asChildto project the layout onto a semantic element (<header>,<ul>,<a>).columncolumn?: boolean | undefinedStack on the block axis instead of the inline axis.
gap='sm'gap?: Layout.Gap | undefinedclassNames='p-4'>classNames?: ClassNameValue<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.asChild>asChild?: boolean | undefined<h2>{React.JSX.IntrinsicElements.h2: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>contact.contact: Contactname}</name: stringh2>React.JSX.IntrinsicElements.h2: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement></Typography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.tone='muted'>{tone?: Typography.TextTone | undefinedEmphasis below the default (DESIGN.md "Text emphasis"):
descriptionfor secondary content,subduedfor interface text.contact.contact: Contactemail}</email: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.tone='muted'>Role: {tone?: Typography.TextTone | undefinedEmphasis below the default (DESIGN.md "Text emphasis"):
descriptionfor secondary content,subduedfor interface text.contact.contact: Contactrole}</role: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.</Layout.import LayoutFlex>const Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>One-axis layout box: the primitive that replaces hand-written
flex …wrapper divs.gapis restricted to the named steps of the theme spacing ramp (seeGap
), which is the point of the prop — an off-ramp
gap-2/gap-3literal in a container is the drift it prevents. Anything the props don't cover (padding, sizing, overflow, colour) goes throughclassNames; the component deliberately grows no padding or colour props, since components own their own spacing.There is no implicit
align. Row-centering is the common case, but defaulting it would silently restyle any consumer relying on the CSSstretchinitial value.Use
asChildto project the layout onto a semantic element (<header>,<ul>,<a>).</ScrollArea.import ScrollAreaViewport>const Viewport: React.ForwardRefExoticComponent<Omit<ScrollArea.ViewportProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ViewportThe scrolling element; under
asChildit is the child (e.g. a Container) itself.</ScrollArea.import ScrollAreaRoot>const Root: React.ForwardRefExoticComponent<Omit<ScrollArea.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export RootNon-scrolling frame: hosts the overlay thumbs and is the query container for its content.
) : (<Status.import StatusEmptyconst Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>Stands in for content that is not there (no items, no selection, no result): a centred status message, its text the children or the translated "No items". Composites build their own
Emptypart on it.icon='ph--address-book--regular'>Choose a contact</icon?: string | undefinedA Phosphor icon above the message; decorative, since the message carries the statement.
Status.import StatusEmpty>const Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>Stands in for content that is not there (no items, no selection, no result): a centred status message, its text the children or the translated "No items". Composites build their own
Emptypart on it.);Nothing on this page clears the selection, so we don’t see the hint yet. It first shows in Icons and translations, after a delete.
-
Put them in a panel. The toolbar goes in
Panel.Header.cols={['16rem', 'fill']}gives the list a fixed width and the detail the rest:importReact, {(alias) namespace Reactimport ReactuseState } from 'react';function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)Returns a stateful value, and a function to update it.
import * asLayout from '@dxos/react-ui/Layout';import Layout1 collapsed lineimport * asListbox from '@dxos/react-ui/Listbox';import Listboximport * asPanel from '@dxos/react-ui/Panel';import Panel2 collapsed linesimport * asScrollArea from '@dxos/react-ui/ScrollArea';import ScrollAreaimport * asStatus from '@dxos/react-ui/Status';import Statusimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbar2 collapsed linesimport * asTypography from '@dxos/react-ui/Typography';import Typographyimport { typeContact,type Contact = {id: string;name: string;email: string;role: string;}CONTACTS } from '../contacts.ts';const CONTACTS: Contact[]45 collapsed linestypeContactListProps = {type ContactListProps = {contacts: Contact[];selected?: string;onSelect: (id: string) => void;}contacts:contacts: Contact[]Contact[];type Contact = {id: string;name: string;email: string;role: string;}selected?: string;selected?: string | undefinedonSelect: (onSelect: (id: string) => voidid: string) => void;id: string};/** One row per contact; the list scrolls inside its own viewport. */export constContactList = ({const ContactList: ({ contacts, selected, onSelect }: ContactListProps) => React.JSX.ElementOne row per contact; the list scrolls inside its own viewport.
contacts,contacts: Contact[]selected,selected: string | undefinedonSelect }:onSelect: (id: string) => voidContactListProps) => {type ContactListProps = {contacts: Contact[];selected?: string;onSelect: (id: string) => void;}constitems =const items: {value: string;label: string;description: string;}[]contacts.contacts: Contact[]map((Array<Contact>.map<{value: string;label: string;description: string;}>(callbackfn: (value: Contact, index: number, array: Contact[]) => {value: string;label: string;description: string;}, thisArg?: any): {value: string;label: string;description: string;}[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
contact) => ({contact: Contactvalue:value: stringcontact.contact: Contactid,id: stringlabel:label: stringcontact.contact: Contactname,name: stringdescription:description: stringcontact.contact: Contactemail,email: string}));return (<Listbox.import ListboxRootconst Root: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "onSelect" | "defaultValue">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: readonly Listbox.Option[];selectionMode?: Listbox.SelectionMode;value?: string[];defaultValue?: string[];onValueChange?: (value: string[]) => void;highlightedValue?: string | null;onHighlightChange?: (value: string | null) => void;... 8 more ...;size?: Size;} & React.RefAttributes<...>>export RootArk listbox: single, multiple or no selection, with keyboard navigation, typeahead and
aria-selectedfrom zag. A flex column that caps itself at its parent's height, so a long list scrolls in its Content.items={items: readonly Listbox.Option[]items}const items: {value: string;label: string;description: string;}[]value={value?: string[] | undefinedselected ? [selected: string | undefinedselected] : []}selected: stringonValueChange={([onValueChange?: ((value: string[]) => void) | undefinedid]) =>id: stringid &&id: stringonSelect(onSelect: (id: string) => voidid)}>id: string<Listbox.import ListboxViewport>const Viewport: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {children: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ViewportA thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a fixed-height panel). Its
Contentis the scrolling element, so the thumb sits in the Content's end gutter. Omit it inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.<Listbox.import ListboxContentconst Content: React.ForwardRefExoticComponent<Omit<Layout.ContainerProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ContentThe listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root'svirtualwindowing over its direct children (the rows). Under aViewportit is the scrolling element (insetgutter by default); otherwise its host scrolls and the rows inherit the host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs aViewport.aria-label='Contacts'>"aria-label"?: string | undefinedDefines a string value that labels the current element.
{items.const items: {value: string;label: string;description: string;}[]map((Array<{ value: string; label: string; description: string; }>.map<React.JSX.Element>(callbackfn: (value: {value: string;label: string;description: string;}, index: number, array: {value: string;label: string;description: string;}[]) => React.JSX.Element, thisArg?: any): React.JSX.Element[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
item) => (item: {value: string;label: string;description: string;}<Listbox.import ListboxItemconst Item: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "children">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {item: Listbox.Option;current?: boolean;highlightOnHover?: boolean;children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ItemA row (
option) at least one block tall: without children, the option's icon, label and description; with them, the caller's parts, which the theme places by part (leading cells, text over description, then trailing cells) or, under Rootcolumns, in order across the shared tracks. Pointer presses on a row control stay with the control: they neither select the row nor take focus from the control.key={React.Attributes.key?: React.Key | null | undefineditem.item: {value: string;label: string;description: string;}value}value: stringitem={item: Listbox.Optionitem} />item: {value: string;label: string;description: string;}))}</Listbox.import ListboxContent>const Content: React.ForwardRefExoticComponent<Omit<Layout.ContainerProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ContentThe listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root'svirtualwindowing over its direct children (the rows). Under aViewportit is the scrolling element (insetgutter by default); otherwise its host scrolls and the rows inherit the host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs aViewport.</Listbox.import ListboxViewport>const Viewport: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {children: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ViewportA thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a fixed-height panel). Its
Contentis the scrolling element, so the thumb sits in the Content's end gutter. Omit it inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.</Listbox.import ListboxRoot>const Root: React.ForwardRefExoticComponent<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "onSelect" | "defaultValue">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: readonly Listbox.Option[];selectionMode?: Listbox.SelectionMode;value?: string[];defaultValue?: string[];onValueChange?: (value: string[]) => void;highlightedValue?: string | null;onHighlightChange?: (value: string | null) => void;... 8 more ...;size?: Size;} & React.RefAttributes<...>>export RootArk listbox: single, multiple or no selection, with keyboard navigation, typeahead and
aria-selectedfrom zag. A flex column that caps itself at its parent's height, so a long list scrolls in its Content.);};/** The selected contact's fields, or a hint when nothing is selected. */export constContactDetail = ({const ContactDetail: ({ contact }: {contact?: Contact;}) => React.JSX.ElementThe selected contact's fields, or a hint when nothing is selected.
contact }: {contact: Contact | undefinedcontact?:contact?: Contact | undefinedContact }) =>type Contact = {id: string;name: string;email: string;role: string;}contact ? (contact: Contact | undefined<ScrollArea.import ScrollAreaRoot>const Root: React.ForwardRefExoticComponent<Omit<ScrollArea.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export RootNon-scrolling frame: hosts the overlay thumbs and is the query container for its content.
<ScrollArea.import ScrollAreaViewportconst Viewport: React.ForwardRefExoticComponent<Omit<ScrollArea.ViewportProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ViewportThe scrolling element; under
asChildit is the child (e.g. a Container) itself.asChild>asChild?: boolean | undefined<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>One-axis layout box: the primitive that replaces hand-written
flex …wrapper divs.gapis restricted to the named steps of the theme spacing ramp (seeGap
), which is the point of the prop — an off-ramp
gap-2/gap-3literal in a container is the drift it prevents. Anything the props don't cover (padding, sizing, overflow, colour) goes throughclassNames; the component deliberately grows no padding or colour props, since components own their own spacing.There is no implicit
align. Row-centering is the common case, but defaulting it would silently restyle any consumer relying on the CSSstretchinitial value.Use
asChildto project the layout onto a semantic element (<header>,<ul>,<a>).columncolumn?: boolean | undefinedStack on the block axis instead of the inline axis.
gap='sm'gap?: Layout.Gap | undefinedclassNames='p-4'>classNames?: ClassNameValue<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.asChild>asChild?: boolean | undefined<h2>{React.JSX.IntrinsicElements.h2: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>contact.contact: Contactname}</name: stringh2>React.JSX.IntrinsicElements.h2: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement></Typography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.tone='muted'>{tone?: Typography.TextTone | undefinedEmphasis below the default (DESIGN.md "Text emphasis"):
descriptionfor secondary content,subduedfor interface text.contact.contact: Contactemail}</email: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.tone='muted'>Role: {tone?: Typography.TextTone | undefinedEmphasis below the default (DESIGN.md "Text emphasis"):
descriptionfor secondary content,subduedfor interface text.contact.contact: Contactrole}</role: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>export TextText whose first line is centred in a block, so it lines up with a Block or control beside it however many lines it wraps to. Renders a
<p>;asChildputs the metrics on a heading or other text element instead.</Layout.import LayoutFlex>const Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>One-axis layout box: the primitive that replaces hand-written
flex …wrapper divs.gapis restricted to the named steps of the theme spacing ramp (seeGap
), which is the point of the prop — an off-ramp
gap-2/gap-3literal in a container is the drift it prevents. Anything the props don't cover (padding, sizing, overflow, colour) goes throughclassNames; the component deliberately grows no padding or colour props, since components own their own spacing.There is no implicit
align. Row-centering is the common case, but defaulting it would silently restyle any consumer relying on the CSSstretchinitial value.Use
asChildto project the layout onto a semantic element (<header>,<ul>,<a>).</ScrollArea.import ScrollAreaViewport>const Viewport: React.ForwardRefExoticComponent<Omit<ScrollArea.ViewportProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export ViewportThe scrolling element; under
asChildit is the child (e.g. a Container) itself.</ScrollArea.import ScrollAreaRoot>const Root: React.ForwardRefExoticComponent<Omit<ScrollArea.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export RootNon-scrolling frame: hosts the overlay thumbs and is the query container for its content.
) : (<Status.import StatusEmptyconst Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>Stands in for content that is not there (no items, no selection, no result): a centred status message, its text the children or the translated "No items". Composites build their own
Emptypart on it.icon='ph--address-book--regular'>Choose a contact</icon?: string | undefinedA Phosphor icon above the message; decorative, since the message carries the statement.
Status.import StatusEmpty>const Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>Stands in for content that is not there (no items, no selection, no result): a centred status message, its text the children or the translated "No items". Composites build their own
Emptypart on it.);export constContactsScreen = () => {const ContactsScreen: () => React.JSX.Elementconst [contacts] =const contacts: Contact[]useState(useState<Contact[]>(initialState: Contact[] | (() => Contact[])): [Contact[], React.Dispatch<React.SetStateAction<Contact[]>>] (+1 overload)Returns a stateful value, and a function to update it.
CONTACTS);const CONTACTS: Contact[]const [selected,const selected: stringsetSelected] =const setSelected: React.Dispatch<React.SetStateAction<string>>useState<string>(useState<string>(initialState: string | (() => string)): [string, React.Dispatch<React.SetStateAction<string>>] (+1 overload)Returns a stateful value, and a function to update it.
contacts[0].const contacts: Contact[]id);id: stringconstcontact =const contact: Contact | undefinedcontacts.const contacts: Contact[]find(({Array<Contact>.find(predicate: (value: Contact, index: number, obj: Contact[]) => unknown, thisArg?: any): Contact | undefined (+1 overload)Returns the value of the first element in the array where predicate is true, and undefined otherwise.
id }) =>id: stringid ===id: stringselected);const selected: stringreturn (<Panel.import PanelRoot>const Root: React.ForwardRefExoticComponent<Omit<Panel.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export RootThe plank host: fills its parent, sets
data-sizeand a level for its subtree, and is the pane's query container, so its header, body and footer collapse at the same pane width.<Panel.import PanelHeader>const Header: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export HeaderThe top row on the bar aspect, which steps off whatever level hosts the panel; it sizes to its content, so it takes no space when empty and one block when it holds a
Toolbar.Root.<Toolbar.import ToolbarRoot>const Root: React.ForwardRefExoticComponent<Omit<Toolbar.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export Rootrole=toolbarwith the roving focus that role promises (decision 9); items that overflow scroll along its axis in a thin ScrollArea whose bar shows on hover, the toolbar itself being the viewport.<Toolbar.import ToolbarText>Contacts</const Text: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export TextA run of text that takes the free space and truncates; not an item, so roving focus skips it.
Toolbar.import ToolbarText>const Text: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export TextA run of text that takes the free space and truncates; not an item, so roving focus skips it.
<Toolbar.import ToolbarSeparatorconst Separator: React.ForwardRefExoticComponent<Omit<Toolbar.SeparatorProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export SeparatorA rule across the toolbar's axis (vertical in a horizontal toolbar), or with
variant='gap'a growing spacer; not an item, so roving focus skips it.variant='gap' />variant?: "line" | "gap" | undefinedgapis an empty spacer that grows, pushing the items after it to the toolbar's end.<Toolbar.import ToolbarText>{const Text: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export TextA run of text that takes the free space and truncates; not an item, so roving focus skips it.
contacts.const contacts: Contact[]length} contacts</Array<Contact>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
Toolbar.import ToolbarText>const Text: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export TextA run of text that takes the free space and truncates; not an item, so roving focus skips it.
</Toolbar.import ToolbarRoot>const Root: React.ForwardRefExoticComponent<Omit<Toolbar.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export Rootrole=toolbarwith the roving focus that role promises (decision 9); items that overflow scroll along its axis in a thin ScrollArea whose bar shows on hover, the toolbar itself being the viewport.</Panel.import PanelHeader>const Header: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export HeaderThe top row on the bar aspect, which steps off whatever level hosts the panel; it sizes to its content, so it takes no space when empty and one block when it holds a
Toolbar.Root.<Panel.import PanelBodyconst Body: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export BodyThe growing middle row, a plain slot: it neither scrolls nor adds a gutter, so content composes its own frame (
asChildonto aScrollArea.Rootaround a Container, or a canvas that fills the row). The first Container under it takes the panel's gutter unless it names one. Like the header and footer it is no query container, so its content collapses against the panel.asChild>asChild?: boolean | undefined<Layout.import LayoutGridconst Grid: React.ForwardRefExoticComponent<Omit<Layout.GridProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>CSS grid container.
cols/rowstake a count for equal tracks, or a list of tokens for anything asymmetric:cols={['fill', 'min']}isgrid-cols-[1fr_min-content], with the flexible track allowed to shrink so long content truncates rather than widening the grid. The tokens are typed, so a misspelt track is a compile error rather than an invalid template.subgridadopts the parent's tracks and spans them (grid-column: 1 / -1), which is the only way it is ever useful; the parent must actually define those tracks. CheckColumn.RowandCard.Rowfirst — both already are 3-track subgrid rows.gapis restricted to the named steps of the theme spacing ramp (seeGap
). As with
Flex, padding, sizing, and colour go throughclassNamesrather than growing props here.cols={['16rem', 'fill']}cols?: Layout.GridTracks | undefinedgrow>grow?: boolean | undefinedFill and clip the parent (
dx-expand); off by default, asFlex's is, so a grid sizes to its content.<ContactListconst ContactList: ({ contacts, selected, onSelect }: ContactListProps) => React.JSX.ElementOne row per contact; the list scrolls inside its own viewport.
contacts={contacts: Contact[]contacts}const contacts: Contact[]selected={selected?: string | undefinedselected}const selected: stringonSelect={onSelect: (id: string) => voidsetSelected} />const setSelected: React.Dispatch<React.SetStateAction<string>><ContactDetailconst ContactDetail: ({ contact }: {contact?: Contact;}) => React.JSX.ElementThe selected contact's fields, or a hint when nothing is selected.
contact={contact?: Contact | undefinedcontact} />const contact: Contact | undefined</Layout.import LayoutGrid>const Grid: React.ForwardRefExoticComponent<Omit<Layout.GridProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>CSS grid container.
cols/rowstake a count for equal tracks, or a list of tokens for anything asymmetric:cols={['fill', 'min']}isgrid-cols-[1fr_min-content], with the flexible track allowed to shrink so long content truncates rather than widening the grid. The tokens are typed, so a misspelt track is a compile error rather than an invalid template.subgridadopts the parent's tracks and spans them (grid-column: 1 / -1), which is the only way it is ever useful; the parent must actually define those tracks. CheckColumn.RowandCard.Rowfirst — both already are 3-track subgrid rows.gapis restricted to the named steps of the theme spacing ramp (seeGap
). As with
Flex, padding, sizing, and colour go throughclassNamesrather than growing props here.</Panel.import PanelBody>const Body: React.ForwardRefExoticComponent<Omit<{asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export BodyThe growing middle row, a plain slot: it neither scrolls nor adds a gutter, so content composes its own frame (
asChildonto aScrollArea.Rootaround a Container, or a canvas that fills the row). The first Container under it takes the panel's gutter unless it names one. Like the header and footer it is no query container, so its content collapses against the panel.</Panel.import PanelRoot>const Root: React.ForwardRefExoticComponent<Omit<Panel.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLDivElement>>export RootThe plank host: fills its parent, sets
data-sizeand a level for its subtree, and is the pane's query container, so its header, body and footer collapse at the same pane width.);};Panel.Body asChildmakes the grid itself the body, so the grid fills the height under the toolbar and no extra element sits between them. -
Render the screen. In
src/main.tsx, render<ContactsScreen />in place of<App />, imported from./layout/ContactsScreen.tsx. Give it the window’s height inindex.html, so the panel fills it:index.html <div id="root" style="height: 100vh"></div>
Try it
Section titled “Try it”Click a contact, or move through the list with the arrow keys.
What you can do now
Section titled “What you can do now”You can lay out a screen with a toolbar, a scrolling list and a detail column. Next, Inputs and actions makes the detail editable.