All Projects → pierpo → React Archer

pierpo / React Archer

Licence: mit
🏹 Draw arrows between React elements 🖋

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Archer

Csshake
CSS classes to move your DOM!
Stars: ✭ 4,531 (+580.33%)
Mutual labels:  dom
Html2canvas
Screenshots with JavaScript
Stars: ✭ 25,113 (+3670.72%)
Mutual labels:  dom
Datafusion
DataFusion has now been donated to the Apache Arrow project
Stars: ✭ 611 (-8.26%)
Mutual labels:  arrow
Awesome
🚀A curated list of awesome resources related to Alpine.
Stars: ✭ 502 (-24.62%)
Mutual labels:  dom
Web Series
📚 现代 Web 开发语法基础与工程实践,涵盖 Web 开发基础、前端工程化、应用架构、性能与体验优化、混合开发、React 实践、Vue 实践、WebAssembly 等多方面。
Stars: ✭ 666 (+0%)
Mutual labels:  dom
React Log
React for the Console
Stars: ✭ 553 (-16.97%)
Mutual labels:  dom
Ijk
Transforms arrays into virtual dom trees; a terse alternative to JSX and h
Stars: ✭ 452 (-32.13%)
Mutual labels:  dom
Ramjet
Morph DOM elements from one state to another with smooth animations and transitions
Stars: ✭ 5,455 (+719.07%)
Mutual labels:  dom
React Svg
🎨 A React component that injects SVG into the DOM.
Stars: ✭ 536 (-19.52%)
Mutual labels:  dom
Html To Image
✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
Stars: ✭ 595 (-10.66%)
Mutual labels:  dom
Motus
Animation library that mimics CSS keyframes when scrolling.
Stars: ✭ 502 (-24.62%)
Mutual labels:  dom
Scrollbear
A modern tool that maintains scroll position when images loaded
Stars: ✭ 523 (-21.47%)
Mutual labels:  dom
Cash
An absurdly small jQuery alternative for modern browsers.
Stars: ✭ 5,714 (+757.96%)
Mutual labels:  dom
Html5 Dom Document Php
A better HTML5 parser for PHP.
Stars: ✭ 477 (-28.38%)
Mutual labels:  dom
Nanomorph
🚅 - Hyper fast diffing algorithm for real DOM nodes
Stars: ✭ 621 (-6.76%)
Mutual labels:  dom
Bunny
BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
Stars: ✭ 473 (-28.98%)
Mutual labels:  dom
Cheerio
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Stars: ✭ 24,616 (+3596.1%)
Mutual labels:  dom
Nanohtml
🐉 HTML template strings for the Browser with support for Server Side Rendering in Node.
Stars: ✭ 651 (-2.25%)
Mutual labels:  dom
Nanojs
Minimal standalone JS library for DOM manipulation
Stars: ✭ 636 (-4.5%)
Mutual labels:  dom
Displayjs
A simple JavaScript framework for building ambitious UIs 😊
Stars: ✭ 590 (-11.41%)
Mutual labels:  dom

react-archer

CircleCI

🏹 Draw arrows between DOM elements in React 🖋

Installation

npm install react-archer --save or yarn add react-archer

Example

Try it out!

Example

import { ArcherContainer, ArcherElement } from 'react-archer';

const rootStyle = { display: 'flex', justifyContent: 'center' };
const rowStyle = { margin: '200px 0', display: 'flex', justifyContent: 'space-between', }
const boxStyle = { padding: '10px', border: '1px solid black', };

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

        <div style={rowStyle}>
          <ArcherElement
            id="element2"
            relations={[
              {
                targetId: 'element3',
                targetAnchor: 'left',
                sourceAnchor: 'right',
                style: { strokeColor: 'blue', strokeWidth: 1 },
                label: <div style={{ marginTop: '-20px' }}>Arrow 2</div>,
              },
            ]}
          >
            <div style={boxStyle}>Element 2</div>
          </ArcherElement>

          <ArcherElement id="element3">
            <div style={boxStyle}>Element 3</div>
          </ArcherElement>

          <ArcherElement
            id="element4"
            relations={[
              {
                targetId: 'root',
                targetAnchor: 'right',
                sourceAnchor: 'left',
                label: 'Arrow 3',
              },
            ]}
          >
            <div style={boxStyle}>Element 4</div>
          </ArcherElement>
        </div>
      </ArcherContainer>
    </div>
  );
}

export default App;

API

ArcherContainer

Props

Name Type Description
strokeColor string A color string '#ff0000'
strokeWidth number A size in px
strokeDasharray string Adds dashes to the stroke. It has to be a string representing an array of sizes. See some SVG strokes documentation.
noCurves boolean Set this to true if you want angles instead of curves
offset number Optional number for space between element and start/end of stroke
svgContainerStyle Style Style of the SVG container element. Useful if you want to add a z-index to your SVG container to draw the arrows under your elements, for example.
children React.Node
endShape Object An object containing the props to configure the "end shape" of the arrow. Can be one of arrow (default) or circle. See ShapeType for a complete list of available options.

Instance methods

If you access to the ref of your ArcherContainer, you will access the refreshScreen method. This will allow you to have more control on when you want to re-draw the arrows.

ArcherElement

Name Type Description
id string The id that will identify the Archer Element. Should only contain alphanumeric characters and standard characters that you can find in HTML ids.
children React.Node | (ArcherContext) => React.Node ⚠️ Must be a single element or a function of the internal context. If you are passing a custom component, it should be wrapped in a div or you should forward the reference (see this)
relations Relation[]

The Relation type has the following shape:

{
  targetId: string,
  targetAnchor: 'top' | 'bottom' | 'left' | 'right' | 'middle',
  sourceAnchor: 'top' | 'bottom' | 'left' | 'right' | 'middle',
  label: React.Node,
  style: ArcherStyle,
}

Please note that the middle anchor does not look very good: the curve won't look nice and the arrow marker will have a little offset. The issue won't be solved before a long time.

The ArcherStyle type has the following shape:

{
  strokeColor: string,
  strokeWidth: number,
  strokeDasharray: number,
  noCurves: boolean,
  endShape: Object
}

Troubleshooting

My arrows don't re-render correctly...

Try using the refreshScreen instance method on your ArcherContainer element. You can access it through the ref of the component.

Call refreshScreen when the event that you need is triggered (onScroll etc.).

TODO

  • Automatic anchoring option
  • Add a Code Sandbox
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].