The TILE component
In this learning path we build one screen: a list of contacts beside the selected person’s details, with a toolbar to add, edit and delete them. This page explains what a TILE component is, and shows the screen finished.
What a TILE component is
Section titled “What a TILE component is”A component library often gives you one Dialog component, and you shape it with props. A TILE component is a
namespace of parts instead:
- A part is one element of the component, such as
Dialog.Trigger,Dialog.ContentorDialog.Title. - A namespace is the object that holds a component’s parts, such as
Dialog. You import each namespace from its own entry point of@dxos/react-ui, such as@dxos/react-ui/Dialog.
Dialog.Root holds the state, and each other part renders one element. You put the parts together in JSX, in the
shape you want, and leave out the ones you don’t need:
import * as import Button
Button from '@dxos/react-ui/Button';import * as import Dialog
Dialog from '@dxos/react-ui/Dialog';import * as import Field
Field from '@dxos/react-ui/Field';import * as import Input
Input from '@dxos/react-ui/Input';
export const const EditDialog: () => React.JSX.Element
EditDialog = () => ( <import Dialog
Dialog.function Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Element
export Root
Root> <import Dialog
Dialog.const Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export Trigger
Use asChild to open the dialog from a Button.
Trigger PolymorphicProps.asChild?: boolean | undefined
Use the provided child element as the default rendered element, combining their props and behavior.
asChild> <import Button
Button.const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & { classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root
Root>Edit contact</import Button
Button.const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & { classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root
Root> </import Dialog
Dialog.const Trigger: React.ForwardRefExoticComponent<DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>export Trigger
Use asChild to open the dialog from a Button.
Trigger> <import Dialog
Dialog.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 Content
Portalled surface at level='raised' over a scrim, centred in the viewport: a column of Header, Body and Footer.
Content> <import Dialog
Dialog.const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export Header
A block row holding the Title and an optional trailing CloseTrigger.
Header> <import Dialog
Dialog.const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Title
Title>Edit contact</import Dialog
Dialog.const Title: React.ForwardRefExoticComponent<Omit<DialogTitleProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { srOnly?: boolean;} & React.RefAttributes<HTMLHeadingElement>>export Title
Title> <import Dialog
Dialog.const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & { children?: React.ReactNode; icon?: string; label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger
CloseTrigger /> </import Dialog
Dialog.const Header: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export Header
A block row holding the Title and an optional trailing CloseTrigger.
Header> <import Dialog
Dialog.const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & { align?: "start" | "center"; children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export Body
Composed scroll (decision 5): a gutter='md' Container as the viewport, so the thumb sits in the end gutter; gap
spaces its rows, since they are the Container's own items.
The element carries ScrollArea's data-scope, since parts cannot rescope a composed child (finding 10).
Body> <import Dialog
Dialog.const Description: React.ForwardRefExoticComponent<Omit<DialogDescriptionProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { srOnly?: boolean;} & React.RefAttributes<HTMLParagraphElement>>export Description
Description> Changes are saved when you press Save. </import Dialog
Dialog.const Description: React.ForwardRefExoticComponent<Omit<DialogDescriptionProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { srOnly?: boolean;} & React.RefAttributes<HTMLParagraphElement>>export Description
Description> <import Field
Field.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 Root
A part, not a container (decision 13): a flex stack in the content track with the label above its control.
Root> <import Field
Field.const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export Label
Names the control; while the root is required it ends with the required indicator, unless a
RequiredIndicator among its children places the mark itself.
Label>Name</import Field
Field.const Label: React.ForwardRefExoticComponent<Omit<FieldLabelProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { srOnly?: boolean;} & React.RefAttributes<HTMLLabelElement>>export Label
Names the control; while the root is required it ends with the required indicator, unless a
RequiredIndicator among its children places the mark itself.
Label> <import Input
Input.const Root: React.ForwardRefExoticComponent<Omit<Input.RootProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLInputElement>>export Root
Text input at control size; inside a Field.Root it takes the field's id, label and description wiring. With
start or end it renders a ControlFrame holding the adornments and a bare input; data-testid and classes then
go to the frame, the ref to the input.
Root defaultValue?: string | number | readonly string[] | undefined
defaultValue='Ada Lovelace' /> </import Field
Field.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 Root
A part, not a container (decision 13): a flex stack in the content track with the label above its control.
Root> </import Dialog
Dialog.const Body: React.ForwardRefExoticComponent<Omit<Pick<ScrollArea.RootProps, "mode" | "native" | "width">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<Layout.ContainerProps, "gap"> & { align?: "start" | "center"; children?: React.ReactNode;} & React.RefAttributes<HTMLDivElement>>export Body
Composed scroll (decision 5): a gutter='md' Container as the viewport, so the thumb sits in the end gutter; gap
spaces its rows, since they are the Container's own items.
The element carries ScrollArea's data-scope, since parts cannot rescope a composed child (finding 10).
Body> <import Dialog
Dialog.const Footer: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export Footer
An end-justified Group of actions; the child div wins the merge, so the part keeps the dialog scope. The
actions stay regular-sized in a small dialog, since they are the dialog's primary targets.
Footer> <import Dialog
Dialog.const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & { children?: React.ReactNode; icon?: string; label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger
CloseTrigger asChild?: boolean | undefined
Use the provided child element as the default rendered element, combining their props and behavior.
asChild> <import Button
Button.const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & { classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root
Root>Cancel</import Button
Button.const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & { classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root
Root> </import Dialog
Dialog.const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & { children?: React.ReactNode; icon?: string; label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger
CloseTrigger> <import Dialog
Dialog.const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & { children?: React.ReactNode; icon?: string; label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger
CloseTrigger asChild?: boolean | undefined
Use the provided child element as the default rendered element, combining their props and behavior.
asChild> <import Button
Button.const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & { classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root
Root variant?: Button.Variant | undefined
variant='primary'>Save</import Button
Button.const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & { classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLButtonElement>>export Root
Root> </import Dialog
Dialog.const CloseTrigger: React.ForwardRefExoticComponent<Omit<DialogCloseTriggerProps, "children"> & { children?: React.ReactNode; icon?: string; label?: string;} & React.RefAttributes<HTMLButtonElement>>export CloseTrigger
CloseTrigger> </import Dialog
Dialog.const Footer: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & React.RefAttributes<HTMLDivElement>>export Footer
An end-justified Group of actions; the child div wins the merge, so the part keeps the dialog scope. The
actions stay regular-sized in a small dialog, since they are the dialog's primary targets.
Footer> </import Dialog
Dialog.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 Content
Portalled surface at level='raised' over a scrim, centred in the viewport: a column of Header, Body and Footer.
Content> </import Dialog
Dialog.function Root({ lazyMount, unmountOnExit, closeOnInteractOutside, placement, ...props }: Dialog.RootProps): React.JSX.Element
export Root
Root>);
Dialog.Trigger wraps the button that opens the dialog. Each button in the footer sits in a Dialog.CloseTrigger,
so Cancel and Save both close it.
Every part takes its look from the theme, which is TILE’s stylesheets and the tokens they are built from. A
token is a named color or size. A part writes its props, such as variant='primary', onto its element as
attributes, and the stylesheets style them with tokens.
The same component therefore follows light and dark mode, and matches the rest of the app. To adjust one part, pass
classNames. Theme.Provider wraps the app and gives the parts their built-in strings and their icons.
The parts also handle the keyboard, focus and ARIA attributes. A dialog traps focus and closes on Escape without code of yours.
Composite components covers parts and the state machines behind them.
Theme and tokens covers the tokens and classNames.
The finished screen
Section titled “The finished screen”This is the screen at the end of the path, before its last page moves the contacts into ECHO, DXOS’s database. Select a contact, edit it, delete it or add one:
Each page of the path builds one piece of it. From Lay out a screen on, each page keeps its version of the screen in a folder of its own:
| Page | Folder | What it adds |
|---|---|---|
| Installation | src/ |
A Vite app with TILE’s theme, icons and dark mode, and its first buttons |
| Lay out a screen | src/layout/ |
The list beside the detail, with a toolbar |
| Inputs and actions | src/inputs/ |
An editor for the selected contact |
| Overlays | src/overlays/ |
An edit dialog, a delete confirmation, a tooltip and a toast |
| Icons and translations | src/icons/ |
Icons, an Add button, and the screen’s strings in a resource |
| Connect to ECHO | src/echo/ |
The contacts as ECHO objects that sync, and a form built from their schema |
Every page before Connect to ECHO keeps the contacts in React state, so the only new thing on each page is TILE.