From 990016b03682f7513e4edb5af342194350f18622 Mon Sep 17 00:00:00 2001 From: 1ilit Date: Tue, 19 Sep 2023 15:46:43 +0300 Subject: [PATCH] Shapes go brrr --- src/App.js | 5 ++--- src/diagram/index.jsx | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/diagram/index.jsx diff --git a/src/App.js b/src/App.js index f3827bf..8317037 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,9 @@ import './App.css'; +import Diagram from './diagram'; function App() { return ( -

- Hello world! -

+ ); } diff --git a/src/diagram/index.jsx b/src/diagram/index.jsx new file mode 100644 index 0000000..2634373 --- /dev/null +++ b/src/diagram/index.jsx @@ -0,0 +1,44 @@ +import React, { useEffect, useRef } from "react"; +import { dia, shapes } from "jointjs"; + +function Diagram() { + const canvas = useRef(null); + + useEffect(() => { + const graph = new dia.Graph(); + + new dia.Paper({ + el: document.getElementById("canvas"), + background: { + color: "#F1F92A", + }, + model: graph, + height: window.height, + width: window.width, + gridSize: 1, + interactive: true, + }); + + const rect = new shapes.standard.Rectangle(); + rect.position(100, 100); + rect.resize(100, 40); + rect.attr({ + body: { + fill: "#7039FF", + }, + label: { + text: "hi", + fill: "white", + }, + }); + rect.addTo(graph); + }, []); + + return ( + <> +
+ + ); +} + +export default Diagram;