By the end of this guide you know where TILE code goes in a plugin. You also know the four rules that keep a
plugin’s UI consistent with the rest of the app.
A PLEX plugin draws its UI with TILE. PLEX is DXOS’s framework for building an app out of
plugins, and Composer, DXOS’s local-first workspace, is built with it. Composer already provides the
theme, the provider, the icon sprite and dark mode, so your plugin skips
Installation and uses the components directly.
Components take props, and containers connect them
You may already split a React app into components that draw and components that fetch data. A plugin makes the same
split, and gives each kind a folder:
A component, under src/components/, renders from its props and never reads a capability. It imports TILE and
nothing from @dxos/app-framework or @dxos/app-toolkit, so you can show it in a story and reuse it.
A container, under src/containers/, is the React component that a PLEX surface renders. It reads
capabilities, queries the user’s data and invokes
operations, then passes the results to components as props.
A PLEX surface is a named place in the app’s UI that plugins fill, which is not the surface of a TILE token.
Surfaces explains how the app picks the container for a place.
Example (Writing a component that takes its data as props)
1
import*as
import Hooks
Hooksfrom'@dxos/react-ui/Hooks';
2
import*as
import Listbox
Listboxfrom'@dxos/react-ui/Listbox';
3
import*as
import Status
Statusfrom'@dxos/react-ui/Status';
4
5
exporttype
typeContactListProps = {
contacts: {
id: string;
name: string;
}[];
onSelect?: (id: string) =>void;
}
ContactListProps = {
6
contacts: {
id: string;
name: string;
}[]
contacts: {
id: string
id: string;
name: string
name: string }[];
7
onSelect?: ((id: string) => void) | undefined
onSelect?: (
id: string
id: string) =>void;
8
};
9
10
/** Takes its data and callbacks as props; a container reads them from the app and passes them in. */
Stands in for content that is not there (no items, no selection, no result): a centred status message, its text the
children or the translated "No items". Composites build their own Empty part on it.
Empty
icon?: string | undefined
A Phosphor icon above the message; decorative, since the message carries the statement.
Stands in for content that is not there (no items, no selection, no result): a centred status message, its text the
children or the translated "No items". Composites build their own Empty part on it.
Empty>
19
);
20
}
21
22
const
const items: {
value: string;
label: string;
}[]
items =
contacts: {
id: string;
name: string;
}[]
contacts.
Array<{ id: string; name: string; }>.map<{
value: string;
label: string;
}>(callbackfn: (value: {
id: string;
name: string;
}, index: number, array: {
id: string;
name: string;
}[]) => {
value: string;
label: string;
}, thisArg?: any): {
value: string;
label: string;
}[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Ark listbox: single, multiple or no selection, with keyboard navigation, typeahead and aria-selected from zag. A
flex column that caps itself at its parent's height, so a long list scrolls in its Content.
A thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a
fixed-height panel). Its Content is the scrolling element, so the thumb sits in the Content's end gutter. Omit it
inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.
The listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root's virtual windowing over its direct children (the rows). Under a
Viewport it is the scrolling element (inset gutter by default); otherwise its host scrolls and the rows inherit the
host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs a Viewport.
Content
"aria-label"?: string | undefined
Defines a string value that labels the current element.
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
A row (option) at least one block tall: without children, the option's icon, label and description; with them,
the caller's parts, which the theme places by part (leading cells, text over description, then trailing cells) or,
under Root columns, in order across the shared tracks. Pointer presses on a row control stay with the control: they
neither select the row nor take focus from the control.
The listbox element: zag's content props with the grid keyboard in front of them, a Container's attributes so a
Viewport's slot merges onto it, and the Root's virtual windowing over its direct children (the rows). Under a
Viewport it is the scrolling element (inset gutter by default); otherwise its host scrolls and the rows inherit the
host's rails (inherit). A windowed (virtual) list measures its scroller, so it needs a Viewport.
A thin overlay ScrollArea (decision 5) that grows to fill the Root, for a list that owns its scrolling (a picker, a
fixed-height panel). Its Content is the scrolling element, so the thumb sits in the Content's end gutter. Omit it
inside a host that already scrolls, which would otherwise trap wheel and trackpad gestures in a nested scroller.
Ark listbox: single, multiple or no selection, with keyboard navigation, typeahead and aria-selected from zag. A
flex column that caps itself at its parent's height, so a long list scrolls in its Content.
Root>
33
);
34
};
35
ContactList renders no Panel, because the panel belongs to its container. That container would query the
contacts and pass each one’s id and name. It would also pass an onSelect that invokes one of the plugin’s
operations.
The container owns the Panel. A container that fills a pane of the app or a dialog renders Panel.Root, with a
toolbar in Panel.Header and a scrolling Panel.Body, and puts its components in the body.
Layout explains how the body scrolls, and Panel lists the
panel’s props.
Lists and forms inside the body own their spacing, so add no padding around them.
You usually build a plugin’s toolbar from its actions with @dxos/react-ui-menu, so that other plugins can add to it.
ActionToolbar shows how to build one and how to add another plugin’s
actions.