npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-draw-arrow

v1.0.24

Published

React-draw-arrow is a project that easily different various components with a simple arrow.

Downloads

18

Readme

react-draw-arrow

Connect components with a simple arrow

Getting Started

# Install the library
npm install react-draw-arrow
yarn add react-draw-arrow
import { DrawArrow, WaterDrop } from "react-draw-arrow";

const App = () => {
  const box1 = useRef<HTMLDivElement>(null);
  const box2 = useRef<HTMLDivElement>(null);
  return (
    <>
      <div ref={box1} />
      <div ref={box2} />
      <DrawArrow
        mainComponent={box1}
        childComponents={[box2]}
        pathConfig={{ blur: true }}
        animate
        animationConfig={{
          delay: 1,
          duration: 3,
          nItems: 3,
          curveStyle: "beizer",
          blur: true,
        }}
        animationInput={(props) => <WaterDrop {...props} />}
      />
    </>
  );
};

Examples

  • https://codesandbox.io/s/suspicious-butterfly-x6hk2g
  • https://codesandbox.io/s/lucid-dijkstra-dn8qpq

Simple use case

import { DrawArrow, WaterDrop } from "react-draw-arrow";

const App = () => {
  const box1 = useRef<HTMLDivElement>(null);
  const box2 = useRef<HTMLDivElement>(null);
  return (
    <>
      <div ref={box1} />
      <div ref={box2} />
      <DrawArrow
        mainComponent={box1}
        childComponents={[box2]}
        pathConfig={{ blur: true }}
        animate
        animationConfig={{
          delay: 1,
          duration: 3,
          nItems: 3,
          curveStyle: "beizer",
          blur: true,
        }}
        animationInput={(props) => <WaterDrop {...props} />}
      />
    </>
  );
};

Using react-draggable

import { DrawArrow, WaterDrop } from "react-draw-arrow";
import Draggable from "react-draggable";

const App = () => {
  const box1 = useRef<HTMLDivElement>(null);
  const box2 = useRef<HTMLDivElement>(null);
  return (
    <>
       <Draggable
          bounds="body"
          position={{x: 100, y: 50}}
        >
          <div ref={box1}>
            Box 1
          </div>
        </Draggable>
       <Draggable
          bounds="body"
          position={{x: 300, y: 600}}
        >
          <div ref={box2}>
            Box 2
          </div>
        </Draggable>
      <DrawArrow
        mainComponent={box1}
        childComponents={[box2]}
        pathConfig={{ blur: true }}
        animate
        animationConfig={{
          delay: 1,
          duration: 3,
          nItems: 3,
          curveStyle: "beizer",
          blur: true,
        }}
        animationInput={(props) => <WaterDrop {...props} />}
      />
    </>
  );
};

Animation components

  • Circle
  • WaterDrop

Circle

import { DrawArrow, Circle } from "react-draw-arrow";

const App = () => {
  const box1 = useRef<HTMLDivElement>(null);
  const box2 = useRef<HTMLDivElement>(null);
  return (
    <>
      <div ref={box1} />
      <div ref={box2} />
      <DrawArrow
        mainComponent={box1}
        childComponents={[box2]}
        pathConfig={{ blur: true }}
        animate
        animationConfig={{
          delay: 1,
          duration: 3,
          nItems: 3,
          curveStyle: "beizer",
          blur: true,
        }}
        animationInput={(props) => <Circle {...props} />}
      />
    </>
  );
};

WaterDrop

import { DrawArrow, WaterDrop } from "react-draw-arrow";

const App = () => {
  const box1 = useRef<HTMLDivElement>(null);
  const box2 = useRef<HTMLDivElement>(null);
  return (
    <>
      <div ref={box1} />
      <div ref={box2} />
      <DrawArrow
        mainComponent={box1}
        childComponents={[box2]}
        pathConfig={{ blur: true }}
        animate
        animationConfig={{
          delay: 1,
          duration: 3,
          nItems: 3,
          curveStyle: "beizer",
          blur: true,
        }}
        animationInput={(props) => <WaterDrop {...props} />}
      />
    </>
  );
};

Custom animation component

Animation components are embedded inside "g" svg component.

const DEFAULT_COLOR = "black";

const AnimationComponent = ({
  path,
  duration,
  delay,
  color,
  reverse,
}: AnimationComponentProps) => {
  const [running, setRunning] = useState<boolean>(false);
  const ref = useRef<SVGElement>(null);
  const backgroundColor = color ? color : DEFAULT_COLOR;

  function toggleRunning(isRunnging: boolean) {
    setRunning(isRunnging);
  }

  useEffect(() => {
    const animationRef = ref.current;
    if (animationRef) {
      animationRef.addEventListener("beginEvent", () => toggleRunning(true));
      animationRef.addEventListener("endEvent", () => toggleRunning(false));
    }
    return () => {
      if (animationRef) {
        animationRef.removeEventListener("beginEvent", () =>
          toggleRunning(true)
        );
        animationRef.removeEventListener("beginEvent", () =>
          toggleRunning(false)
        );
      }
    };
  }, []);
  return (
       <circle r={8} fill={running ? backgroundColor : "none"}>
        <animateMotion
          dur={duration}
          repeatCount="indefinite"
          path={path}
          keyPoints={reverse ? "1;0" : "0;1"}
          keyTimes="0;1"
          begin={delay}
          ref={ref}
          offset={-100}
          startOffset={-100}
        />
      </circle>
      />
  );
};

Props

| Property | Description | Type | | -------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------- | | mainComponent? | Main component | RefObject or string | | childComponents? | Child components | RefObject[] or string[] | | animate? | Animate arrow | boolean | | showDots? | Show control position,start point and end point af arrow | boolean | | showStartArrow? | Show start arrow marker | boolean | | showEndArrow? | Show end arrow marker | boolean | | label? | Label | string | | animationInput? | Input of animation component | (props: AnimationComponentProps ) => React.ReactNode | | labelInput? | Input of label component | React.ReactNode | | animationConfig? | Animation configuration | AnimationConfigProps | | pathConfig? | Path configuration | PathConfigProps | | markerConfiguration? | Marker configuration | MarkerConfigProps |

AnimationConfigProps

| Property | Description | Type | | ------------- | ------------- | ------------- | | duration? | Duration of animation |number | delay? | Delay of animation |number | nItems? | Number of animation items | number | nItems? | Number of animation items | number | reverse? |Animation reverse mode | number | curveStyle? | Curve style of arrow | number | blur? | Blur mode | boolean | offset? | Offset of control point regarding curve (defualt 60) | "beizer" -"straight" - "curve" | color? | Animation color | string

AnimationComponentProps

| Property | Description | Type | | ------------- | ------------- | ------------- | | duration? | Duration of animation |number | delay? | Delay of animation |number | path? | Path of animation | string | reverse? |Animation reverse mode | number | color? | Animation color | string

PathConfigProps

| Property | Description | Type | | ------------- | ------------- | ------------- | | strokeWidth? | Width of arrow (defualt 3) |number | isStrokeArray? | If arrow is dashed |boolean | blur? | Blur mode in path | boolean | color? | Path color, this case could be gradient | GradientColor

MarkerConfigProps

| Property | Description | Type | | ------------- | ------------- | ------------- | | scale? | Scale of marker | number | color? | Marker color (default #f00) | string

GradientColor

| Property | Description | Type | | ------------- | ------------- | ------------- | | start? | Start color | string | end? | End color | string