Icons and translations
By the end of this page the screen’s own strings come from a translation resource, and the count says “1 contact” or “3 contacts” as it should. Icons mark the email and the role, and an Add button creates a contact.
Background
Section titled “Background”Our first toolbar wrote its count as {contacts.length} contacts, which says “1 contacts” when one is left. A
translation resource holds both forms of the string and picks one from the number:
- A translation resource maps keys to strings for each language. It files them under a translation namespace, a name that keeps one screen’s keys apart from another’s. Step 1 writes ours.
Hooks.useTranslation(ns)returnst, which looks a key up in the user’s language. If a key has_oneand_otherforms, thecountwe pass chooses between them. Steps 2 and 3 call it.
An icon needs no import. We name it in full, as a string, such as ph--envelope--regular for
Phosphor’s envelope in the regular weight. IconsPlugin finds the names in our code and
puts those icons in the sprite, the one file of icons it builds.
Translations and icons explains how resources merge, and what happens to an icon whose name the build did not see.
-
Write the resource. Use a namespace no other code uses, such as a reverse domain.
as constlets TypeScript check the keys we pass tot. Addsrc/icons/translations.ts:import type * asTheme from '@dxos/react-ui/Theme';import Themeexport constns = 'com.example.contacts';const ns: "com.example.contacts"export consttranslations = [const translations: [{readonly 'en-US': {readonly "com.example.contacts": {readonly 'title.label': "Contacts";readonly 'count.label_one': "{{count}} contact";readonly 'count.label_other': "{{count}} contacts";readonly 'add.label': "Add contact";readonly 'edit.label': "Edit contact";readonly 'delete.label': "Delete contact";readonly 'empty.message': "Choose a contact";readonly 'new-contact.name': "New contact";readonly 'role.viewer': "Can read the contact book";readonly 'role.editor': "Can change contacts";readonly 'role.admin': "Can change contacts and who has access";};};}]{'en-US': {[ns]: {const ns: "com.example.contacts"'title.label': 'Contacts','count.label_one': '{{count}} contact','count.label_other': '{{count}} contacts','add.label': 'Add contact','edit.label': 'Edit contact','delete.label': 'Delete contact','empty.message': 'Choose a contact','new-contact.name': 'New contact','role.viewer': 'Can read the contact book','role.editor': 'Can change contacts','role.admin': 'Can change contacts and who has access',},},},] asconst satisfiestype const = [{readonly 'en-US': {readonly "com.example.contacts": {readonly 'title.label': "Contacts";readonly 'count.label_one': "{{count}} contact";readonly 'count.label_other': "{{count}} contacts";readonly 'add.label': "Add contact";readonly 'edit.label': "Edit contact";readonly 'delete.label': "Delete contact";readonly 'empty.message': "Choose a contact";readonly 'new-contact.name': "New contact";readonly 'role.viewer': "Can read the contact book";readonly 'role.editor': "Can change contacts";readonly 'role.admin': "Can change contacts and who has access";};};}]Theme.import ThemeResource[];export Resourcecount.label_oneandcount.label_otherare two forms of one key,count.label. -
Mark the fields with icons.
Icon.Icondraws a sprite icon at the text’s size. The role’s tooltip text now comes from the resource, keyed by the role. Addsrc/icons/ContactsScreen.tsx:import * asHooks from '@dxos/react-ui/Hooks';import Hooksimport * asIcon from '@dxos/react-ui/Icon';import Iconimport * asLayout from '@dxos/react-ui/Layout';import Layout1 collapsed lineimport * asPanel from '@dxos/react-ui/Panel';import Panelimport * asStatus from '@dxos/react-ui/Status';import Status1 collapsed lineimport * 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[]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.
import {DeletePopover,const DeletePopover: ({ label, onDelete }: DeletePopoverProps) => React.JSX.ElementEditDialog } from '../overlays/ContactsScreen.tsx';const EditDialog: ({ label, contact, onSave }: EditDialogProps) => React.JSX.ElementThe editor from the last page, in a dialog that closes on Save.
import {ns } from './translations.ts';const ns: "com.example.contacts"/** Each field beside an icon that says what it is. */constContactDetail = ({const ContactDetail: ({ contact }: {contact?: Contact;}) => React.JSX.ElementEach field beside an icon that says what it is.
contact }: {contact: Contact | undefinedcontact?:contact?: Contact | undefinedContact }) => {type Contact = {id: string;name: string;email: string;role: string;}const {t } =const t: TFunction<Namespace<string>, KeyPrefix<Namespace<string>>>Hooks.import HooksuseTranslation(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 useTranslationns);const ns: "com.example.contacts"if (!contact) {contact: Contact | undefinedreturn <Status.import StatusEmptyconst Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>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
Emptypart on it.icon='ph--address-book--regular'>{icon?: string | undefinedA Phosphor icon above the message; decorative, since the message carries the statement.
t('empty.message')}</const t: TFunction<"empty.message", ReactI18NextChild | Iterable<ReactI18NextChild>, StringMap>(key: "empty.message" | "empty.message"[], options?: string | TOptions<StringMap> | undefined) => ReactI18NextChild | Iterable<ReactI18NextChild> (+1 overload)Status.import StatusEmpty>;const Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>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
Emptypart on it.}return (<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>).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>, "children" | "role" | "style"> & 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>{JSX.IntrinsicElements.h2: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>contact.contact: Contactname}</name: stringh2>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>, "children" | "role" | "style"> & 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.<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 | undefinedalign='center'>align?: Layout.Align | undefined<Icon.import IconIconconst 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='ph--envelope--regular' />icon: string<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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.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>, "children" | "role" | "style"> & 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.</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>).<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. */}<divJSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>tabIndex={0}>HTMLAttributes<HTMLDivElement>.tabIndex?: number | undefined<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 | undefinedalign='center'>align?: Layout.Align | undefined<Icon.import IconIconconst 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='ph--identification-badge--regular' />icon: string<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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.contact: Contactrole}</role: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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.</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>).</div>JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement></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}.t(`role.${const t: TFunction<`role.${string}`, ReactI18NextChild | Iterable<ReactI18NextChild>, StringMap>(key: `role.${string}` | `role.${string}`[], options?: string | TOptions<StringMap> | undefined) => ReactI18NextChild | Iterable<ReactI18NextChild> (+1 overload)contact.contact: Contactrole}`)}</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</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>).);};Each
iconprop is a whole name, which is howIconsPluginfinds it. A name put together at run time would not be in the sprite. -
Use the strings. The toolbar reads its text from
t. Add is an icon button whose label is both its tooltip and its name for screen readers. Edit and Delete take their labels as props, so we pass them in fromttoo.Add this to the same file:
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 * asHooks from '@dxos/react-ui/Hooks';import Hooks1 collapsed lineimport * asIcon from '@dxos/react-ui/Icon';import Iconimport * asLayout from '@dxos/react-ui/Layout';import Layoutimport * asPanel from '@dxos/react-ui/Panel';import Panel1 collapsed lineimport * asStatus from '@dxos/react-ui/Status';import Statusimport * asToolbar from '@dxos/react-ui/Toolbar';import Toolbar3 collapsed linesimport * 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 {ContactList } from '../layout/ContactsScreen.tsx';const ContactList: ({ contacts, selected, onSelect }: ContactListProps) => React.JSX.ElementOne row per contact; the list scrolls inside its own viewport.
import {DeletePopover,const DeletePopover: ({ label, onDelete }: DeletePopoverProps) => React.JSX.ElementEditDialog } from '../overlays/ContactsScreen.tsx';const EditDialog: ({ label, contact, onSave }: EditDialogProps) => React.JSX.ElementThe editor from the last page, in a dialog that closes on Save.
import {ns } from './translations.ts';const ns: "com.example.contacts"33 collapsed lines/** Each field beside an icon that says what it is. */constContactDetail = ({const ContactDetail: ({ contact }: {contact?: Contact;}) => React.JSX.ElementEach field beside an icon that says what it is.
contact }: {contact: Contact | undefinedcontact?:contact?: Contact | undefinedContact }) => {type Contact = {id: string;name: string;email: string;role: string;}const {t } =const t: TFunction<Namespace<string>, KeyPrefix<Namespace<string>>>Hooks.import HooksuseTranslation(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 useTranslationns);const ns: "com.example.contacts"if (!contact) {contact: Contact | undefinedreturn <Status.import StatusEmptyconst Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>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
Emptypart on it.icon='ph--address-book--regular'>{icon?: string | undefinedA Phosphor icon above the message; decorative, since the message carries the statement.
t('empty.message')}</const t: TFunction<"empty.message", ReactI18NextChild | Iterable<ReactI18NextChild>, StringMap>(key: "empty.message" | "empty.message"[], options?: string | TOptions<StringMap> | undefined) => ReactI18NextChild | Iterable<ReactI18NextChild> (+1 overload)Status.import StatusEmpty>;const Empty: React.ForwardRefExoticComponent<Omit<Status.EmptyProps, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>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
Emptypart on it.}return (<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>).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>, "children" | "role" | "style"> & 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>{JSX.IntrinsicElements.h2: React.DetailedHTMLProps<React.HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>contact.contact: Contactname}</name: stringh2>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>, "children" | "role" | "style"> & 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.<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 | undefinedalign='center'>align?: Layout.Align | undefined<Icon.import IconIconconst 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='ph--envelope--regular' />icon: string<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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.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>, "children" | "role" | "style"> & 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.</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>).<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. */}<divJSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>tabIndex={0}>HTMLAttributes<HTMLDivElement>.tabIndex?: number | undefined<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 | undefinedalign='center'>align?: Layout.Align | undefined<Icon.import IconIconconst 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='ph--identification-badge--regular' />icon: string<Typography.import TypographyTextconst Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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.contact: Contactrole}</role: stringTypography.import TypographyText>const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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.</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>).</div>JSX.IntrinsicElements.div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement></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}.t(`role.${const t: TFunction<`role.${string}`, ReactI18NextChild | Iterable<ReactI18NextChild>, StringMap>(key: `role.${string}` | `role.${string}`[], options?: string | TOptions<StringMap> | undefined) => ReactI18NextChild | Iterable<ReactI18NextChild> (+1 overload)contact.contact: Contactrole}`)}</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</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>).);};export constContactsScreen = () => {const ContactsScreen: () => React.JSX.Elementconst {t } =const t: TFunction<Namespace<string>, KeyPrefix<Namespace<string>>>Hooks.import HooksuseTranslation(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 useTranslationns);const ns: "com.example.contacts"const [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: stringconstcontact =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 | undefinedconsthandleAdd = () => {const handleAdd: () => voidconstcontact:const contact: ContactContact = {type Contact = {id: string;name: string;email: string;role: string;}id:id: stringcrypto.var crypto: CryptorandomUUID(),Crypto.randomUUID(): `${string}-${string}-${string}-${string}-${string}`The
randomUUID()method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator. Available only in secure contexts.name:name: stringt('new-contact.name'),const t: TFunction<"new-contact.name", string, StringMap>(key: "new-contact.name" | "new-contact.name"[], options?: string | TOptions<StringMap> | undefined) => string (+1 overload)email: '',email: stringrole: 'viewer',role: string};setContacts((const setContacts: (value: React.SetStateAction<Contact[]>) => voidcontacts) => [...contacts: Contact[]contacts,contacts: Contact[]contact]);const contact: ContactsetSelected(const setSelected: (value: React.SetStateAction<string | undefined>) => voidcontact.const contact: Contactid);id: string};consthandleSave = (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: ContactconsthandleDelete = (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 (<Panel.import PanelRoot>const Root: React.ForwardRefExoticComponent<Omit<Panel.RootProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>{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 TextA run of text that takes the free space and truncates; not an item, so roving focus skips it.
t('title.label')}</const t: TFunction<"title.label", ReactI18NextChild | Iterable<ReactI18NextChild>, StringMap>(key: "title.label" | "title.label"[], options?: string | TOptions<StringMap> | undefined) => ReactI18NextChild | Iterable<ReactI18NextChild> (+1 overload)Toolbar.import ToolbarText>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 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>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>export TextA run of text that takes the free space and truncates; not an item, so roving focus skips it.
t('count.label', {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)count:count: numberCount value used for plurals
contacts.const contacts: Contact[]length })}</Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
Toolbar.import ToolbarText>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 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>, "children" | "role" | "style"> & 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.<Button.import ButtonRootconst Root: React.ForwardRefExoticComponent<Omit<Button.RootProps, "className"> & {classNames?: ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLButtonElement>>export Rooticon='ph--plus--regular'icon?: string | undefinedLeading icon.
label={label?: string | undefinedVisible text;
childrentake precedence.Required: names the button (
aria-label) and shows in a Tooltip.t('add.label')}const t: TFunction<"add.label", string | undefined, StringMap>(key: "add.label" | "add.label"[], options?: string | TOptions<StringMap> | undefined) => string | undefined (+1 overload)iconOnlyiconOnly?: boolean | undefinedA control-sized square inset in a block-sized cell (follow-up 19), showing only the icon.
onClick={onClick?: React.MouseEventHandler<HTMLButtonElement> | undefinedhandleAdd} />const handleAdd: () => void{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={label: stringt('edit.label')}const t: TFunction<"edit.label", string, StringMap>(key: "edit.label" | "edit.label"[], options?: string | TOptions<StringMap> | undefined) => string (+1 overload)contact={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={label: stringt('delete.label')}const t: TFunction<"delete.label", string, StringMap>(key: "delete.label" | "delete.label"[], options?: string | TOptions<StringMap> | undefined) => string (+1 overload)onDelete={() =>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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>><ContactDetailconst ContactDetail: ({ contact }: {contact?: Contact;}) => React.JSX.ElementEach field beside an icon that says what it is.
contact={contact?: Contact | undefinedcontact} />const contact: Contact | undefined</Layout.import LayoutGrid>const Grid: React.ForwardRefExoticComponent<Omit<Layout.GridProps & {asChild?: boolean;}, "className"> & {classNames?: import("@dxos/ui-types").ClassNameValue;} & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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>, "children" | "role" | "style"> & 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.);};handleDeleteclears the selection, andContactDetailthen shows its hint.EditDialogandDeletePopovercome from the last page as they are, so the strings inside them are not in the resource yet. This screen also leaves out the toast. -
Register the resource and render the screen.
Theme.Providertakes our resource beside react-ui’s own. Insrc/main.tsx, import react-ui’stranslationsunder the nameuiTranslations, import ours and this page’sContactsScreen, and replace the render:import {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.
2 collapsed linesimport '@dxos/react-ui/theme.css';import * asTheme from '@dxos/react-ui/Theme';import Theme2 collapsed linesimport {translations asconst 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.";};};}]uiTranslations } from '@dxos/react-ui/translations';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.";};};}]import {ContactsScreen } from './icons/ContactsScreen.tsx';const ContactsScreen: () => React.JSX.Element2 collapsed linesimport {translations } from './icons/translations.ts';const translations: [{readonly 'en-US': {readonly "com.example.contacts": {readonly 'title.label': "Contacts";readonly 'count.label_one': "{{count}} contact";readonly 'count.label_other': "{{count}} contacts";readonly 'add.label': "Add contact";readonly 'edit.label': "Edit contact";readonly 'delete.label': "Delete contact";readonly 'empty.message': "Choose a contact";readonly 'new-contact.name': "New contact";readonly 'role.viewer': "Can read the contact book";readonly 'role.editor': "Can change contacts";readonly 'role.admin': "Can change contacts and who has access";};};}]createRoot(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[] | undefineduiTranslations, ...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.";};};}]translations]}>const translations: [{readonly 'en-US': {readonly "com.example.contacts": {readonly 'title.label': "Contacts";readonly 'count.label_one': "{{count}} contact";readonly 'count.label_other': "{{count}} contacts";readonly 'add.label': "Add contact";readonly 'edit.label': "Edit contact";readonly 'delete.label': "Delete contact";readonly 'empty.message': "Choose a contact";readonly 'new-contact.name': "New contact";readonly 'role.viewer': "Can read the contact book";readonly 'role.editor': "Can change contacts";readonly 'role.admin': "Can change contacts and who has access";};};}]<ContactsScreen />const ContactsScreen: () => React.JSX.Element</Theme.import ThemeProvider>,const Provider: ({ children, fallback, resourceExtensions, appNs, tx, themeMode, platform, }: Theme.ProviderProps) => React.JSX.Elementexport Provider);A resource that is missing from
resourceExtensionsshows on screen as its keys, such asadd.label.
Try it
Section titled “Try it”Delete contacts until one is left and watch the count. Press Add, then Edit to name the new contact.
What you can do now
Section titled “What you can do now”You can use icons by name and keep a screen’s strings in a resource. Next, Connect to ECHO stores the contacts in a database that syncs.