Skip to main content

react-archer

🏹 Draw arrows between DOM elements in React πŸ–‹

react-archer lets you declaratively draw arrows between elements. Wrap your layout in an ArcherContainer, mark the endpoints with ArcherElement, and describe the connections with relations β€” the library measures the DOM and draws the SVG arrows for you.

Installation​

npm install react-archer --save

Quick start​

The example below is live β€” it is the same component that runs in the project's example app, rendered right here in the docs:

Loading example…
BasicArrows.tsx
import React from 'react';
import ArcherContainer from '../src/ArcherContainer/ArcherContainer';
import ArcherElement from '../src/ArcherElement/ArcherElement';
import Box from './components/Box';
const rootStyle = {
display: 'flex',
justifyContent: 'center',
};
const rowStyle = {
margin: '200px 0',
display: 'flex',
justifyContent: 'space-between',
};

const BasicArrows = () => {
return (
<div
style={{
height: '500px',
margin: '50px',
}}
>
<ArcherContainer strokeColor="#6366f1">
<div style={rootStyle}>
<ArcherElement
id="root"
relations={[
{
targetId: 'element2',
targetAnchor: 'top',
sourceAnchor: 'bottom',
style: {
strokeDasharray: '5,5',
},
},
]}
>
<Box>Root</Box>
</ArcherElement>
</div>

<div style={rowStyle}>
<ArcherElement
id="element2"
relations={[
{
targetId: 'element3',
style: {
strokeColor: '#ec4899',
strokeWidth: 1,
},
label: (
<div
style={{
marginTop: '-20px',
}}
>
Arrow 2
</div>
),
},
]}
>
<Box>Element 2</Box>
</ArcherElement>

<ArcherElement id="element3">
<Box>Element 3</Box>
</ArcherElement>

<ArcherElement
id="element4"
relations={[
{
targetId: 'root',
label: 'Arrow 3',
},
]}
>
<Box>Element 4</Box>
</ArcherElement>
</div>
</ArcherContainer>
</div>
);
};

export default BasicArrows;

Head over to Examples for more advanced scenarios (dynamic elements, custom anchors, styled relations, interactive arrows, drag & drop), or to the API reference for the full list of props.