Translations and icons
TILE components show no hard-coded text and load no icon files of their own. Strings come from translation resources, and icons from a sprite that the build assembles.
A label written straight into the JSX cannot be translated without a change to the component. With TILE, you name the string by a key instead, and you name an icon the same way, by a string.
Resources. A translation resource maps a language to translation namespaces, and each namespace to keys. A translation namespace is the name a set of keys is filed under, so two packages can use the same key.
For example, react-ui’s own strings, such as the “No items” of an empty state, are in the @dxos/react-ui namespace
of its translations export. Your app or plugin adds its own namespace:
import * as import Theme
Theme from '@dxos/react-ui/Theme';
const const ns: "com.example.contacts"
ns = 'com.example.contacts';
export const const translations: [{ readonly 'en-US': { readonly "com.example.contacts": { readonly 'add.label': "Add contact"; readonly 'count.label_one': "{{count}} contact"; readonly 'count.label_other': "{{count}} contacts"; readonly 'empty.message': "No contacts yet"; readonly 'list.label': "Contacts"; }; };}]
translations = [ { 'en-US': { [const ns: "com.example.contacts"
ns]: { 'add.label': 'Add contact', 'count.label_one': '{{count}} contact', 'count.label_other': '{{count}} contacts', 'empty.message': 'No contacts yet', 'list.label': 'Contacts', }, }, },] as type const = [{ readonly 'en-US': { readonly "com.example.contacts": { readonly 'add.label': "Add contact"; readonly 'count.label_one': "{{count}} contact"; readonly 'count.label_other': "{{count}} contacts"; readonly 'empty.message': "No contacts yet"; readonly 'list.label': "Contacts"; }; };}]
const satisfies import Theme
Theme.export Resource
Resource[];
ns is com.example.contacts, a reverse domain, so no other package files its keys under the same name.
count.label has two forms, _one and _other.
The provider merges them. Theme.Provider takes every resource in resourceExtensions, so pass react-ui’s together
with your own:
import * as import Theme
Theme from '@dxos/react-ui/Theme';
export const const App: () => React.JSX.Element
App = () => ( <import Theme
Theme.const Provider: ({ children, fallback, resourceExtensions, appNs, tx, themeMode, platform, }: Theme.ProviderProps) => React.JSX.Elementexport Provider
Provider tx?: ThemeFunction<Record<string, any>> | undefined
tx={import Theme
Theme.const defaultTx: ThemeFunction<Record<string, any>>
defaultTx} resourceExtensions?: Theme.Resource[] | undefined
resourceExtensions={[...const uiTranslations: [{ 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."; }; };}]
uiTranslations, ...const translations: [{ readonly 'en-US': { readonly "com.example.contacts": { readonly 'add.label': "Add contact"; readonly 'count.label_one': "{{count}} contact"; readonly 'count.label_other': "{{count}} contacts"; readonly 'empty.message': "No contacts yet"; readonly 'list.label': "Contacts"; }; };}]
translations]} > <const ContactsToolbar: ({ count }: { count: number;}) => React.JSX.Element
ContactsToolbar count: number
count={3} /> </import Theme
Theme.const Provider: ({ children, fallback, resourceExtensions, appNs, tx, themeMode, platform, }: Theme.ProviderProps) => React.JSX.Elementexport Provider
Provider>);
resourceExtensions takes one flat list, so App spreads each package’s resources into it.
Hooks.useTranslation reads them. It returns t for one translation namespace. Use it in any component that
shows text. Keys take i18next interpolation and plurals, so count.label with
{ count: 3 } picks the _other form.
Example (Reading a plural and a label)
import * as import Button
Button from '@dxos/react-ui/Button';import * as import Hooks
Hooks from '@dxos/react-ui/Hooks';import * as import Toolbar
Toolbar from '@dxos/react-ui/Toolbar';
export const const ContactsToolbar: ({ count }: { count: number;}) => React.JSX.Element
ContactsToolbar = ({ count: number
count }: { count: number
count: number }) => { const { const t: TFunction<Namespace<string>, KeyPrefix<Namespace<string>>>
t } = import Hooks
Hooks.function useTranslation(ns?: string | string[] | readonly string[] | undefined, options?: UseTranslationOptions<KeyPrefix<Namespace<string>>> | undefined): { toString(): string; toLocaleString(): string; toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string; pop(): boolean | TFunction<Namespace<string>, KeyPrefix<Namespace<string>>> | i18n | undefined; push(...items: (boolean | TFunction<Namespace<string>, KeyPrefix<Namespace<string>>> | i18n)[]): number; concat(...items: ConcatArray<boolean | TFunction<...> | i18n>[]): (boolean | TFunction<...> | i18n)[]; concat(...items: (boolean | ConcatArray<boolean | TFunction<...> | i18n> | TFunction<...> | i18n)[]): (boolean | TFunction<...> | i18n)[]; join(separator?: string): string; reverse(): (boolean | TFunction<...> | i18n)[]; shift(): boolean | TFunction<...> | i18n | undefined; slice(start?: number, end?: number): (boolean | TFunction<...> | i18n)[]; sort(compareFn?: ((a: boolean | TFunction<...> | i18n, b: boolean | TFunction<...> | i18n) => number) | undefined): UseTranslationResponse<...>; splice(start: number, deleteCount?: number): (boolean | TFunction<...> | i18n)[]; splice(start: number, deleteCount: number, ...items: (boolean | TFunction<...> | i18n)[]): (boolean | TFunction<...> | i18n)[]; unshift(...items: (boolean | TFunction<...> | i18n)[]): number; indexOf(searchElement: boolean | TFunction<...> | i18n, fromIndex?: number): number; lastIndexOf(searchElement: boolean | TFunction<...> | i18n, fromIndex?: number): number; every<S extends boolean | TFunction<...> | i18n>(predicate: (value: boolean | TFunction<...> | i18n, index: number, array: (boolean | TFunction<...> | i18n)[]) => value is S, thisArg?: any): this is S[]; every(predicate: (value: boolean | TFunction<...> | i18n, index: number, array: (boolean | TFunction<...> | i18n)[]) => unknown, thisArg?: any): boolean; some(predicate: (value: boolean | TFunction<...> | i18n, index: number, array: (boolean | TFunction<...> | i18n)[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: boolean | TFunction<...> | i18n, index: number, array: (boolean | TFunction<...> | i18n)[]) => void, thisArg?: any): void; map<U>(callbackfn: (value: boolean | TFunction<...> | i18n, index: number, array: (boolean | TFunction<...> | i18n)[]) => U, thisArg?: any): U[]; filter<S extends boolean | TFunction<...> | i18n>(predicate: (value: boolean | TFunction<...> | i18n, index: number, array: (boolean | TFunction<...> | i18n)[]) => value is S, thisArg?: any): S[]; filter(predicate: (value: boolean | TFunction<...> | i18n, index: number, array: (boolean | TFunction<...> | i18n)[]) => unknown, thisArg?: any): (boolean | TFunction<...> | i18n)[]; reduce(callbackfn: (previousValue: boolean | TFunction<...> | i18n, currentValue: boolean | TFunction<...> | i18n, currentIndex: number, array: (boolean | TFunction<...> | i18n)[]) => boolean | TFunction<...> | i18n): boolean | TFunction<...> | i18n; reduce(callbackfn: (previousValue: boolean | TFunction<...> | i18n, currentValue: boolean | TFunction<...> | i18n, currentIndex: number, array: (boolean | TFunction<...> | i18n)[]) => boolean | TFunction<...> | i18n, initialValue: boolean | TFunction<...> | i18n): boolean | TFunction<...> | i18n; reduce<U>(callbackfn: (previousValue: U, currentValue: boolean | TFunction<...> | i18n, currentIndex: number, array: (boolean | TFunction<...> | i18n)[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: boolean | TFunction<...> | i18n, currentValue: boolean | TFunction<...> | i18n, currentIndex: number, array: (boolean | TFunction<...> | i18n)[]) => boolean | TFunction<...> | i18n): boolean | TFunction<...> | i18n; reduceRight(callbackfn: (previousValue: boolean | TFunction<...> | i18n, currentValue: boolean | TFunction<...> | i18n, currentIndex: number, array: (boolean | TFunction<...> | i18n)[]) => boolean | TFunction<...> | i18n, initialValue: boolean | TFunction<...> | i18n): boolean | TFunction<...> | i18n; reduceRight<U>(callbackfn: (previousValue: U, currentValue: boolean | TFunction<...> | i18n, currentIndex: number, array: (boolean | TFunction<...> | i18n)[]) => U, initialValue: U): U; find<S extends boolean | TFunction<...> | i18n>(predicate: (value: boolean | TFunction<...> | i18n, index: number, obj: (boolean | TFunction<...> | i18n)[]) => value is S, thisArg?: any): S | undefined; find(predicate: (value: boolean | TFunction<...> | i18n, index: number, obj: (boolean | TFunction<...> | i18n)[]) => unknown, thisArg?: any): boolean | TFunction<...> | i18n | undefined; findIndex(predicate: (value: boolean | TFunction<...> | i18n, index: number, obj: (boolean | TFunction<...> | i18n)[]) => unknown, thisArg?: any): number; fill(value: boolean | TFunction<...> | i18n, start?: number, end?: number): UseTranslationResponse<...>; copyWithin ...export useTranslation
useTranslation(const ns: "com.example.contacts"
ns); return ( <import Toolbar
Toolbar.const Root: React.ForwardRefExoticComponent<Omit<Toolbar.RootProps & { asChild?: boolean;}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export Root
role=toolbar with 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.
Root> <import Toolbar
Toolbar.const Text: React.ForwardRefExoticComponent<Omit<{ asChild?: boolean;}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export Text
A run of text that takes the free space and truncates; not an item, so roving focus skips it.
Text>{const t: TFunction<"count.label", ReactI18NextChild | Iterable<ReactI18NextChild>, { count: number;}>(key: "count.label" | "count.label"[], options?: string | TOptions<{ count: number;}> | undefined) => ReactI18NextChild | Iterable<ReactI18NextChild> (+1 overload)
t('count.label', { count: number
Count value used for plurals
count })}</import Toolbar
Toolbar.const Text: React.ForwardRefExoticComponent<Omit<{ asChild?: boolean;}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export Text
A run of text that takes the free space and truncates; not an item, so roving focus skips it.
Text> <import Toolbar
Toolbar.const Separator: React.ForwardRefExoticComponent<Omit<Toolbar.SeparatorProps, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export Separator
A 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.
Separator variant?: "line" | "gap" | undefined
gap is an empty spacer that grows, pushing the items after it to the toolbar's end.
variant='gap' /> <import Button
Button.const Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & { classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Root
Root icon?: string | undefined
Leading icon.
icon='ph--plus--regular' label?: string | undefined
Visible text; children take precedence.
Required: names the button (aria-label) and shows in a Tooltip.
label={const t: TFunction<"add.label", string | undefined, StringMap>(key: "add.label" | "add.label"[], options?: string | TOptions<StringMap> | undefined) => string | undefined (+1 overload)
t('add.label')} iconOnly?: boolean | undefined
A control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
iconOnly /> </import Toolbar
Toolbar.const Root: React.ForwardRefExoticComponent<Omit<Toolbar.RootProps & { asChild?: boolean;}, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export Root
role=toolbar with 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.
Root> );};
ContactsToolbar names its namespace once, in Hooks.useTranslation(ns), and each call to t then names only a
key.
Icons. An icon is named ph--<name>--<weight>, from the Phosphor set, such as
ph--house--regular or ph--heart--fill. The weights are thin, light, regular, bold, fill and duotone.
DXOS’s own marks use dx--<name>--regular.
The sprite is the single SVG file, /icons.svg, that holds the icons an app draws. IconsPlugin finds every
icon name in your sources and in the scanned packages, and writes their SVGs into it. Theme.Provider loads the
sprite once into the page, and Icon.Icon draws a <use> of the symbol it names.
Example (Drawing icons by name)
import * as import Icon
Icon from '@dxos/react-ui/Icon';import * as import Layout
Layout from '@dxos/react-ui/Layout';
export const const Icons: () => React.JSX.Element
Icons = () => ( <import Layout
Layout.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.
gap is restricted to the named steps of the theme spacing ramp (see
Gap
), which is the
point of the prop — an off-ramp gap-2/gap-3 literal in a container is the drift it prevents.
Anything the props don't cover (padding, sizing, overflow, colour) goes through classNames; 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 CSS stretch initial value.
Use asChild to project the layout onto a semantic element (<header>, <ul>, <a>).
Flex gap?: Layout.Gap | undefined
gap='md' align?: Layout.Align | undefined
align='center'> <import Icon
Icon.const Icon: React.ForwardRefExoticComponent<Omit<Omit<React.SVGProps<SVGSVGElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { icon: string; label?: string; hue?: Icon.IconHue; valence?: Icon.IconValence; tone?: Icon.IconTone; spin?: boolean; size?: Size;} & React.RefAttributes<SVGSVGElement>>
Icon icon: string
icon='ph--house--regular' size?: Size | undefined
The icon at this size's scale instead of its scope's (one icon in a denser or roomier control).
size='lg' /> <import Icon
Icon.const Icon: React.ForwardRefExoticComponent<Omit<Omit<React.SVGProps<SVGSVGElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { icon: string; label?: string; hue?: Icon.IconHue; valence?: Icon.IconValence; tone?: Icon.IconTone; spin?: boolean; size?: Size;} & React.RefAttributes<SVGSVGElement>>
Icon icon: string
icon='ph--heart--fill' size?: Size | undefined
The icon at this size's scale instead of its scope's (one icon in a denser or roomier control).
size='lg' hue?: Hue | undefined
Colours the glyph with a Tag hue's foreground (--color-<hue>-fg).
hue='red' /> <import Icon
Icon.const Icon: React.ForwardRefExoticComponent<Omit<Omit<React.SVGProps<SVGSVGElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { icon: string; label?: string; hue?: Icon.IconHue; valence?: Icon.IconValence; tone?: Icon.IconTone; spin?: boolean; size?: Size;} & React.RefAttributes<SVGSVGElement>>
Icon icon: string
icon='ph--warning--regular' size?: Size | undefined
The icon at this size's scale instead of its scope's (one icon in a denser or roomier control).
size='lg' valence?: MessageValence | undefined
Colours the glyph with a valence's semantic text colour (--color-<valence>-text); takes precedence over hue.
valence='warning' /> <import Icon
Icon.const Icon: React.ForwardRefExoticComponent<Omit<Omit<React.SVGProps<SVGSVGElement>, "ref">, "className"> & { classNames?: import("@dxos/ui-types").ClassNameValue;} & { icon: string; label?: string; hue?: Icon.IconHue; valence?: Icon.IconValence; tone?: Icon.IconTone; spin?: boolean; size?: Size;} & React.RefAttributes<SVGSVGElement>>
Icon icon: string
icon='ph--spinner--regular' size?: Size | undefined
The icon at this size's scale instead of its scope's (one icon in a denser or roomier control).
size='lg' spin?: boolean | undefined
Rotates continuously, as a busy indicator; still under prefers-reduced-motion. Spinners share one phase (the
animation starts at the wall clock's second), so several in a list turn together.
spin /> </import Layout
Layout.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.
gap is restricted to the named steps of the theme spacing ramp (see
Gap
), which is the
point of the prop — an off-ramp gap-2/gap-3 literal in a container is the drift it prevents.
Anything the props don't cover (padding, sizing, overflow, colour) goes through classNames; 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 CSS stretch initial value.
Use asChild to project the layout onto a semantic element (<header>, <ul>, <a>).
Flex>);
Icon.Icon takes the whole name in icon. Use size, hue or valence to change how the icon is drawn, and
spin to turn it, as the spinner does.
Behavior
Section titled “Behavior”- A component that takes
iconandlabeluses the label as the button’s accessible name and, for an icon-only button, as its tooltip. Pass a translated string. - If the build did not find a name, such as one built from a string at run time, the icon is fetched on its own when
it is first drawn. The request goes to the app’s icon-set route, such as
/phosphor/regular/plus.svg.- If the app serves that route, the icon appears. Composer, DXOS’s local-first workspace, serves it, so icons from a plugin installed at run time still appear.
- If the app serves no such route, it shows a blank icon.
Limits
Section titled “Limits”- A missing key renders as the key itself, such as
add.label. If you see one, check that the resource is inresourceExtensions. - Name icons in full in your code, so the build finds them and the sprite has them from the start. The same rule holds for classes, as Theme and tokens explains.