ActionToolbar draws a list of actions as a toolbar. When the row is too narrow, it moves actions into an overflow
menu.
An action is a label, an icon and the function it runs. You build the list with MenuBuilder and
useMenuBuilder. Because the list is data, other code can add to it. This is how PLEX plugins add buttons to each
other’s toolbars.
The actions live 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 toolbar reads. Without a provider, the toolbar reads the library’s default registry.
Add the package’s strings from @dxos/react-ui-menu/translations to the resourceExtensions of Theme.Provider.
A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a
plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮,
TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a
single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as
custom items (MenuBuilder.custom), labels as text items.
Convenience wrapper around useMenuActions that creates the backing atom inline.
Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads
it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when
the action graph is composed from local state (e.g. a toolbar driven by component state).
Read reactive state via get inside the builder; deps should hold only stable references.
useMenuBuilder } from'@dxos/react-ui-menu';
3
import*as
import Typography
Typographyfrom'@dxos/react-ui/Typography';
4
5
/** A toolbar built from actions: each action is a label, an icon and the function it runs. */
6
exportconst
constFormatToolbar: () =>React.JSX.Element
A toolbar built from actions: each action is a label, an icon and the function it runs.
Convenience wrapper around useMenuActions that creates the backing atom inline.
Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads
it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when
the action graph is composed from local state (e.g. a toolbar driven by component state).
Read reactive state via get inside the builder; deps should hold only stable references.
A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a
plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮,
TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a
single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as
custom items (MenuBuilder.custom), labels as text items.
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.
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>
41
</>
42
);
43
};
44
iconOnly leaves Bold and Italic as icons, and placement puts Share at the far end of the row. Each action’s
function records its name in state, and the text under the toolbar shows the last one run.
A switch shows whether something is on. Pass the state as checked, and list it in the dependencies, so
useMenuBuilder rebuilds the actions when the state changes.
Example (Showing word wrap as a switch)
1
import {
functionuseState<S>(initialState: S | (() =>S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1overload)
Returns a stateful value, and a function to update it.
A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a
plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮,
TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a
single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as
custom items (MenuBuilder.custom), labels as text items.
Convenience wrapper around useMenuActions that creates the backing atom inline.
Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads
it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when
the action graph is composed from local state (e.g. a toolbar driven by component state).
Read reactive state via get inside the builder; deps should hold only stable references.
useMenuBuilder } from'@dxos/react-ui-menu';
3
4
/** A switch shows its state in the toolbar; the deps rebuild the actions when the state changes. */
5
exportconst
constViewToolbar: () =>React.JSX.Element
A switch shows its state in the toolbar; the deps rebuild the actions when the state changes.
Convenience wrapper around useMenuActions that creates the backing atom inline.
Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads
it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when
the action graph is composed from local state (e.g. a toolbar driven by component state).
Read reactive state via get inside the builder; deps should hold only stable references.
A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a
plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮,
TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a
single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as
custom items (MenuBuilder.custom), labels as text items.
ActionToolbar {...
const menu: MenuActions
menu}
alwaysActive?: boolean | undefined
alwaysActive />;
18
};
19
wrap is both the switch’s checked value and the one dependency, and the switch’s function flips it.
In a PLEX plugin, other plugins add actions to an object’s node in App Graph.
graphActions reads those actions from the graph, so you can add them to your toolbar.
Pass the surface’s attendableId, so the toolbar is active while its surface has the user’s attention.
Pass onAction to run a graph action. useActionRunner from @dxos/plugin-graph gives you one.
Example (Adding other plugins’ actions to a toolbar)
A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a
plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮,
TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a
single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as
custom items (MenuBuilder.custom), labels as text items.
Read a node's contributed actions from the app-graph as menu ActionGraphProps, for splicing into a
hand-built toolbar via MenuBuilder.subgraph(graphActions(graph, get, nodeId)). Reactive: reads the
graph's action atoms through get, so contributed actions appear/disappear as extensions update.
@idiom ― org.dxos.react-ui-menu.graphActionsToolbar
applies: Splicing a node's app-graph-contributed toolbar actions into a hand-built object toolbar
instead-of: Reading graph.actions(nodeId) and filtering/wiring nodes/edges by hand in every toolbar
uses: graphActions, MenuBuilder , useMenuBuilder related: org.dxos.react-ui-menu.toolbarMenu
Convenience wrapper around useMenuActions that creates the backing atom inline.
Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads
it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when
the action graph is composed from local state (e.g. a toolbar driven by component state).
Read reactive state via get inside the builder; deps should hold only stable references.
useMenuBuilder } from'@dxos/react-ui-menu';
3
4
/**
5
* In a plugin, the toolbar also shows the actions other plugins add to the object's node in App Graph.
6
* `onAction` runs a graph action. Get one from `useActionRunner` in `@dxos/plugin-graph`.
In a plugin, the toolbar also shows the actions other plugins add to the object's node in App Graph.
onAction runs a graph action. Get one from useActionRunner in @dxos/plugin-graph.
Convenience wrapper around useMenuActions that creates the backing atom inline.
Pass a builder thunk and a dependency list — the hook memoizes Atom.make(build) and threads
it through useMenuActions. Saves the useMemo(() => Atom.make(...), deps) boilerplate when
the action graph is composed from local state (e.g. a toolbar driven by component state).
Read reactive state via get inside the builder; deps should hold only stable references.
Read a node's contributed actions from the app-graph as menu ActionGraphProps, for splicing into a
hand-built toolbar via MenuBuilder.subgraph(graphActions(graph, get, nodeId)). Reactive: reads the
graph's action atoms through get, so contributed actions appear/disappear as extensions update.
@idiom ― org.dxos.react-ui-menu.graphActionsToolbar
applies: Splicing a node's app-graph-contributed toolbar actions into a hand-built object toolbar
instead-of: Reading graph.actions(nodeId) and filtering/wiring nodes/edges by hand in every toolbar
uses: graphActions, MenuBuilder , useMenuBuilder related: org.dxos.react-ui-menu.toolbarMenu
A toolbar driven from a MenuActions. Each item's placement puts it in the start or end zone of a row; a
plain named group renders inline and others extend it (MenuBuilder.extend); the overflow menu (⋮,
TOOLBAR_OVERFLOW_ID) ends the first row and takes collapsible items while a row is too narrow. One row renders as a
single Toolbar.Root (which takes the props and ref); more stack one per row. Hand-written controls join the graph as
custom items (MenuBuilder.custom), labels as text items.
ActionToolbar {...
const menu: MenuActions
menu}
attendableId?: string | undefined
The toolbar is dimmed (still operable) while this attendable lacks attention, unless alwaysActive.
attendableId={
attendableId: string
attendableId}
onAction?: ActionExecutor | undefined
onAction={
onAction: ActionExecutor
onAction} />
33
);
34
};
35
ObjectToolbar has one action of its own, Refresh. subgraph adds the actions that graphActions reads from the
graph, and isToolbarAction keeps the ones marked for the toolbar.