Git Product home page Git Product logo

react-dnd-diagrams's Introduction

React DnD Diagrams

A customizable React drag and drop NPM package for building interactive diagrams. This is the most powerful and developer friendly visual diagram builder for your app.

Overview
ScreenRecording2024-03-23at11 55 21AM-ezgif com-video-to-gif-converter

Live Demo

Check out the live demo here: https://github.com/tharindukumarasiri.github.io/react-dnd-diagrams (Source Code)

Installation

The easiest way to use React DnD Diagram is to install it from NPM and include it in your own React build process.

npm install react-dnd-diagrams --save

Usage

Require the DnDFlow component and render it with JSX:

import React from "react";
import { render } from "react-dom";

import DnDFlow from "react-dnd-diagrams";

const Categories = {
  SHAPES: "Shapes",
  STRUCTURES: "Other",
};

const parentNodes = ["Table", "LineChart"];

const ShapesData = {
  Square: {
    image: (
      <rect
        x="0.5"
        y="0.5"
        width="25"
        height="25"
        vectorEffect="non-scaling-stroke"
      />
    ),
    viewBox: "0 0 26 26",
    category: [Categories.SHAPES],
    keepAspectRatio: false,
  },
  Table: {
    image: (
      <>
        <g>
          <path d="M245.9,5.2v89.7H4.7V5.2H245.9 M246.9,4.2H3.7v91.7h243.1V4.2L246.9,4.2z" />
        </g>
        <g>
          <line class="st0" x1="59.5" y1="4.8" x2="59.5" y2="95" />
        </g>
        <g>
          <line class="st0" x1="158" y1="4.8" x2="158" y2="95" />
        </g>
        <line class="st0" x1="4.6" y1="21.2" x2="246.4" y2="21.2" />
      </>
    ),
    viewBox: "0 0 251 101",
    size: { width: 100, height: 100 },
    keepAspectRatio: false,
    hideTextInput: true,
    hideShape: true,
    category: [Categories.STRUCTURES],
  },
};

const App = (props) => {
  return (
    <div>
      <DnDFlow
        categories={Categories}
        parentNodes={parentNodes}
        shapesData={ShapesData}
        DrawingContent={null}
        saveDiagram={(data) => {
          console.log(data);
        }}
      />
    </div>
  );
};

render(<App />, document.getElementById("app"));

See the example source for a reference implementation.

Properties

property type description
DrawingContent Object data Takes the design JSON and loads it in the canvas
saveDiagram Function callback Returns the design JSON in a callback function
categories Object {[key]: id :[value]: category name} Categories of of shapes in sidebar
shapesData Object {[key]: name :[value]: shape props} Shape data including the SVG
parentNodes Array Node names that has the ability to group(act as parent nodes)

Shape Properties

All shapes are used from SVG format, please remove the <svg> tag and add the viewBox values as given in the example above.

  • image {<HTMLElement>} svg of the shape without the tag and other elements outside of the tag
  • viewBox {String} viewBox of the svg
  • category {Array} list of category ids, to include inside of the categories
  • size {Object { width: number, height: number }} Size of the shape when initially dropped (optional)
  • keepAspectRatio {Boolean} (default: true) ability to keep the aspect ratio when resizing (optional)
  • hideTextInput {Boolean} (default: false) hide the text input inside of the shape
  • hideShape {Boolean} (default: false) hide svg shape

Tools and options

Image upload

ScreenRecording2024-03-23at4 53 44PM-ezgif com-video-to-gif-converter

Layers

ScreenRecording2024-03-23at5 02 40PM-ezgif com-video-to-gif-converter

*This library is in early stages more features and customization coming soon.

All bug reports and PRs are appreciated

License

Copyright (c) 2024 [MIT] Licensed.

react-dnd-diagrams's People

Contributors

tharindukumarasiri avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.