Inputs and actions
By the end of this page the detail column is a form. You can change a contact’s name, email or role, then save or revert.
Background
Section titled “Background”We build the form from three components:
- A
Fieldholds one input. It ties the label to the control for screen readers, and lines up labels, help text and errors. Use one around every input that has a label. Input.Rootis a text input. Use itstypefor one kind of text, such as the'email'of step 1.Selectopens a list of options, and the user picks one. Use it when the choices are fixed, as our three roles are.
Input.Root and Select both work controlled, with a value and a change handler, the way React inputs do.
Input lists the other controls, such as checkboxes and switches, and
Button lists the button variants.
-
Write the editor. The editor edits a copy of the contact, which it keeps in
draft, so nothing changes until Save. We disable Save until the draft differs from the contact, and while the name is empty. Addsrc/inputs/ContactEditor.tsx: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 * asButton from '@dxos/react-ui/Button';import Buttonimport * asField from '@dxos/react-ui/Field';import Fieldimport * asInput from '@dxos/react-ui/Input';import Inputimport * asLayout from '@dxos/react-ui/Layout';import Layoutimport * asSelect from '@dxos/react-ui/Select';import Selectimport { typeContact,type Contact = {id: string;name: string;email: string;role: string;}ROLES } from '../contacts.ts';const ROLES: Select.Option[]6 collapsed linesexport typeContactEditorProps = {type ContactEditorProps = {contact: Contact;onSave: (contact: Contact) => void;}contact:contact: ContactContact;type Contact = {id: string;name: string;email: string;role: string;}onSave: (onSave: (contact: Contact) => voidcontact:contact: ContactContact) => void;type Contact = {id: string;name: string;email: string;role: string;}};/** Edits a copy of `contact`; nothing changes until Save. */export constContactEditor = ({const ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.contact,contact: ContactonSave }:onSave: (contact: Contact) => voidContactEditorProps) => {type ContactEditorProps = {contact: Contact;onSave: (contact: Contact) => void;}const [draft,const draft: ContactsetDraft] =const setDraft: React.Dispatch<React.SetStateAction<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.
contact);contact: Contactconstchanged =const changed: booleanJSON.var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
stringify(JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
draft) !==const draft: ContactJSON.var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
stringify(JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
contact);contact: Contactreturn (<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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='form'>gap?: Layout.Gap | undefined<Field.import FieldRoot>const Root: React.ForwardRefExoticComponent<Omit<FieldRootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {validationValence?: Field.Valence;layout?: "stack" | "row" | "inline";level?: Layout.Level;span?: Layout.Span;tone?: "muted";} & React.RefAttributes<HTMLDivElement>>export RootA part, not a container (decision 13): a flex stack in the content track with the label above its control.
<Field.import FieldLabel>Name</const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export LabelNames the control; while the root is
requiredit ends with the required indicator, unless aRequiredIndicatoramong its children places the mark itself.Field.import FieldLabel>const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export LabelNames the control; while the root is
requiredit ends with the required indicator, unless aRequiredIndicatoramong its children places the mark itself.<Input.import InputRootconst Root: React.ForwardRefExoticComponent<Omit<Input.RootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLInputElement>>export RootText input at control size; inside a
Field.Rootit takes the field's id, label and description wiring. Withstartorendit renders aControlFrameholding the adornments and a bare input;data-testidand classes then go to the frame, the ref to the input.value={value?: string | number | readonly string[] | undefineddraft.const draft: Contactname}name: stringonChange={(onChange?: React.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefinedevent) =>event: React.ChangeEvent<HTMLInputElement, HTMLInputElement>setDraft({ ...const setDraft: (value: React.SetStateAction<Contact>) => voiddraft,const draft: Contactname:name: stringevent.event: React.ChangeEvent<HTMLInputElement, HTMLInputElement>target.React.ChangeEvent<HTMLInputElement, HTMLInputElement>.target: EventTarget & HTMLInputElementvalue })} />HTMLInputElement.value: stringThe
valueproperty of the HTMLInputElement interface represents the current value of the element as a string.</Field.import FieldRoot>const Root: React.ForwardRefExoticComponent<Omit<FieldRootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {validationValence?: Field.Valence;layout?: "stack" | "row" | "inline";level?: Layout.Level;span?: Layout.Span;tone?: "muted";} & React.RefAttributes<HTMLDivElement>>export RootA part, not a container (decision 13): a flex stack in the content track with the label above its control.
<Field.import FieldRoot>const Root: React.ForwardRefExoticComponent<Omit<FieldRootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {validationValence?: Field.Valence;layout?: "stack" | "row" | "inline";level?: Layout.Level;span?: Layout.Span;tone?: "muted";} & React.RefAttributes<HTMLDivElement>>export RootA part, not a container (decision 13): a flex stack in the content track with the label above its control.
<Field.import FieldLabel>Email</const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export LabelNames the control; while the root is
requiredit ends with the required indicator, unless aRequiredIndicatoramong its children places the mark itself.Field.import FieldLabel>const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export LabelNames the control; while the root is
requiredit ends with the required indicator, unless aRequiredIndicatoramong its children places the mark itself.<Input.import InputRootconst Root: React.ForwardRefExoticComponent<Omit<Input.RootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLInputElement>>export RootText input at control size; inside a
Field.Rootit takes the field's id, label and description wiring. Withstartorendit renders aControlFrameholding the adornments and a bare input;data-testidand classes then go to the frame, the ref to the input.type='email'type?: React.HTMLInputTypeAttribute | undefinedvalue={value?: string | number | readonly string[] | undefineddraft.const draft: Contactemail}email: stringonChange={(onChange?: React.ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefinedevent) =>event: React.ChangeEvent<HTMLInputElement, HTMLInputElement>setDraft({ ...const setDraft: (value: React.SetStateAction<Contact>) => voiddraft,const draft: Contactemail:email: stringevent.event: React.ChangeEvent<HTMLInputElement, HTMLInputElement>target.React.ChangeEvent<HTMLInputElement, HTMLInputElement>.target: EventTarget & HTMLInputElementvalue })}HTMLInputElement.value: stringThe
valueproperty of the HTMLInputElement interface represents the current value of the element as a string./></Field.import FieldRoot>const Root: React.ForwardRefExoticComponent<Omit<FieldRootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {validationValence?: Field.Valence;layout?: "stack" | "row" | "inline";level?: Layout.Level;span?: Layout.Span;tone?: "muted";} & React.RefAttributes<HTMLDivElement>>export RootA part, not a container (decision 13): a flex stack in the content track with the label above its control.
<Field.import FieldRoot>const Root: React.ForwardRefExoticComponent<Omit<FieldRootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {validationValence?: Field.Valence;layout?: "stack" | "row" | "inline";level?: Layout.Level;span?: Layout.Span;tone?: "muted";} & React.RefAttributes<HTMLDivElement>>export RootA part, not a container (decision 13): a flex stack in the content track with the label above its control.
<Field.import FieldLabel>Role</const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export LabelNames the control; while the root is
requiredit ends with the required indicator, unless aRequiredIndicatoramong its children places the mark itself.Field.import FieldLabel>const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export LabelNames the control; while the root is
requiredit ends with the required indicator, unless aRequiredIndicatoramong its children places the mark itself.<Select.import SelectRootconst Root: React.ForwardRefExoticComponent<Omit<Omit<SelectRootProps<Select.Option>, "collection" | "positioning">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: Select.Option[];positioning?: Select.Positioning;} & React.RefAttributes<HTMLDivElement>>export RootArk select over a flat option list (grouped in the popup with
ItemGroup); the root takes no box so its trigger is laid out as the parent's child.multiplekeeps the popup open while choosing. The popup is at least as wide as the trigger and grows to fit its widest option, up to the viewport's width.items={items: Select.Option[]ROLES}const ROLES: Select.Option[]value={[value?: string[] | undefinedThe controlled keys of the selected items
draft.const draft: Contactrole]}role: stringonValueChange={({onValueChange?: ((details: ValueChangeDetails<Select.Option>) => void) | undefinedThe callback fired when the selected item changes.
value: [ValueChangeDetails<SelectOption>.value: string[]role] }) =>role: stringsetDraft({ ...const setDraft: (value: React.SetStateAction<Contact>) => voiddraft,const draft: Contactrole })}role: string><Select.import SelectTrigger />const Trigger: React.ForwardRefExoticComponent<Omit<Omit<SelectTriggerProps, "children">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {placeholder?: string;loading?: boolean;fixed?: boolean;tag?: boolean;icon?: string;} & React.RefAttributes<HTMLButtonElement>>export TriggerShows the chosen option (its icon when exactly one is chosen;
multiplelists the labels) and a caret.<Select.import SelectContent>const Content: React.ForwardRefExoticComponent<Omit<SelectContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled listbox at
level='popup', scrolling in a thin ScrollArea whose viewport is the listbox itself.{ROLES.const ROLES: Select.Option[]map((Array<SelectOption>.map<React.JSX.Element>(callbackfn: (value: Select.Option, index: number, array: Select.Option[]) => 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: Select.Option<Select.import SelectItemconst Item: React.ForwardRefExoticComponent<Omit<Omit<SelectItemProps, "children" | "item">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {item: Select.Option;children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export ItemA block-tall row: without children, the option's icon, its label and the check shown while it is selected.
key={React.Attributes.key?: React.Key | null | undefineditem.item: Select.Optionvalue}value: stringitem={item: Select.Optionitem} />item: Select.Option))}</Select.import SelectContent>const Content: React.ForwardRefExoticComponent<Omit<SelectContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled listbox at
level='popup', scrolling in a thin ScrollArea whose viewport is the listbox itself.</Select.import SelectRoot>const Root: React.ForwardRefExoticComponent<Omit<Omit<SelectRootProps<Select.Option>, "collection" | "positioning">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {items: Select.Option[];positioning?: Select.Positioning;} & React.RefAttributes<HTMLDivElement>>export RootArk select over a flat option list (grouped in the popup with
ItemGroup); the root takes no box so its trigger is laid out as the parent's child.multiplekeeps the popup open while choosing. The popup is at least as wide as the trigger and grows to fit its widest option, up to the viewport's width.</Field.import FieldRoot>const Root: React.ForwardRefExoticComponent<Omit<FieldRootProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {validationValence?: Field.Valence;layout?: "stack" | "row" | "inline";level?: Layout.Level;span?: Layout.Span;tone?: "muted";} & React.RefAttributes<HTMLDivElement>>export RootA part, not a container (decision 13): a flex stack in the content track with the label above its control.
<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>).gap='sm'gap?: Layout.Gap | undefinedjustify='end'>justify?: Layout.Justify | undefined<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Rootdisabled={!disabled?: boolean | undefinedchanged}const changed: booleanonClick={() =>onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedsetDraft(const setDraft: (value: React.SetStateAction<Contact>) => voidcontact)}>contact: ContactRevert</Button.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Root<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='primary'variant?: Button.Variant | undefineddisabled={!disabled?: boolean | undefinedchanged ||const changed: booleandraft.const draft: Contactname.name: stringtrim() === ''}String.trim(): stringRemoves the leading and trailing white space and line terminator characters from a string.
onClick={() =>onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonSave(onSave: (contact: Contact) => voiddraft)}>const draft: ContactSave</Button.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Root</Layout.import LayoutFlex>const Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>).</Layout.import LayoutFlex>const Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>).);};gap='form'is the spacing the theme uses between fields. ASelect’s value is a list, because a select can allow several choices, soonValueChangetakes its first item. -
Put the editor in the detail column. The screen now holds the contacts with
setContacts, and Save replaces the one that changed. Addsrc/inputs/ContactsScreen.tsx, which reusesContactListfrom the last page, and render thisContactsScreenfromsrc/main.tsx: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 Layoutimport * asPanel from '@dxos/react-ui/Panel';import Panelimport * asScrollArea from '@dxos/react-ui/ScrollArea';import ScrollAreaimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbarimport { typeContact,type Contact = {id: string;name: string;email: string;role: string;}CONTACTS } from '../contacts.ts';const CONTACTS: Contact[]import {ContactList } from '../layout/ContactsScreen.tsx';const ContactList: ({ contacts, selected, onSelect }: ContactListProps) => React.JSX.ElementOne row per contact; the list scrolls inside its own viewport.
import {ContactEditor } from './ContactEditor.tsx';const ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.export constContactsScreen = () => {const ContactsScreen: () => React.JSX.Elementconst [contacts,const contacts: Contact[]setContacts] =const setContacts: React.Dispatch<React.SetStateAction<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: stringconsthandleSave = (const handleSave: (next: Contact) => voidnext:next: ContactContact) =>type Contact = {id: string;name: string;email: string;role: string;}setContacts((const setContacts: (value: React.SetStateAction<Contact[]>) => voidcontacts) =>contacts: Contact[]contacts.contacts: Contact[]map((Array<Contact>.map<Contact>(callbackfn: (value: Contact, index: number, array: Contact[]) => Contact, thisArg?: any): Contact[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
contact) => (contact: Contactcontact.contact: Contactid ===id: stringnext.next: Contactid ?id: stringnext :next: Contactcontact)));contact: Contactreturn (<Panel.import PanelRoot>const Root: React.ForwardRefExoticComponent<Omit<Panel.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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?: "gap" | "line" | 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>><ScrollArea.import ScrollAreaRoot>const Root: React.ForwardRefExoticComponent<Omit<ScrollArea.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export ViewportThe scrolling element; under
asChildit is the child (e.g. a Container) itself.classNames='p-4'>classNames?: ClassNameValue{contact && <const contact: Contact | undefinedContactEditorconst ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.key={React.Attributes.key?: React.Key | null | undefinedcontact.const contact: Contactid}id: stringcontact={contact: Contactcontact}const contact: ContactonSave={onSave: (contact: Contact) => voidhandleSave} />}const handleSave: (next: Contact) => void</ScrollArea.import ScrollAreaViewport>const Viewport: React.ForwardRefExoticComponent<Omit<ScrollArea.ViewportProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export RootNon-scrolling frame: hosts the overlay thumbs and is the query container for its content.
</Layout.import LayoutGrid>const Grid: React.ForwardRefExoticComponent<Omit<Layout.GridProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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.);};key={contact.id}gives each contact its own editor. Without it, the editor would keep the last contact’s draft when we choose another.
Try it
Section titled “Try it”Change Ada’s name, and Save and Revert become active. Save, and the list shows the new name.
What you can do now
Section titled “What you can do now”You can build a form from fields, inputs, a select and buttons, and keep its state in React. Next, Overlays moves the editor into a dialog.