Overlays
By the end of this page the detail column shows the contact’s fields as text again. The toolbar has Edit, which opens the editor in a dialog, and Delete, which asks first. A toast says when a contact is saved.
Background
Section titled “Background”Our screen needs four things to appear above the page: an editor, a question, a hint and a notice. Which component draws each one? An overlay is a component that TILE draws above the page, and we use four of them:
- A
Dialogis modal. The page behind it is inert until it closes. Use it for a task the user finishes or cancels before going on, as step 1 does for the editor. - A
Popoveropens beside its trigger and closes when the user clicks elsewhere. Use it for short content that belongs to one control, as step 2 does for the delete question. - A
Tooltipshows a short hint on hover or focus. Use it to name a control or explain a value, as step 3 does for the role. It never takes focus, so put nothing in it that the user has to click. - A
Toastreports something that happened and goes away by itself. Use it when the user does not have to answer, as step 4 does for a save.
A dialog, a popover and a tooltip each have a Trigger that opens it and a Content that holds it. asChild on a
trigger makes our button the trigger. Without it, the trigger wraps our button in a button of its own.
A toast has neither. It is open while open on its Toast.Root is true.
Dialog, Popover, Tooltip and Toast list the parts of each. TILE has more overlays than these four, such as Menu for a list of actions and AlertDialog for a question the user must answer.
-
Move the editor into a dialog. The dialog is controlled, so it can close itself when the editor saves. The trigger is an icon-only button, which shows its label as a tooltip on its own. Add
src/overlays/ContactsScreen.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 * asDialog from '@dxos/react-ui/Dialog';import Dialog8 collapsed linesimport * asLayout from '@dxos/react-ui/Layout';import Layoutimport * asPanel from '@dxos/react-ui/Panel';import Panelimport * asPopover from '@dxos/react-ui/Popover';import Popoverimport * asToast from '@dxos/react-ui/Toast';import Toastimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbarimport * asTooltip from '@dxos/react-ui/Tooltip';import Tooltipimport * 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[]import {ContactEditor } from '../inputs/ContactEditor.tsx';const ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.2 collapsed linesimport {ContactList } from '../layout/ContactsScreen.tsx';const ContactList: ({ contacts, selected, onSelect }: ContactListProps) => React.JSX.ElementOne row per contact; the list scrolls inside its own viewport.
typeEditDialogProps = {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}label: string;label: stringcontact: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;}};/** The editor from the last page, in a dialog that closes on Save. */export constEditDialog = ({const EditDialog: ({ label, contact, onSave }: EditDialogProps) => React.JSX.ElementThe editor from the last page, in a dialog that closes on Save.
label,label: stringcontact,contact: ContactonSave }:onSave: (contact: Contact) => voidEditDialogProps) => {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}const [open,const open: booleansetOpen] =const setOpen: React.Dispatch<React.SetStateAction<boolean>>useState(false);useState<boolean>(initialState: boolean | (() => boolean)): [boolean, React.Dispatch<React.SetStateAction<boolean>>] (+1 overload)Returns a stateful value, and a function to update it.
return (<Dialog.import DialogRootfunction Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Rootopen={open?: boolean | undefinedThe controlled open state of the dialog
open}const open: booleanonOpenChange={({onOpenChange?: ((details: OpenChangeDetails) => void) | undefinedFunction to call when the dialog's open state changes
open }) =>open: booleansetOpen(const setOpen: (value: React.SetStateAction<boolean>) => voidopen)}>open: boolean<Dialog.import DialogTriggerconst Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.asChild>PolymorphicProps.asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rooticon='ph--pencil-simple--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.label}label: stringiconOnly />iconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
</Dialog.import DialogTrigger>const Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.<Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.<Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogTitle>{const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Titlecontact.contact: Contactname}</name: stringDialog.import DialogTitle>const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Title<Dialog.import DialogCloseTrigger />const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger</Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).<ContactEditorconst ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.contact={contact: Contactcontact}contact: ContactonSave={(onSave: (contact: Contact) => voidnext) => {next: ContactonSave(onSave: (contact: Contact) => voidnext);next: ContactsetOpen(false);const setOpen: (value: React.SetStateAction<boolean>) => void}}/></Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).</Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.</Dialog.import DialogRoot>function Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Root);};onSavesaves the contact, then callssetOpen(false). A dialog that holds its own state would stay open after Save, because the editor’s Save button is not aDialog.CloseTrigger. -
Ask before deleting. A popover is lighter than a dialog for a yes-or-no question.
Popover.CloseTriggercloses it without deleting:import * asButton from '@dxos/react-ui/Button';import Button1 collapsed lineimport * asDialog from '@dxos/react-ui/Dialog';import Dialogimport * asLayout from '@dxos/react-ui/Layout';import Layout1 collapsed lineimport * asPanel from '@dxos/react-ui/Panel';import Panelimport * asPopover from '@dxos/react-ui/Popover';import Popover42 collapsed linesimport * asToast from '@dxos/react-ui/Toast';import Toastimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbarimport * asTooltip from '@dxos/react-ui/Tooltip';import Tooltipimport * 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[]import {ContactEditor } from '../inputs/ContactEditor.tsx';const ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.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.
typeEditDialogProps = {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}label: string;label: stringcontact: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;}};/** The editor from the last page, in a dialog that closes on Save. */export constEditDialog = ({const EditDialog: ({ label, contact, onSave }: EditDialogProps) => React.JSX.ElementThe editor from the last page, in a dialog that closes on Save.
label,label: stringcontact,contact: ContactonSave }:onSave: (contact: Contact) => voidEditDialogProps) => {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}const [open,const open: booleansetOpen] =const setOpen: React.Dispatch<React.SetStateAction<boolean>>useState(false);useState<boolean>(initialState: boolean | (() => boolean)): [boolean, React.Dispatch<React.SetStateAction<boolean>>] (+1 overload)Returns a stateful value, and a function to update it.
return (<Dialog.import DialogRootfunction Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Rootopen={open?: boolean | undefinedThe controlled open state of the dialog
open}const open: booleanonOpenChange={({onOpenChange?: ((details: OpenChangeDetails) => void) | undefinedFunction to call when the dialog's open state changes
open }) =>open: booleansetOpen(const setOpen: (value: React.SetStateAction<boolean>) => voidopen)}>open: boolean<Dialog.import DialogTriggerconst Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.asChild>PolymorphicProps.asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rooticon='ph--pencil-simple--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.label}label: stringiconOnly />iconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
</Dialog.import DialogTrigger>const Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.<Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.<Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogTitle>{const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Titlecontact.contact: Contactname}</name: stringDialog.import DialogTitle>const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Title<Dialog.import DialogCloseTrigger />const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger</Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).<ContactEditorconst ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.contact={contact: Contactcontact}contact: ContactonSave={(onSave: (contact: Contact) => voidnext) => {next: ContactonSave(onSave: (contact: Contact) => voidnext);next: ContactsetOpen(false);const setOpen: (value: React.SetStateAction<boolean>) => void}}/></Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).</Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.</Dialog.import DialogRoot>function Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Root);};/** Asks before it deletes, in a popover beside the button. */typeDeletePopoverProps = {type DeletePopoverProps = {label: string;onDelete: () => void;}Asks before it deletes, in a popover beside the button.
label: string;label: stringonDelete: () => void;onDelete: () => void};export constDeletePopover = ({const DeletePopover: ({ label, onDelete }: DeletePopoverProps) => React.JSX.Elementlabel,label: stringonDelete }:onDelete: () => voidDeletePopoverProps) => (type DeletePopoverProps = {label: string;onDelete: () => void;}Asks before it deletes, in a popover beside the button.
<Popover.import PopoverRoot>function Root({ lazyMount, unmountOnExit, positioning, ...props }: Popover.RootProps): React.JSX.Elementexport Root<Popover.import PopoverTriggerconst Trigger: React.ForwardRefExoticComponent<PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the popover from aButton.asChild>PolymorphicProps.asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='destructive'variant?: Button.Variant | undefinedicon='ph--trash--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.label}label: stringiconOnly />iconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
</Popover.import PopoverTrigger>const Trigger: React.ForwardRefExoticComponent<PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the popover from aButton.<Popover.import PopoverContent>const Content: React.ForwardRefExoticComponent<Omit<PopoverContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled panel at
level='popup', padded by the size's gap, with an arrow unlessarrow={false}.<Popover.import PopoverHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Popover.import PopoverTitle>Delete this contact?</const Title: React.ForwardRefExoticComponent<Omit<PopoverTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLHeadingElement>>export TitlePopover.import PopoverTitle>const Title: React.ForwardRefExoticComponent<Omit<PopoverTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLHeadingElement>>export Title</Popover.import PopoverHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>).gap='sm'gap?: Layout.Gap | undefinedjustify='end'>justify?: Layout.Justify | undefined<Popover.import PopoverCloseTriggerconst CloseTrigger: React.ForwardRefExoticComponent<Omit<PopoverCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTriggerasChild>asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRoot>Keep</const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export RootButton.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root</Popover.import PopoverCloseTrigger>const CloseTrigger: React.ForwardRefExoticComponent<Omit<PopoverCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='destructive'variant?: Button.Variant | undefinedonClick={onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonDelete}>onDelete: () => voidDelete</Button.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & 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>, "role" | "style" | "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>).</Popover.import PopoverContent>const Content: React.ForwardRefExoticComponent<Omit<PopoverContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled panel at
level='popup', padded by the size's gap, with an arrow unlessarrow={false}.</Popover.import PopoverRoot>function Root({ lazyMount, unmountOnExit, positioning, ...props }: Popover.RootProps): React.JSX.Elementexport Root);The destructive
Button.RootcallsonDeleteand closes nothing itself. Step 4 clears the selection on a delete, and the screen then stops renderingDeletePopover. -
Explain the role. A tooltip can wrap any element, not only a button:
import * asTooltip from '@dxos/react-ui/Tooltip';import Tooltipimport * asTypography from '@dxos/react-ui/Typography';import Typography65 collapsed linesimport { typeContact,type Contact = {id: string;name: string;email: string;role: string;}CONTACTS } from '../contacts.ts';const CONTACTS: Contact[]import {ContactEditor } from '../inputs/ContactEditor.tsx';const ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.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.
typeEditDialogProps = {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}label: string;label: stringcontact: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;}};/** The editor from the last page, in a dialog that closes on Save. */export constEditDialog = ({const EditDialog: ({ label, contact, onSave }: EditDialogProps) => React.JSX.ElementThe editor from the last page, in a dialog that closes on Save.
label,label: stringcontact,contact: ContactonSave }:onSave: (contact: Contact) => voidEditDialogProps) => {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}const [open,const open: booleansetOpen] =const setOpen: React.Dispatch<React.SetStateAction<boolean>>useState(false);useState<boolean>(initialState: boolean | (() => boolean)): [boolean, React.Dispatch<React.SetStateAction<boolean>>] (+1 overload)Returns a stateful value, and a function to update it.
return (<Dialog.import DialogRootfunction Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Rootopen={open?: boolean | undefinedThe controlled open state of the dialog
open}const open: booleanonOpenChange={({onOpenChange?: ((details: OpenChangeDetails) => void) | undefinedFunction to call when the dialog's open state changes
open }) =>open: booleansetOpen(const setOpen: (value: React.SetStateAction<boolean>) => voidopen)}>open: boolean<Dialog.import DialogTriggerconst Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.asChild>PolymorphicProps.asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rooticon='ph--pencil-simple--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.label}label: stringiconOnly />iconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
</Dialog.import DialogTrigger>const Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.<Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.<Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogTitle>{const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Titlecontact.contact: Contactname}</name: stringDialog.import DialogTitle>const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Title<Dialog.import DialogCloseTrigger />const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger</Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).<ContactEditorconst ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.contact={contact: Contactcontact}contact: ContactonSave={(onSave: (contact: Contact) => voidnext) => {next: ContactonSave(onSave: (contact: Contact) => voidnext);next: ContactsetOpen(false);const setOpen: (value: React.SetStateAction<boolean>) => void}}/></Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).</Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.</Dialog.import DialogRoot>function Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Root);};/** Asks before it deletes, in a popover beside the button. */typeDeletePopoverProps = {type DeletePopoverProps = {label: string;onDelete: () => void;}Asks before it deletes, in a popover beside the button.
label: string;label: stringonDelete: () => void;onDelete: () => void};export constDeletePopover = ({const DeletePopover: ({ label, onDelete }: DeletePopoverProps) => React.JSX.Elementlabel,label: stringonDelete }:onDelete: () => voidDeletePopoverProps) => (type DeletePopoverProps = {label: string;onDelete: () => void;}Asks before it deletes, in a popover beside the button.
<Popover.import PopoverRoot>function Root({ lazyMount, unmountOnExit, positioning, ...props }: Popover.RootProps): React.JSX.Elementexport Root<Popover.import PopoverTriggerconst Trigger: React.ForwardRefExoticComponent<PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the popover from aButton.asChild>PolymorphicProps.asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='destructive'variant?: Button.Variant | undefinedicon='ph--trash--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.label}label: stringiconOnly />iconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
</Popover.import PopoverTrigger>const Trigger: React.ForwardRefExoticComponent<PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the popover from aButton.<Popover.import PopoverContent>const Content: React.ForwardRefExoticComponent<Omit<PopoverContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled panel at
level='popup', padded by the size's gap, with an arrow unlessarrow={false}.<Popover.import PopoverHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Popover.import PopoverTitle>Delete this contact?</const Title: React.ForwardRefExoticComponent<Omit<PopoverTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLHeadingElement>>export TitlePopover.import PopoverTitle>const Title: React.ForwardRefExoticComponent<Omit<PopoverTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLHeadingElement>>export Title</Popover.import PopoverHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>).gap='sm'gap?: Layout.Gap | undefinedjustify='end'>justify?: Layout.Justify | undefined<Popover.import PopoverCloseTriggerconst CloseTrigger: React.ForwardRefExoticComponent<Omit<PopoverCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTriggerasChild>asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRoot>Keep</const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export RootButton.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root</Popover.import PopoverCloseTrigger>const CloseTrigger: React.ForwardRefExoticComponent<Omit<PopoverCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='destructive'variant?: Button.Variant | undefinedonClick={onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonDelete}>onDelete: () => voidDelete</Button.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & 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>, "role" | "style" | "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>).</Popover.import PopoverContent>const Content: React.ForwardRefExoticComponent<Omit<PopoverContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled panel at
level='popup', padded by the size's gap, with an arrow unlessarrow={false}.</Popover.import PopoverRoot>function Root({ lazyMount, unmountOnExit, positioning, ...props }: Popover.RootProps): React.JSX.Elementexport Root);constROLE_HELP:const ROLE_HELP: Record<string, string>Record<string, string> = {type Record<K extends keyof any, T> = { [P in K]: T; }Construct a type with a set of properties K of type T
viewer: 'Can read the contact book',viewer: stringeditor: 'Can change contacts',editor: stringadmin: 'Can change contacts and who has access',admin: string};/** The role, with what it allows in a tooltip. */export constRole = ({const Role: ({ role }: {role: string;}) => React.JSX.ElementThe role, with what it allows in a tooltip.
role }: {role: stringrole: string }) => (role: string<Tooltip.import TooltipRoot>function Root({ openDelay, lazyMount, unmountOnExit, positioning, ...props }: Tooltip.RootProps): React.JSX.Elementexport Root<Tooltip.import TooltipTriggerconst Trigger: React.ForwardRefExoticComponent<Omit<TooltipTriggerProps, "content"> & {content?: React.ReactNode;side?: Tooltip.Side;} & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto describe aButton. Opens on hover after the Root's delay and on keyboard focus only; the delay runs here because zag skips it while any tooltip is marked open, so a click would flash one (DESIGN.md follow-up 33). Withcontentit needs no Root or Content around it.asChild>asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
{/* Focusable, so a keyboard user can open the tooltip too. */}<spanReact.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>tabIndex={0}>React.HTMLAttributes<HTMLSpanElement>.tabIndex?: number | undefined<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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.role}</role: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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.</span>React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement></Tooltip.import TooltipTrigger>const Trigger: React.ForwardRefExoticComponent<Omit<TooltipTriggerProps, "content"> & {content?: React.ReactNode;side?: Tooltip.Side;} & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto describe aButton. Opens on hover after the Root's delay and on keyboard focus only; the delay runs here because zag skips it while any tooltip is marked open, so a click would flash one (DESIGN.md follow-up 33). Withcontentit needs no Root or Content around it.<Tooltip.import TooltipContent>{const Content: React.ForwardRefExoticComponent<Omit<TooltipContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled text on the inverted surface (as the current Tooltip; no
data-surface, whose popup fill it would fight), capped at 20rem wide, with an arrow unlessarrow={false}.ROLE_HELP[const ROLE_HELP: Record<string, string>role]}</role: stringTooltip.import TooltipContent>const Content: React.ForwardRefExoticComponent<Omit<TooltipContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled text on the inverted surface (as the current Tooltip; no
data-surface, whose popup fill it would fight), capped at 20rem wide, with an arrow unlessarrow={false}.</Tooltip.import TooltipRoot>function Root({ openDelay, lazyMount, unmountOnExit, positioning, ...props }: Tooltip.RootProps): React.JSX.Elementexport Root);ROLE_HELPkeeps its strings in the component for now. The next page moves them into a translation resource. -
Put them on the screen. Edit and Delete go in the toolbar, after the gap that pushes them to the end.
Toast.Providerwraps the screen, andToast.Toasteris where toasts appear. The toast is open whilesavedholds a name.Add the screen to the same file, and render it from
src/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.
3 collapsed linesimport * asButton from '@dxos/react-ui/Button';import Buttonimport * asDialog from '@dxos/react-ui/Dialog';import Dialogimport * asLayout from '@dxos/react-ui/Layout';import Layoutimport * asPanel from '@dxos/react-ui/Panel';import Panel1 collapsed lineimport * asPopover from '@dxos/react-ui/Popover';import Popoverimport * asToast from '@dxos/react-ui/Toast';import Toastimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbar1 collapsed lineimport * asTooltip from '@dxos/react-ui/Tooltip';import Tooltipimport * 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[]1 collapsed lineimport {ContactEditor } from '../inputs/ContactEditor.tsx';const ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.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.
80 collapsed linestypeEditDialogProps = {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}label: string;label: stringcontact: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;}};/** The editor from the last page, in a dialog that closes on Save. */export constEditDialog = ({const EditDialog: ({ label, contact, onSave }: EditDialogProps) => React.JSX.ElementThe editor from the last page, in a dialog that closes on Save.
label,label: stringcontact,contact: ContactonSave }:onSave: (contact: Contact) => voidEditDialogProps) => {type EditDialogProps = {label: string;contact: Contact;onSave: (contact: Contact) => void;}const [open,const open: booleansetOpen] =const setOpen: React.Dispatch<React.SetStateAction<boolean>>useState(false);useState<boolean>(initialState: boolean | (() => boolean)): [boolean, React.Dispatch<React.SetStateAction<boolean>>] (+1 overload)Returns a stateful value, and a function to update it.
return (<Dialog.import DialogRootfunction Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Rootopen={open?: boolean | undefinedThe controlled open state of the dialog
open}const open: booleanonOpenChange={({onOpenChange?: ((details: OpenChangeDetails) => void) | undefinedFunction to call when the dialog's open state changes
open }) =>open: booleansetOpen(const setOpen: (value: React.SetStateAction<boolean>) => voidopen)}>open: boolean<Dialog.import DialogTriggerconst Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.asChild>PolymorphicProps.asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rooticon='ph--pencil-simple--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.label}label: stringiconOnly />iconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
</Dialog.import DialogTrigger>const Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the dialog from aButton.<Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.<Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogTitle>{const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Titlecontact.contact: Contactname}</name: stringDialog.import DialogTitle>const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Title<Dialog.import DialogCloseTrigger />const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger</Dialog.import DialogHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).<ContactEditorconst ContactEditor: ({ contact, onSave }: ContactEditorProps) => React.JSX.ElementEdits a copy of
contact; nothing changes until Save.contact={contact: Contactcontact}contact: ContactonSave={(onSave: (contact: Contact) => voidnext) => {next: ContactonSave(onSave: (contact: Contact) => voidnext);next: ContactsetOpen(false);const setOpen: (value: React.SetStateAction<boolean>) => void}}/></Dialog.import DialogBody>const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollAreaRootProps, "mode" | "native" | "width">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & {align?: "start" | "center";children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export BodyComposed scroll (decision 5): a
gutter='md'Container as the viewport, so the thumb sits in the end gutter;gapspaces its rows, since they are the Container's own items. The element carries ScrollArea'sdata-scope, since parts cannot rescope a composed child (finding 10).</Dialog.import DialogContent>const Content: React.ForwardRefExoticComponent<Omit<DialogContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;container?: React.RefObject<HTMLElement | null>;placement?: Dialog.Placement;scrim?: boolean;closeOnInteractOutside?: boolean;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled surface at
level='raised'over a scrim, centred in the viewport: a column of Header, Body and Footer.</Dialog.import DialogRoot>function Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Elementexport Root);};/** Asks before it deletes, in a popover beside the button. */typeDeletePopoverProps = {type DeletePopoverProps = {label: string;onDelete: () => void;}Asks before it deletes, in a popover beside the button.
label: string;label: stringonDelete: () => void;onDelete: () => void};export constDeletePopover = ({const DeletePopover: ({ label, onDelete }: DeletePopoverProps) => React.JSX.Elementlabel,label: stringonDelete }:onDelete: () => voidDeletePopoverProps) => (type DeletePopoverProps = {label: string;onDelete: () => void;}Asks before it deletes, in a popover beside the button.
<Popover.import PopoverRoot>function Root({ lazyMount, unmountOnExit, positioning, ...props }: Popover.RootProps): React.JSX.Elementexport Root<Popover.import PopoverTriggerconst Trigger: React.ForwardRefExoticComponent<PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the popover from aButton.asChild>PolymorphicProps.asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='destructive'variant?: Button.Variant | undefinedicon='ph--trash--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.label}label: stringiconOnly />iconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
</Popover.import PopoverTrigger>const Trigger: React.ForwardRefExoticComponent<PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto open the popover from aButton.<Popover.import PopoverContent>const Content: React.ForwardRefExoticComponent<Omit<PopoverContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled panel at
level='popup', padded by the size's gap, with an arrow unlessarrow={false}.<Popover.import PopoverHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Popover.import PopoverTitle>Delete this contact?</const Title: React.ForwardRefExoticComponent<Omit<PopoverTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLHeadingElement>>export TitlePopover.import PopoverTitle>const Title: React.ForwardRefExoticComponent<Omit<PopoverTitleProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLHeadingElement>>export Title</Popover.import PopoverHeader>const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export HeaderA block row holding the Title and an optional trailing CloseTrigger.
<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>).gap='sm'gap?: Layout.Gap | undefinedjustify='end'>justify?: Layout.Justify | undefined<Popover.import PopoverCloseTriggerconst CloseTrigger: React.ForwardRefExoticComponent<Omit<PopoverCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTriggerasChild>asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
<Button.import ButtonRoot>Keep</const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export RootButton.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root</Popover.import PopoverCloseTrigger>const CloseTrigger: React.ForwardRefExoticComponent<Omit<PopoverCloseTriggerProps, "children"> & {children?: React.ReactNode;icon?: string;label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='destructive'variant?: Button.Variant | undefinedonClick={onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedonDelete}>onDelete: () => voidDelete</Button.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "children"> & 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>, "role" | "style" | "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>).</Popover.import PopoverContent>const Content: React.ForwardRefExoticComponent<Omit<PopoverContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled panel at
level='popup', padded by the size's gap, with an arrow unlessarrow={false}.</Popover.import PopoverRoot>function Root({ lazyMount, unmountOnExit, positioning, ...props }: Popover.RootProps): React.JSX.Elementexport Root);constROLE_HELP:const ROLE_HELP: Record<string, string>Record<string, string> = {type Record<K extends keyof any, T> = { [P in K]: T; }Construct a type with a set of properties K of type T
viewer: 'Can read the contact book',viewer: stringeditor: 'Can change contacts',editor: stringadmin: 'Can change contacts and who has access',admin: string};/** The role, with what it allows in a tooltip. */export constRole = ({const Role: ({ role }: {role: string;}) => React.JSX.ElementThe role, with what it allows in a tooltip.
role }: {role: stringrole: string }) => (role: string<Tooltip.import TooltipRoot>function Root({ openDelay, lazyMount, unmountOnExit, positioning, ...props }: Tooltip.RootProps): React.JSX.Elementexport Root<Tooltip.import TooltipTriggerconst Trigger: React.ForwardRefExoticComponent<Omit<TooltipTriggerProps, "content"> & {content?: React.ReactNode;side?: Tooltip.Side;} & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto describe aButton. Opens on hover after the Root's delay and on keyboard focus only; the delay runs here because zag skips it while any tooltip is marked open, so a click would flash one (DESIGN.md follow-up 33). Withcontentit needs no Root or Content around it.asChild>asChild?: boolean | undefinedUse the provided child element as the default rendered element, combining their props and behavior.
{/* Focusable, so a keyboard user can open the tooltip too. */}<spanReact.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>tabIndex={0}>React.HTMLAttributes<HTMLSpanElement>.tabIndex?: number | undefined<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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.role}</role: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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.</span>React.JSX.IntrinsicElements.span: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement></Tooltip.import TooltipTrigger>const Trigger: React.ForwardRefExoticComponent<Omit<TooltipTriggerProps, "content"> & {content?: React.ReactNode;side?: Tooltip.Side;} & React.RefAttributes<HTMLButtonElement>>export TriggerUse
asChildto describe aButton. Opens on hover after the Root's delay and on keyboard focus only; the delay runs here because zag skips it while any tooltip is marked open, so a click would flash one (DESIGN.md follow-up 33). Withcontentit needs no Root or Content around it.<Tooltip.import TooltipContent>{const Content: React.ForwardRefExoticComponent<Omit<TooltipContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled text on the inverted surface (as the current Tooltip; no
data-surface, whose popup fill it would fight), capped at 20rem wide, with an arrow unlessarrow={false}.ROLE_HELP[const ROLE_HELP: Record<string, string>role]}</role: stringTooltip.import TooltipContent>const Content: React.ForwardRefExoticComponent<Omit<TooltipContentProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & {size?: Size;arrow?: boolean;container?: React.RefObject<HTMLElement | null>;} & React.RefAttributes<HTMLDivElement>>export ContentPortalled text on the inverted surface (as the current Tooltip; no
data-surface, whose popup fill it would fight), capped at 20rem wide, with an arrow unlessarrow={false}.</Tooltip.import TooltipRoot>function Root({ openDelay, lazyMount, unmountOnExit, positioning, ...props }: Tooltip.RootProps): React.JSX.Elementexport Root);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: string | undefinedsetSelected] =const setSelected: React.Dispatch<React.SetStateAction<string | undefined>>useState<string | undefined>(useState<string | undefined>(initialState: string | (() => string | undefined) | undefined): [string | undefined, React.Dispatch<React.SetStateAction<string | undefined>>] (+1 overload)Returns a stateful value, and a function to update it.
contacts[0].const contacts: Contact[]id);id: stringconst [saved,const saved: string | undefinedsetSaved] =const setSaved: React.Dispatch<React.SetStateAction<string | undefined>>useState<string>();useState<string>(): [string | undefined, React.Dispatch<React.SetStateAction<string | undefined>>] (+1 overload)Returns a stateful value, and a function to update it.
constcontact =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: string | undefinedconsthandleSave = (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: ContactsetSaved(const setSaved: (value: React.SetStateAction<string | undefined>) => voidnext.next: Contactname);name: string};consthandleDelete = (const handleDelete: (id: string) => voidid: string) => {id: stringsetContacts((const setContacts: (value: React.SetStateAction<Contact[]>) => voidcontacts) =>contacts: Contact[]contacts.contacts: Contact[]filter((Array<Contact>.filter(predicate: (value: Contact, index: number, array: Contact[]) => unknown, thisArg?: any): Contact[] (+1 overload)Returns the elements of an array that meet the condition specified in a callback function.
contact) =>contact: Contactcontact.contact: Contactid !==id: stringid));id: stringsetSelected(const setSelected: (value: React.SetStateAction<string | undefined>) => voidundefined);var undefined};return (<Toast.import ToastProvider>function Provider({ duration, overlap, children }: Toast.ProviderProps): React.JSX.Elementexport Provider<Panel.import PanelRoot>const Root: React.ForwardRefExoticComponent<Omit<Panel.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>, "role" | "style" | "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>, "role" | "style" | "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>, "role" | "style" | "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>, "role" | "style" | "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>, "role" | "style" | "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.{contact && <const contact: Contact | undefinedEditDialogconst EditDialog: ({ label, contact, onSave }: EditDialogProps) => React.JSX.ElementThe editor from the last page, in a dialog that closes on Save.
label='Edit'label: stringcontact={contact: Contactcontact}const contact: ContactonSave={onSave: (contact: Contact) => voidhandleSave} />}const handleSave: (next: Contact) => void{contact && <const contact: Contact | undefinedDeletePopoverconst DeletePopover: ({ label, onDelete }: DeletePopoverProps) => React.JSX.Elementlabel='Delete'label: stringonDelete={() =>onDelete: () => voidhandleDelete(const handleDelete: (id: string) => voidcontact.const contact: Contactid)} />}id: string</Toolbar.import ToolbarRoot>const Root: React.ForwardRefExoticComponent<Omit<Toolbar.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>, "role" | "style" | "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>, "role" | "style" | "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>, "role" | "style" | "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: string | undefinedonSelect={onSelect: (id: string) => voidsetSelected} />const setSelected: React.Dispatch<React.SetStateAction<string | undefined>>{contact && (const contact: Contact | undefined<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>, "role" | "style" | "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.const 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>, "role" | "style" | "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>, "role" | "style" | "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.const 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>, "role" | "style" | "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.<Roleconst Role: ({ role }: {role: string;}) => React.JSX.ElementThe role, with what it allows in a tooltip.
role={role: stringcontact.const contact: Contactrole} />role: string</Layout.import LayoutFlex>const Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>).)}</Layout.import LayoutGrid>const Grid: React.ForwardRefExoticComponent<Omit<Layout.GridProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "role" | "style" | "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>, "role" | "style" | "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>, "role" | "style" | "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.<Toast.import ToastRootconst Root: React.ForwardRefExoticComponent<Omit<Toast.RootProps, "ref"> & React.RefAttributes<HTMLDivElement>>export RootDeclares a toast. Renders nothing where it stands: the content is registered for the toaster, and
openis mirrored into the store, which reports a timeout or a close back asonOpenChange.open={open?: boolean | undefinedsaved !==const saved: string | undefinedundefined}var undefinedonOpenChange={(onOpenChange?: ((open: boolean) => void) | undefinedopen) => !open: booleanopen &&open: booleansetSaved(const setSaved: (value: React.SetStateAction<string | undefined>) => voidundefined)}>var undefined<Toast.import ToastHeaderconst Header: React.ForwardRefExoticComponent<Omit<Toast.HeaderProps, "ref"> & React.RefAttributes<HTMLDivElement>>export HeaderA block row: an optional icon, the Title (children) and a close button.
icon='ph--check-circle--regular'>Contact saved</icon?: string | undefinedToast.import ToastHeader>const Header: React.ForwardRefExoticComponent<Omit<Toast.HeaderProps, "ref"> & React.RefAttributes<HTMLDivElement>>export HeaderA block row: an optional icon, the Title (children) and a close button.
<Toast.import ToastDescription>{const Description: React.ForwardRefExoticComponent<Omit<Toast.DescriptionProps, "ref"> & React.RefAttributes<HTMLDivElement>>export Descriptionsaved} was updated.</const saved: string | undefinedToast.import ToastDescription>const Description: React.ForwardRefExoticComponent<Omit<Toast.DescriptionProps, "ref"> & React.RefAttributes<HTMLDivElement>>export Description</Toast.import ToastRoot>const Root: React.ForwardRefExoticComponent<Omit<Toast.RootProps, "ref"> & React.RefAttributes<HTMLDivElement>>export RootDeclares a toast. Renders nothing where it stands: the content is registered for the toaster, and
openis mirrored into the store, which reports a timeout or a close back asonOpenChange.<Toast.import ToastToaster />const Toaster: React.ForwardRefExoticComponent<Omit<Toast.ToasterProps, "ref"> & React.RefAttributes<HTMLDivElement>>export ToasterArk's region host; place one per app, after the content that declares toasts.
</Toast.import ToastProvider>function Provider({ duration, overlap, children }: Toast.ProviderProps): React.JSX.Elementexport Provider);};Toast.RootpassesonOpenChangethe boolean itself, whereDialog.Rootpasses an object that holds it. When the toast times out, the handler clearssaved, so the next save opens the toast again.
Try it
Section titled “Try it”Choose a contact and press Edit. Save a change, and the toast appears. Hover over the role, or tab to it, to see what the role allows. Press Delete, then Keep or Delete.
What you can do now
Section titled “What you can do now”You can open dialogs and popovers from buttons, add tooltips to any element, and show toasts. Next, Icons and translations moves the screen’s strings into a resource.