Edge Label
A dedicated label component designed for use on an edge within a diagram.
The EdgeLabel component provides a consistent and unified design, following the styling conventions prepared for edges.
The state of the label (such as hover, selection, and disabled) is managed externally.
Therefore, dedicated props are exposed to reflect these states visually.
The component extends a standard HTMLDivElement, enabling flexibility in layout and positioning.
For example, you can use CSS transforms or absolute positioning to control the label's placement on the edge.
The content of the label can be any valid ReactNode, allowing full customization.
Note: By default,
EdgeLabelusesposition: absoluteto properly position the label based on thelabelXandlabelYparameters provided by ReactFlow. This ensures the label appears at the correct location on the edge. When usingEdgeLabeloutside of a diagram context, keep in mind that it may require additional wrapper elements or layout adjustments, as its absolute positioning removes it from the normal document flow.
function Example() { return ( <div style={{ display: 'flex', gap: '8px', flexWrap: 'wrap' }}> <EdgeLabel style={{ position: 'relative' }}>Edge Label</EdgeLabel> <EdgeLabel style={{ position: 'relative' }} type="compound"> <DiamondsFour /> Edge Label </EdgeLabel> <EdgeLabel style={{ position: 'relative' }} type="compound" state="selected" > <DiamondsFour /> Edge Label </EdgeLabel> <EdgeLabel style={{ position: 'relative' }} type="compound" state="disabled" > <DiamondsFour /> Edge Label </EdgeLabel> <EdgeLabel style={{ position: 'relative' }} type="icon"> <DiamondsFour /> </EdgeLabel> </div> ); }