Skip to content

Repository files navigation

react-lineto

Draw a line between two elements in React.

Build Status

Getting Started

yarn install
yarn run demo

Browse to localhost:4567.

Components

LineTo

Draw line between two DOM elements.

Example

import LineTo from 'react-lineto';
function render() {
return (
<div>
<div className="A">Element A</div>
<div className="B">Element B</div>
<LineTo from="A" to="B" />
</div>
);
}

Properties

NameTypeDescriptionExample Values
from*stringCSS class name of the first element
to*stringCSS class name of the second element
fromAnchorstringAnchor for starting point (Format: "x y")top right, bottom center, 100% 0
toAnchorstringAnchor for ending point (Format: "x y")top right, bottom center, 100% 0
bottomSpacenumberFor stepped lines, defines the bottom space20
steppedbooleanSpecify if line is stepped linefalse
delaynumberForce render after delay (ms)
classNamestringDesired CSS className for the rendered element
borderstringLine decoration (CSS border property syntax)1px solid #000
zIndexnumberZ-index offset
styleobjectOverride default styles{ border: 'none', height: '2px', background-image: 'linear-gradient(261deg, #fd7700, #fd4400)' }
withinstringCSS class name of the desired container

Normal Line:

 *
\
\
\
\
\
*

Stepped Line:

 * | | | ----- /\
| | Bottom space
| |
* \/

* Required

Line

Draw line using pixel coordinates (relative to viewport).

Example

import { Line } from 'react-lineto';
function render() {
return (
<Line x0={0} y0={0} x1={10} y1={10} />
);
}

Properties

NameTypeDescriptionExample Values
x0*numberFirst X coordinate
y0*numberFirst Y coordinate
x1*numberSecond X coordinate
y1*numberSecond Y coordinate
classNamestringDesired CSS className for the rendered element
borderstringLine decoration (CSS border property syntax)1px solid #000
zIndexnumberZ-index offset
styleobjectOverride default styles{ border: 'none', height: '2px', background-image: 'linear-gradient(261deg, #fd7700, #fd4400)' }
withinstringCSS class name of the desired container

* Required

Labels

To add a label, simply add it as a child:

import LineTo, { Line } from 'react-lineto';
function render() {
return (
<div>
<div className="A">Element A</div>
<div className="B">Element B</div>
<LineTo from="A" to="B">
Line from A to B
</LineTo>
<Line x0={0} y0={0} x1={10} y1={10}>
Line from (0,0) to (10,10)
</Line>
</div>
);
}

About

Draw a line between two elements in React

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages