API: primitives (@fragiola/flow-react, @fragiola/flow-vue, @fragiola/flow-svelte, @fragiola/flow-angular)
NodeToolbar
Flow.NodeToolbar places your buttons next to a node, outside the zoom so they keep their size, shown while the node is selected by default.
Flow.NodeToolbar goes inside Flow.Node (or anywhere in the root with a nodeId). It is
portalled into Flow.Root, outside the zoom, at the anchor node-toolbar-by gives: on the node's
side, aligned to its align, offset pixels away. So it keeps its size at any zoom and follows
the node as it moves. By default it is shown while its node is selected (selection()); open
decides instead. With nodeIds it stands beside several nodes' bounds (a toolbar for the
selection), anywhere in the root, shown while every one of them is selected. Presses and the wheel
over it are left to it. It renders only your children.
function Toolbar({ node }: { node: FlowNode<Types> }) {
const { model } = useFlow<Types, typeof features>();
return (
<Flow.NodeToolbar role="toolbar" aria-label={`${node.data.text}: actions`} side="top" offset={8}>
<button type="button" aria-label="Delete" onClick={() => model.run("node.remove", { nodeId: node.id })}>
<Trash2Icon />
</button>
</Flow.NodeToolbar>
);
}A toolbar has no role: give it role="toolbar" and a label when it holds several buttons.
Side and alignment
side is the node's side the toolbar stands on, and align where along it: "start" (the left
of a top or bottom side, the top of a left or right one), "center" (the default) or "end".
offset is the gap in pixels. A toolbar below a node, flush with its right edge:
<Flow.NodeToolbar side="bottom" align="end" offset={6}>…</Flow.NodeToolbar>Props
NodeToolbarProps extends the common primitive props and
every div attribute.
| prop | type | default | description |
|---|---|---|---|
nodeId | string | the enclosing Flow.Node's | its node |
nodeIds | readonly string[] | none | several nodes it stands beside (their bounds) instead of one: when not empty it wins over nodeId, needs no enclosing node, and the toolbar is shown while every one of them is selected |
side | HandleSide | "top" | the node's side it stands on |
align | "start" | "center" | "end" | "center" | where along that side |
offset | number | 10 | the gap between the node and the toolbar, in pixels |
open | boolean | while its node (every node of nodeIds) is selected | whether it is shown |
children | ReactNode | none | your buttons |
State
NodeToolbarState, what className, style and render receive:
| field | type | description |
|---|---|---|
nodeId | string | undefined | its node (undefined for several nodes' toolbar) |
nodeIds | readonly string[] | the nodes it stands beside: nodeIds, or its one node |
position | NodeToolbarPosition | its anchor, in pixels relative to the root (engine reads) |
side | HandleSide | the side it stands on |
Data attributes
| attribute | value |
|---|---|
data-flow-part | "toolbar" |
data-flow-id | its node's id (none for several nodes') |
Structural style
position: absolute; top: 0; left: 0; transform: translate(<x>px, <y>px) translate(<-anchorX × 100>%, <-anchorY × 100>%)
at its anchor.