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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZYQAumujy5kXaOKurr6zgTP2krHrFVXi2kj8seRYrlvq2GssUjReh5MiVpQbLFQNy9HsmcasqpBNVsXytWTw0ZDjA=

Tree

import { Tree, createStaticTreeModel } from '@dxos/react-ui-list';
Terminal window
npm install @dxos/react-ui-list @effect/atom-react

A tree is a list of nested rows that open and close. Tree reads its rows from a model and reports what the user does to them.

The model keeps each row’s open and current state in an atom.

Wrap your app in RegistryProvider from @effect/atom-react. This is best practice, because your app then controls the registry that the tree reads. Without a provider, the tree reads the library’s default registry.

Each part handles keyboard navigation and the current and selected states. Each part also sets its own spacing, so put the tree in a panel’s body with no padding around it.

Part What it is
Tree.Root The root, which takes the model and an id. It reports onOpenChange and onSelect
Tree.Label The tree’s name
Tree.Content The scroll area for the rows. Its child can render each row
Tree.Item One row, or a section header
Tree.ItemIndicator The caret that opens a branch
Tree.ItemIcon The row’s icon
Tree.ItemText The row’s label
Tree.ItemCount A count badge
Tree.ItemActions The controls at the row’s end. They show on a row that is hovered, focused, selected or holding an open menu
Tree.ItemGroup A section header
Tree.ItemGroupLabel The section header’s label
Tree.Empty The placeholder shown while there are no rows

createStaticTreeModel makes a model over data you already hold. You tell it how to find an item’s children and what to show for the item.

Example (Holding folders in memory)

type
type Folder = {
id: string;
name: string;
items: Folder[];
}
Folder
= {
id: string
id
: string;
name: string
name
: string;
items: Folder[]
items
:
type Folder = {
id: string;
name: string;
items: Folder[];
}
Folder
[] };
const
const ROOT: Folder
ROOT
:
type Folder = {
id: string;
name: string;
items: Folder[];
}
Folder
= {
id: string
id
: 'root',
name: string
name
: 'Contacts',
items: Folder[]
items
: [
{
id: string
id
: 'work',
name: string
name
: 'Work',
items: Folder[]
items
: [
{
id: string
id
: 'ada',
name: string
name
: 'Ada Lovelace',
items: Folder[]
items
: [] },
{
id: string
id
: 'grace',
name: string
name
: 'Grace Hopper',
items: Folder[]
items
: [] },
],
},
{
id: string
id
: 'family',
name: string
name
: 'Family',
items: Folder[]
items
: [{
id: string
id
: 'alan',
name: string
name
: 'Alan Turing',
items: Folder[]
items
: [] }],
},
],
};

Each Folder keeps its children in items.

When the user opens a row or selects it, the tree calls onOpenChange or onSelect. Write the new state to the row’s atom, and the tree draws it.

Example (Drawing the folders as a tree)

import {
const RegistryContext: React.Context<AtomRegistry>

Provides a React context that supplies the AtomRegistry used by Atom hooks and hydration helpers, defaulting to a standalone registry when no provider is present.

When to use

Use to supply an existing AtomRegistry through React context when hooks or hydration helpers need to share registry state that is managed outside RegistryProvider.

@see ― RegistryProvider for creating and providing a registry for a React subtree

@stability ― unstable

@category ― context

@since ― 4.0.0

RegistryContext
} from '@effect/atom-react/RegistryContext';
import {
function useContext<T>(context: React.Context<T>): T

Accepts a context object (the value returned from React.createContext) and returns the current context value, as given by the nearest context provider for the given context.

useContext
,
function useMemo<T>(factory: () => T, deps: React.DependencyList): T

useMemo will only recompute the memoized value when one of the deps has changed.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useMemo

useMemo
,
function useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
} from 'react';
import {
const Tree: {
Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
};
Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>;
Content: {
({ children, gutter, rowInset, scroll }: TreeContentProps): React.JSX.Element;
displayName: string;
};
... 8 more ...;
Empty: React.ForwardRefExoticComponent<TreeEmptyProps & React.RefAttributes<HTMLDivElement>>;
}

Hierarchical list on Ark's tree-view, driven by TreeModel atoms, with Ark's part names on the Next row vocabulary: Root (model, virtual, animate, activation policy, drag and drop), Label, Content (the scrolling tree element; a row renderer as children), Item (one row), ItemIndicator (caret), ItemIcon, ItemText, ItemCount, ItemActions (trailing controls shown on the row in play), ItemGroup/ItemGroupLabel (section headers) and Empty.

Tree
, type
type TreeSelectEvent<T extends { id: string; } = any> = {
item: T;
path: string[];
current: boolean;
range?: {
item: T;
path: string[];
}[];
} & SelectModifiers
TreeSelectEvent
,
const createStaticTreeModel: <T extends {
id: string;
}>(root: T, options: StaticTreeModelOptions<T>) => StaticTreeModel<T>

Adapts a plain in-memory tree to the

TreeModel

atom-family contract the Tree consumes.

Tree's only entry point is five atom families, which is the right shape for a store that is already reactive per node (ECHO, a live app graph) but roughly a hundred lines of plumbing for a caller that just holds an array — the cost that kept ObjectsTree, ProcessTree and the stories on hand-rolled renderers instead. Open/current state is owned here, keyed by path, so the same node appearing at two paths stays independent.

createStaticTreeModel
} from '@dxos/react-ui-list';
import * as
import Typography
Typography
from '@dxos/react-ui/Typography';
/** A tree over an in-memory folder structure; open and selected rows are kept in the model. */
export const
const FolderTree: () => React.JSX.Element

A tree over an in-memory folder structure; open and selected rows are kept in the model.

FolderTree
= () => {
const
const registry: AtomRegistry
registry
=
useContext<AtomRegistry>(context: React.Context<AtomRegistry>): AtomRegistry

Accepts a context object (the value returned from React.createContext) and returns the current context value, as given by the nearest context provider for the given context.

useContext
(
const RegistryContext: React.Context<AtomRegistry>

Provides a React context that supplies the AtomRegistry used by Atom hooks and hydration helpers, defaulting to a standalone registry when no provider is present.

When to use

Use to supply an existing AtomRegistry through React context when hooks or hydration helpers need to share registry state that is managed outside RegistryProvider.

@see ― RegistryProvider for creating and providing a registry for a React subtree

@stability ― unstable

@category ― context

@since ― 4.0.0

RegistryContext
);
const [
const selected: string[] | undefined
selected
,
const setSelected: React.Dispatch<React.SetStateAction<string[] | undefined>>
setSelected
] =
useState<string[]>(): [string[] | undefined, React.Dispatch<React.SetStateAction<string[] | undefined>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useState

useState
<string[]>();
const
const model: StaticTreeModel<Folder>
model
=
useMemo<StaticTreeModel<Folder>>(factory: () => StaticTreeModel<Folder>, deps: React.DependencyList): StaticTreeModel<Folder>

useMemo will only recompute the memoized value when one of the deps has changed.

@version ― 16.8.0

@see ― https://react.dev/reference/react/useMemo

useMemo
(
() =>
createStaticTreeModel<Folder>(root: Folder, options: StaticTreeModelOptions<Folder>): StaticTreeModel<Folder>

Adapts a plain in-memory tree to the

TreeModel

atom-family contract the Tree consumes.

Tree's only entry point is five atom families, which is the right shape for a store that is already reactive per node (ECHO, a live app graph) but roughly a hundred lines of plumbing for a caller that just holds an array — the cost that kept ObjectsTree, ProcessTree and the stories on hand-rolled renderers instead. Open/current state is owned here, keyed by path, so the same node appearing at two paths stays independent.

createStaticTreeModel
(
const ROOT: Folder
ROOT
, {
getChildren: (item: Folder) => readonly Folder[] | undefined

Children of a node; undefined or empty marks a leaf. Required — there is no shape to guess.

getChildren
: (
folder: Folder
folder
) =>
folder: Folder
folder
.
items: Folder[]
items
,
getProps?: ((item: Folder, path: string[]) => Partial<TreeItemDataProps>) | undefined

Merged over the derived defaults (id, label, and parentOf/count for branches).

getProps
: (
folder: Folder
folder
) => ({
label?: Label | undefined
label
:
folder: Folder
folder
.
name: string
name
,
icon?: string | undefined
icon
:
folder: Folder
folder
.
items: Folder[]
items
.
Array<Folder>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
> 0
? 'ph--folder--regular'
: 'ph--user--regular',
}),
}),
[],
);
const
const handleOpenChange: ({ path, open, }: {
path: string[];
open: boolean;
}) => void
handleOpenChange
= ({
path: string[]
path
,
open: boolean
open
,
}: {
path: string[]
path
: string[];
open: boolean
open
: boolean;
}) => {
const
const state: Writable<TreeNodeState, TreeNodeState>
state
=
const model: StaticTreeModel<Folder>
model
.
StaticTreeModel<Folder>.stateAtom: (path: string[]) => Writable<TreeNodeState>

Writable per-path state, for wiring the tree's onOpenChange / selection callbacks.

stateAtom
(
path: string[]
path
);
const registry: AtomRegistry
registry
.
AtomRegistry.set: <TreeNodeState, {
open: boolean;
current: boolean;
}>(atom: Writable<TreeNodeState, {
open: boolean;
current: boolean;
}>, value: {
open: boolean;
current: boolean;
}) => void
set
(
const state: Writable<TreeNodeState, TreeNodeState>
state
, { ...
const registry: AtomRegistry
registry
.
AtomRegistry.get: <TreeNodeState>(atom: Atom<TreeNodeState>) => TreeNodeState
get
(
const state: Writable<TreeNodeState, TreeNodeState>
state
),
open: boolean
open
});
};
const
const handleSelect: ({ path, current }: TreeSelectEvent<Folder>) => void
handleSelect
= ({
path: string[]
path
,
current: boolean

The state the row is taken to: in multiple mode a meta-click reports the toggled state.

current
}:
type TreeSelectEvent<T extends { id: string; } = any> = {
item: T;
path: string[];
current: boolean;
range?: {
item: T;
path: string[];
}[];
} & SelectModifiers
TreeSelectEvent
<
type Folder = {
id: string;
name: string;
items: Folder[];
}
Folder
>) => {
if (
const selected: string[] | undefined
selected
) {
const
const previous: Writable<TreeNodeState, TreeNodeState>
previous
=
const model: StaticTreeModel<Folder>
model
.
StaticTreeModel<Folder>.stateAtom: (path: string[]) => Writable<TreeNodeState>

Writable per-path state, for wiring the tree's onOpenChange / selection callbacks.

stateAtom
(
const selected: string[]
selected
);
const registry: AtomRegistry
registry
.
AtomRegistry.set: <TreeNodeState, {
current: boolean;
open: boolean;
}>(atom: Writable<TreeNodeState, {
current: boolean;
open: boolean;
}>, value: {
current: boolean;
open: boolean;
}) => void
set
(
const previous: Writable<TreeNodeState, TreeNodeState>
previous
, { ...
const registry: AtomRegistry
registry
.
AtomRegistry.get: <TreeNodeState>(atom: Atom<TreeNodeState>) => TreeNodeState
get
(
const previous: Writable<TreeNodeState, TreeNodeState>
previous
),
current: boolean
current
: false });
}
const
const state: Writable<TreeNodeState, TreeNodeState>
state
=
const model: StaticTreeModel<Folder>
model
.
StaticTreeModel<Folder>.stateAtom: (path: string[]) => Writable<TreeNodeState>

Writable per-path state, for wiring the tree's onOpenChange / selection callbacks.

stateAtom
(
path: string[]
path
);
const registry: AtomRegistry
registry
.
AtomRegistry.set: <TreeNodeState, {
current: boolean;
open: boolean;
}>(atom: Writable<TreeNodeState, {
current: boolean;
open: boolean;
}>, value: {
current: boolean;
open: boolean;
}) => void
set
(
const state: Writable<TreeNodeState, TreeNodeState>
state
, { ...
const registry: AtomRegistry
registry
.
AtomRegistry.get: <TreeNodeState>(atom: Atom<TreeNodeState>) => TreeNodeState
get
(
const state: Writable<TreeNodeState, TreeNodeState>
state
),
current: boolean
current
});
const setSelected: (value: React.SetStateAction<string[] | undefined>) => void
setSelected
(
current: boolean

The state the row is taken to: in multiple mode a meta-click reports the toggled state.

current
?
path: string[]
path
:
var undefined
undefined
);
};
return (
<>
<
const Tree: {
Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
};
Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>;
Content: {
({ children, gutter, rowInset, scroll }: TreeContentProps): React.JSX.Element;
displayName: string;
};
... 8 more ...;
Empty: React.ForwardRefExoticComponent<TreeEmptyProps & React.RefAttributes<HTMLDivElement>>;
}

Hierarchical list on Ark's tree-view, driven by TreeModel atoms, with Ark's part names on the Next row vocabulary: Root (model, virtual, animate, activation policy, drag and drop), Label, Content (the scrolling tree element; a row renderer as children), Item (one row), ItemIndicator (caret), ItemIcon, ItemText, ItemCount, ItemActions (trailing controls shown on the row in play), ItemGroup/ItemGroupLabel (section headers) and Empty.

Tree
.
type Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
}
Root
id: string

Prefix of every row's path, and the drag scope: trees sharing it accept each other's rows.

id
='contacts'
model: TreeModel<Folder>
model
={
const model: StaticTreeModel<Folder>
model
}
rootId?: string | undefined

The model node whose children are the top rows; undefined asks the model for its root.

rootId
={
const model: StaticTreeModel<Folder>
model
.
StaticTreeModel<Folder>.rootId: string

Id of the synthetic root; childIds(undefined) resolves to this node's children.

rootId
}
onOpenChange?: ((params: {
item: Folder;
path: string[];
open: boolean;
}) => void) | undefined
onOpenChange
={
const handleOpenChange: ({ path, open, }: {
path: string[];
open: boolean;
}) => void
handleOpenChange
}
onSelect?: ((event: TreeSelectEvent<Folder>) => void) | undefined

A row activation (click, Enter, or the machine's selection). Option-click on a branch toggles it instead, and a click on the current row reports it again (the machine emits nothing for it).

onSelect
={
const handleSelect: ({ path, current }: TreeSelectEvent<Folder>) => void
handleSelect
}
>
<
const Tree: {
Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
};
Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>;
Content: {
({ children, gutter, rowInset, scroll }: TreeContentProps): React.JSX.Element;
displayName: string;
};
... 8 more ...;
Empty: React.ForwardRefExoticComponent<TreeEmptyProps & React.RefAttributes<HTMLDivElement>>;
}

Hierarchical list on Ark's tree-view, driven by TreeModel atoms, with Ark's part names on the Next row vocabulary: Root (model, virtual, animate, activation policy, drag and drop), Label, Content (the scrolling tree element; a row renderer as children), Item (one row), ItemIndicator (caret), ItemIcon, ItemText, ItemCount, ItemActions (trailing controls shown on the row in play), ItemGroup/ItemGroupLabel (section headers) and Empty.

Tree
.
type Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>
Label
srOnly?: boolean | undefined

Names the tree for assistive tech only, for a tree whose surroundings already title it.

srOnly
>Contacts</
const Tree: {
Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
};
Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>;
Content: {
({ children, gutter, rowInset, scroll }: TreeContentProps): React.JSX.Element;
displayName: string;
};
... 8 more ...;
Empty: React.ForwardRefExoticComponent<TreeEmptyProps & React.RefAttributes<HTMLDivElement>>;
}

Hierarchical list on Ark's tree-view, driven by TreeModel atoms, with Ark's part names on the Next row vocabulary: Root (model, virtual, animate, activation policy, drag and drop), Label, Content (the scrolling tree element; a row renderer as children), Item (one row), ItemIndicator (caret), ItemIcon, ItemText, ItemCount, ItemActions (trailing controls shown on the row in play), ItemGroup/ItemGroupLabel (section headers) and Empty.

Tree
.
type Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>
Label
>
<
const Tree: {
Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
};
Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>;
Content: {
({ children, gutter, rowInset, scroll }: TreeContentProps): React.JSX.Element;
displayName: string;
};
... 8 more ...;
Empty: React.ForwardRefExoticComponent<TreeEmptyProps & React.RefAttributes<HTMLDivElement>>;
}

Hierarchical list on Ark's tree-view, driven by TreeModel atoms, with Ark's part names on the Next row vocabulary: Root (model, virtual, animate, activation policy, drag and drop), Label, Content (the scrolling tree element; a row renderer as children), Item (one row), ItemIndicator (caret), ItemIcon, ItemText, ItemCount, ItemActions (trailing controls shown on the row in play), ItemGroup/ItemGroupLabel (section headers) and Empty.

Tree
.
type Content: {
({ children, gutter, rowInset, scroll }: TreeContentProps): React.JSX.Element;
displayName: string;
}
Content
/>
</
const Tree: {
Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
};
Label: React.ForwardRefExoticComponent<Omit<TreeViewLabelProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & {
srOnly?: boolean;
} & React.RefAttributes<HTMLHeadingElement>>;
Content: {
({ children, gutter, rowInset, scroll }: TreeContentProps): React.JSX.Element;
displayName: string;
};
... 8 more ...;
Empty: React.ForwardRefExoticComponent<TreeEmptyProps & React.RefAttributes<HTMLDivElement>>;
}

Hierarchical list on Ark's tree-view, driven by TreeModel atoms, with Ark's part names on the Next row vocabulary: Root (model, virtual, animate, activation policy, drag and drop), Label, Content (the scrolling tree element; a row renderer as children), Item (one row), ItemIndicator (caret), ItemIcon, ItemText, ItemCount, ItemActions (trailing controls shown on the row in play), ItemGroup/ItemGroupLabel (section headers) and Empty.

Tree
.
type Root: {
<T extends {
id: string;
}>({ model, rootId, id, path, size, columns, multiline, selectionMode, selectionFollowsFocus, virtual, draggable, dragPreview, leavesAcceptChildren, dropBelowExpanded, dropAtEnd, hideDragSource, indentGuides, animate, canSelect, canDrop, getDropKind, onOpenChange, onSelect, onItemHover, onKeyDown, onDrop, ref, children, }: TreeRootProps<T>): React.JSX.Element;
displayName: string;
}
Root
>
<
import Typography
Typography
.
const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {
asChild?: boolean;
}, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>
export Text

Text 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>; asChild puts the metrics on a heading or other text element instead.

Text
tone?: Typography.TextTone | undefined

Emphasis below the default (DESIGN.md "Text emphasis"): description for secondary content, subdued for interface text.

tone
='muted'>
{
const selected: string[] | undefined
selected
? `Selected ${
const selected: string[]
selected
.
Array<string>.at(index: number): string | undefined

Returns the item located at the specified index.

@param ― index The zero-based index of the desired code unit. A negative index will count back from the last item.

at
(-1)}` : 'Nothing selected'}
</
import Typography
Typography
.
const Text: React.ForwardRefExoticComponent<Omit<Typography.TextProps & {
asChild?: boolean;
}, "className"> & {
classNames?: import("@dxos/ui-types").ClassNameValue;
} & Pick<React.HTMLAttributes<Element>, "style" | "role" | "children"> & React.RefAttributes<HTMLParagraphElement>>
export Text

Text 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>; asChild puts the metrics on a heading or other text element instead.

Text
>
</>
);
};

getChildren returns a folder’s items, and getProps gives each row its label and icon. handleOpenChange and handleSelect write open and current to the atom that model.stateAtom returns for the row’s path.

A tree over App Graph, such as Composer’s navigation, gets its model from the graph instead.