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.
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.
| prop | type | default | description |
|---|---|---|---|
edgeId | string | the enclosing Flow.Edge's | its edge |
position | "label" | "source" | "target" | "label" | the point of the edge it stands at: its label point, its source or its target end |
point | XY | none | a flow point it stands at instead (absolute flow coordinates); wins over position |
offset | XY | { 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 |
open | boolean | while its edge is selected | whether it is shown |
children | ReactNode | none | your buttons |
State
EdgeToolbarState, what className, style and render receive:
| field | type | description |
|---|---|---|
edgeId | string | its edge |
position | "label" | "source" | "target" | the point of the edge it stands at |
anchor | EdgeToolbarPosition | where 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
| attribute | value |
|---|---|
data-flow-part | "toolbar" |
data-flow-id | its 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).