Fragiola

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.

Node toolbar
Gallery
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.

proptypedefaultdescription
nodeIdstringthe enclosing Flow.Node'sits node
nodeIdsreadonly string[]noneseveral 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
sideHandleSide"top"the node's side it stands on
align"start" | "center" | "end""center"where along that side
offsetnumber10the gap between the node and the toolbar, in pixels
openbooleanwhile its node (every node of nodeIds) is selectedwhether it is shown
childrenReactNodenoneyour buttons

State

NodeToolbarState, what className, style and render receive:

fieldtypedescription
nodeIdstring | undefinedits node (undefined for several nodes' toolbar)
nodeIdsreadonly string[]the nodes it stands beside: nodeIds, or its one node
positionNodeToolbarPositionits anchor, in pixels relative to the root (engine reads)
sideHandleSidethe side it stands on

Data attributes

attributevalue
data-flow-part"toolbar"
data-flow-idits 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.