Graph Prop: isInteractive (#56)

* feat(props): add isInteractive

* refactor(selection): dont allow if not interactive

* feat(renderer): add class if is interactive

* chore(inactive): add tests

* refactor(inactive): no connection line, no edge selection

closes #49
This commit is contained in:
Moritz
2019-10-23 18:42:17 +02:00
committed by GitHub
parent cf4bd7199a
commit 873fb50b19
28 changed files with 2528 additions and 377 deletions
+46
View File
@@ -0,0 +1,46 @@
import React, { useState } from 'react';
import Graph, { MiniMap, Controls } from 'react-flow';
const initialElements = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
{ id: '3', data: { label: 'Node 3' }, position: { x: 400, y: 100 } },
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
{ id: 'e1-3', source: '1', target: '3' },
];
const EmptyGraph = () => {
const [isInteractive, setIsInteractive] = useState(false);
const onToggleInteractive = (evt) => {
setIsInteractive(evt.target.checked);
};
return (
<Graph
elements={initialElements}
style={{ width: '100%', height: '100%' }}
backgroundType="lines"
isInteractive={isInteractive}
>
<MiniMap />
<Controls />
<div
style={{ position: 'absolute', right: 10, top: 10, zIndex: 4 }}
>
<label>
interactive
<input
type="checkbox"
checked={isInteractive}
onChange={onToggleInteractive}
className="react-flow__interactive"
/>
</label>
</div>
</Graph>
);
}
export default EmptyGraph;
+4
View File
@@ -1,3 +1,7 @@
body {
font-family: sans-serif;
}
html, body {
margin: 0;
}
+4
View File
@@ -5,6 +5,7 @@ import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import CustomNodes from './CustomNodes';
import Basic from './Basic';
import Empty from './Empty';
import Inactive from './Inactive';
import './index.css';
@@ -17,6 +18,9 @@ ReactDOM.render((
<Route path="/empty">
<Empty />
</Route>
<Route path="/inactive">
<Inactive />
</Route>
<Route path="/">
<CustomNodes />
</Route>