Fragiola

API: primitives (@fragiola/flow-react, @fragiola/flow-vue, @fragiola/flow-svelte, @fragiola/flow-angular)

EdgeToolbar

Flow.EdgeToolbar places your buttons on an edge, outside the zoom so they keep their size, shown while the edge is selected by default.

Flow.EdgeToolbar goes inside Flow.Edge (or anywhere in the root with an edgeId). It is portalled into Flow.Root, outside the zoom, centred at the point edge-toolbar-by gives: the edge's label point (position="label", the default) or one of its ends ("source", "target"), moved by offset pixels. So it keeps its size at any zoom and follows the edge as its nodes move and the viewport pans or zooms. Nothing is drawn before the edge has a path. By default it is shown while its edge is selected (selection()); open decides instead. Presses and the wheel over it are left to it. It renders only your children.

Edge labels
Gallery
function Edge({ edge }: { edge: FlowEdge<Types> }) {
    const { model } = useFlow<Types, typeof features>();
    return (
        <Flow.Edge edge={edge}>
            <Flow.EdgePath />
            <Flow.EdgeToolbar role="toolbar" aria-label="Edge actions" offset={{ x: 0, y: -24 }}>
                <button type="button" aria-label="Delete" onClick={() => model.run("edge.remove", { edgeId: edge.id })}>
                    <Trash2Icon />
                </button>
            </Flow.EdgeToolbar>
        </Flow.Edge>
    );
}

A toolbar has no role: give it role="toolbar" and a label when it holds several buttons.

At a point, aligned

point stands the toolbar at a flow point of yours instead of one of the edge's (where the user clicked the edge, a point you computed on its path): absolute flow coordinates, followed as the viewport pans and zooms. alignX and alignY say which of the toolbar's own edges goes at the point: "start" (its left, its top), "center" (the default) or "end" (its right, its bottom). So alignY="end" sets it above the point, whatever its height:

<Flow.EdgeToolbar point={clicked} alignX="start" alignY="end" offset={{ x: 4, y: -4 }} open={clicked !== undefined}>
    …
</Flow.EdgeToolbar>

clicked is yours: the point of the root's onEdgeClick event, kept in your state.

Props

EdgeToolbarProps extends the common primitive props and every div attribute.

proptypedefaultdescription
edgeIdstringthe enclosing Flow.Edge'sits edge
position"label" | "source" | "target""label"the point of the edge it stands at: its label point, its source or its target end
pointXYnonea flow point it stands at instead (absolute flow coordinates); wins over position
offsetXY{ x: 0, y: 0 }a screen offset from that point, in pixels
alignX"start" | "center" | "end""center"which of its edges goes at the point across: its left, centre or right
alignY"start" | "center" | "end""center"which of its edges goes at the point down: its top, centre or bottom
openbooleanwhile its edge is selectedwhether it is shown
childrenReactNodenoneyour buttons

State

EdgeToolbarState, what className, style and render receive:

fieldtypedescription
edgeIdstringits edge
position"label" | "source" | "target"the point of the edge it stands at
anchorEdgeToolbarPositionwhere it is anchored, in pixels relative to the root, with the share of its size that goes there (anchorX, anchorY: alignX, alignY) (engine reads)

Data attributes

attributevalue
data-flow-part"toolbar"
data-flow-idits edge's id

Structural style

position: absolute; top: 0; left: 0; transform: translate(<x>px, <y>px) translate(<-anchorX × 100>%, <-anchorY × 100>%) at its anchor (by default -50%, -50%: the toolbar's centre on the point).