Installation
By the end of this page the contacts screen is a Vite app with TILE’s theme. It shows its first two buttons, in light or dark mode to match the system. TILE needs neither ECHO, DXOS’s database, nor PLEX, its plugin framework, for this.
Background
Section titled “Background”You need Node 20 or later. Every page of the path is the same app, so keep the project when you go on to the next one.
A component library usually ships a finished stylesheet. TILE generates its CSS when our app builds, so we install the tools that build it beside the components. Step 1 installs seven packages, and sets the version of React:
@dxos/react-uiholds the components. It needs React 19.3, which is why step 1 names a version ofreactandreact-dom.@dxos/ui-theme, its peer, holds the tokens andThemePlugin, a Vite plugin that turns them into CSS. A token is a named color or size that the components read. We set the plugin up in step 2.effectand@effect/atom-reactare peers of@dxos/react-uitoo, so we install them beside it.@dxos/vite-plugin-iconsholdsIconsPlugin, which gathers the icons the app draws into one file.@phosphor-icons/coreholds the icons themselves, as SVG files thatIconsPluginreads.tailwindcssis the compiler thatThemePluginruns.
Until the next npm release, we install the @dxos packages from pkg.pr.new, as the build of main that these pages
describe. The releases on npm are older and do not all run outside the DXOS repository. ECHO’s
Installation installs its packages from the same build.
-
Make a Vite app. Create a React and TypeScript project and install the packages:
Terminal window npm create vite@latest contacts -- --template react-tscd contactsnpm install \https://pkg.pr.new/dxos/dxos/@dxos/react-ui@20a14b9 \https://pkg.pr.new/dxos/dxos/@dxos/ui-theme@20a14b9 \effect@4.0.4 @effect/atom-react@4.0.4 react@~19.3.1 react-dom@~19.3.1npm install --save-dev \https://pkg.pr.new/dxos/dxos/@dxos/vite-plugin-icons@20a14b9 \@phosphor-icons/core tailwindcssInstall any other
@dxospackage from the same build, with its name in place ofreact-ui. -
Configure Vite. Replace
vite.config.ts. Two plugins do the work:ThemePlugingenerates the theme’s CSS with Tailwind. Tailwind emits a token or a class only when a file it scans names it, socontentpoints it at the components’ own stylesheets.IconsPluginbuilds/icons.svg, a sprite, which is one file that holds every icon our code and the components name.
vite.config.ts import react from '@vitejs/plugin-react';import { join } from 'node:path';import { defineConfig } from 'vite';import { ThemePlugin } from '@dxos/ui-theme/plugin';import { IconsPlugin, iconSymbolPattern } from '@dxos/vite-plugin-icons';const phosphor = join(import.meta.dirname, 'node_modules/@phosphor-icons/core/assets');export default defineConfig({plugins: [ThemePlugin({ content: ['node_modules/@dxos/*/src/**/*.css'] }),IconsPlugin({symbolPattern: iconSymbolPattern({ sets: ['ph'] }),assetPath: (_set, name, variant) =>join(phosphor, variant, variant === 'regular' ? `${name}.svg` : `${name}-${variant}.svg`),spriteFile: 'icons.svg',contentPaths: [join(import.meta.dirname, 'src/**/*.{ts,tsx}')],// Pre-bundled dependencies skip the plugin's transform, so their icons are found by scanning up front.scanPaths: [join(import.meta.dirname, 'node_modules/@dxos/*/dist/**/*.mjs')],}),react(),],});ThemePluginalso gives the app dark mode. The dark value of every token applies under adarkclass on the root element. The plugin adds a script to the page’s<head>that sets the class from the system’s setting before the first paint, and sets it again when the setting changes.To let the user choose the mode instead, see Custom themes and dark mode, which sets the class from a stored choice.
-
Render the app inside the theme. Replace
src/main.tsx. The new file imports two stylesheets before any component:@dxos-themeis the virtual module thatThemePluginserves.@dxos/react-ui/theme.cssholds the components’ own rules.
Then it renders the app inside
Theme.Provider, which gives every component the strings its built-in labels read and the icons it draws:import '@dxos-theme';importReact from 'react';(alias) namespace Reactimport Reactimport {createRoot } from 'react-dom/client';function createRoot(container: Container, options?: RootOptions): RootcreateRoot lets you create a root to display React components inside a browser DOM node.
import '@dxos/react-ui/theme.css';import * asTheme from '@dxos/react-ui/Theme';import Themeimport {translations } from '@dxos/react-ui/translations';const translations: [{readonly 'en-US': {readonly "@dxos/react-ui": {readonly "empty.label": "No items";readonly "error-fallback.title.label": "Runtime Error";readonly "error-fallback.stack.label": "Stack";readonly "error-fallback.data.label": "Data";readonly "steps.step.label": "Step {{index}}";readonly "remove.label": "Delete";readonly "toolbar-menu.label": "Action menu";readonly "toolbar-drag-handle.label": "Drag to rearrange";readonly "toolbar-close.label": "Close";readonly "toolbar-delete.label": "Delete";readonly "floating-panel.minimize.label": "Minimize";readonly "floating-panel.maximize.label": "Maximize";readonly "floating-panel.restore.label": "Restore";readonly "drawer.resize.label": "Resize drawer";readonly "system-button.star.label": "Star";readonly "system-button.unstar.label": "Unstar";readonly "system-button.bookmark.label": "Bookmark";readonly "system-button.unbookmark.label": "Remove bookmark";readonly "system-button.check.label": "Check";readonly "system-button.uncheck.label": "Uncheck";readonly "system-button.expand.label": "Expand";readonly "system-button.collapse.label": "Collapse";readonly "system-button.ai.label": "Run AI";readonly "system-button.add.label": "Add";readonly "system-button.delete.label": "Delete";readonly "system-button.remove.label": "Delete";readonly "system-button.edit.label": "Edit";readonly "system-button.close.label": "Close";readonly "system-button.open.label": "Open";readonly "system-button.save.label": "Save";readonly "system-button.cancel.label": "Cancel";readonly "system-button.upload.label": "Upload";readonly "system-button.download.label": "Download";readonly "system-button.clipboard.label": "Copy";readonly "system-button.copied.label": "Copied";readonly "carousel-viewport.label": "Carousel";readonly "carousel-prev.label": "Previous slide";readonly "carousel-next.label": "Next slide";readonly "carousel-indicators.label": "Carousel slides";readonly "carousel-go-to.label": "Go to slide {{index}}";readonly "date-picker.placeholder.single.label": "Pick a date";readonly "date-picker.placeholder.range.label": "Pick a date range";readonly "date-picker.placeholder.multiple.label": "Pick dates";readonly "date-picker.clear.label": "Clear";readonly "calendar.nav.previous.label": "Previous month";readonly "calendar.nav.next.label": "Next month";readonly "calendar.nav.previous-year.label": "Previous year";readonly "calendar.nav.next-year.label": "Next year";readonly "calendar.nav.previous-decade.label": "Previous decade";readonly "calendar.nav.next-decade.label": "Next decade";readonly "calendar.footer.today.label": "Today";readonly "trigger-button.label": "Open";readonly "number-input.increment.label": "Increment";readonly "number-input.decrement.label": "Decrement";readonly "number-input.slider.label": "Adjust";readonly "password-input.show.label": "Show password";readonly "password-input.hide.label": "Hide password";readonly "tag.delete.label": "Remove {{label}}";readonly "combobox.search.label": "Search";readonly "combobox.empty.label": "No results";readonly "combobox.loading.label": "Loading\u2026";readonly "combobox.create.label": "Create \u201C{{query}}\u201D";readonly "drag-handle.label": "Drag to rearrange";readonly "drag-handle.role.label": "drag handle";readonly "drag-handle.grabbed.message": "Grabbed. Press the arrow keys to move, Space to drop.";readonly "drag-handle.moved-up.message": "Moved up.";readonly "drag-handle.moved-down.message": "Moved down.";readonly "drag-handle.dropped.message": "Dropped.";};};}]import {App } from './App.tsx';const App: () => React.JSX.ElementcreateRoot(function createRoot(container: Container, options?: RootOptions): RootcreateRoot lets you create a root to display React components inside a browser DOM node.
document.var document: Documentwindow.documentreturns a reference to the document contained in the window.getElementById('root')!).Document.getElementById(elementId: string): HTMLElement | nullThe
getElementById()method of the Document interface returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.render(Root.render(children: React.ReactNode): void<Theme.import ThemeProviderconst Provider: ({ children, fallback, resourceExtensions, appNs, tx, themeMode, platform, }: Theme.ProviderProps) => React.JSX.Elementexport Providertx={tx?: ThemeFunction<Record<string, any>> | undefinedTheme.import ThemedefaultTx}const defaultTx: ThemeFunction<Record<string, any>>resourceExtensions={resourceExtensions?: Theme.Resource[] | undefinedtranslations}>const translations: [{readonly 'en-US': {readonly "@dxos/react-ui": {readonly "empty.label": "No items";readonly "error-fallback.title.label": "Runtime Error";readonly "error-fallback.stack.label": "Stack";readonly "error-fallback.data.label": "Data";readonly "steps.step.label": "Step {{index}}";readonly "remove.label": "Delete";readonly "toolbar-menu.label": "Action menu";readonly "toolbar-drag-handle.label": "Drag to rearrange";readonly "toolbar-close.label": "Close";readonly "toolbar-delete.label": "Delete";readonly "floating-panel.minimize.label": "Minimize";readonly "floating-panel.maximize.label": "Maximize";readonly "floating-panel.restore.label": "Restore";readonly "drawer.resize.label": "Resize drawer";readonly "system-button.star.label": "Star";readonly "system-button.unstar.label": "Unstar";readonly "system-button.bookmark.label": "Bookmark";readonly "system-button.unbookmark.label": "Remove bookmark";readonly "system-button.check.label": "Check";readonly "system-button.uncheck.label": "Uncheck";readonly "system-button.expand.label": "Expand";readonly "system-button.collapse.label": "Collapse";readonly "system-button.ai.label": "Run AI";readonly "system-button.add.label": "Add";readonly "system-button.delete.label": "Delete";readonly "system-button.remove.label": "Delete";readonly "system-button.edit.label": "Edit";readonly "system-button.close.label": "Close";readonly "system-button.open.label": "Open";readonly "system-button.save.label": "Save";readonly "system-button.cancel.label": "Cancel";readonly "system-button.upload.label": "Upload";readonly "system-button.download.label": "Download";readonly "system-button.clipboard.label": "Copy";readonly "system-button.copied.label": "Copied";readonly "carousel-viewport.label": "Carousel";readonly "carousel-prev.label": "Previous slide";readonly "carousel-next.label": "Next slide";readonly "carousel-indicators.label": "Carousel slides";readonly "carousel-go-to.label": "Go to slide {{index}}";readonly "date-picker.placeholder.single.label": "Pick a date";readonly "date-picker.placeholder.range.label": "Pick a date range";readonly "date-picker.placeholder.multiple.label": "Pick dates";readonly "date-picker.clear.label": "Clear";readonly "calendar.nav.previous.label": "Previous month";readonly "calendar.nav.next.label": "Next month";readonly "calendar.nav.previous-year.label": "Previous year";readonly "calendar.nav.next-year.label": "Next year";readonly "calendar.nav.previous-decade.label": "Previous decade";readonly "calendar.nav.next-decade.label": "Next decade";readonly "calendar.footer.today.label": "Today";readonly "trigger-button.label": "Open";readonly "number-input.increment.label": "Increment";readonly "number-input.decrement.label": "Decrement";readonly "number-input.slider.label": "Adjust";readonly "password-input.show.label": "Show password";readonly "password-input.hide.label": "Hide password";readonly "tag.delete.label": "Remove {{label}}";readonly "combobox.search.label": "Search";readonly "combobox.empty.label": "No results";readonly "combobox.loading.label": "Loading\u2026";readonly "combobox.create.label": "Create \u201C{{query}}\u201D";readonly "drag-handle.label": "Drag to rearrange";readonly "drag-handle.role.label": "drag handle";readonly "drag-handle.grabbed.message": "Grabbed. Press the arrow keys to move, Space to drop.";readonly "drag-handle.moved-up.message": "Moved up.";readonly "drag-handle.moved-down.message": "Moved down.";readonly "drag-handle.dropped.message": "Dropped.";};};}]<App />const App: () => React.JSX.Element</Theme.import ThemeProvider>,const Provider: ({ children, fallback, resourceExtensions, appNs, tx, themeMode, platform, }: Theme.ProviderProps) => React.JSX.Elementexport Provider);resourceExtensions={translations}passes react-ui’s own strings, such as the “No items” of an empty list.txtakes a theme function, andTheme.defaultTxis the one TILE exports. -
Add the first buttons. Replace
src/App.tsx.Layout.Flexlays the buttons out in a row with a gap from the theme’s scale, andvariant='primary'marks the main action:importReact from 'react';(alias) namespace Reactimport Reactimport * asButton from '@dxos/react-ui/Button';import Buttonimport * asLayout from '@dxos/react-ui/Layout';import Layoutexport constApp = () => (const App: () => React.JSX.Element<Layout.import LayoutFlexconst Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>One-axis layout box: the primitive that replaces hand-written
flex …wrapper divs.gapis restricted to the named steps of the theme spacing ramp (seeGap
), which is the point of the prop — an off-ramp
gap-2/gap-3literal in a container is the drift it prevents. Anything the props don't cover (padding, sizing, overflow, colour) goes throughclassNames; the component deliberately grows no padding or colour props, since components own their own spacing.There is no implicit
align. Row-centering is the common case, but defaulting it would silently restyle any consumer relying on the CSSstretchinitial value.Use
asChildto project the layout onto a semantic element (<header>,<ul>,<a>).gap='sm'>gap?: Layout.Gap | undefined<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Rootvariant='primary'variant?: Button.Variant | undefinedicon='ph--plus--regular'icon?: string | undefinedLeading icon.
label='Add contact' />label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.<Button.import ButtonRoot>Import</const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export RootButton.import ButtonRoot>const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Root</Layout.import LayoutFlex>const Flex: React.ForwardRefExoticComponent<Omit<Layout.FlexProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>One-axis layout box: the primitive that replaces hand-written
flex …wrapper divs.gapis restricted to the named steps of the theme spacing ramp (seeGap
), which is the point of the prop — an off-ramp
gap-2/gap-3literal in a container is the drift it prevents. Anything the props don't cover (padding, sizing, overflow, colour) goes throughclassNames; the component deliberately grows no padding or colour props, since components own their own spacing.There is no implicit
align. Row-centering is the common case, but defaulting it would silently restyle any consumer relying on the CSSstretchinitial value.Use
asChildto project the layout onto a semantic element (<header>,<ul>,<a>).);Delete
src/App.cssandsrc/index.css, which Vite’s template made. The theme replaces them.
Try it
Section titled “Try it”Run npm run dev and open the page. Switch your system between light and dark, and the buttons follow. This preview
follows the docs’ own mode picker instead:
What you can do now
Section titled “What you can do now”You can render TILE components in a themed app that follows light and dark mode. Next,
Lay out a screen builds the list and the detail beside it, in a folder of its
own, src/layout/.