refactor(floating-edges-example): comments and cleanup

This commit is contained in:
moklick
2021-10-14 12:29:05 +02:00
parent ab2391fd51
commit ceb96201de
5 changed files with 74 additions and 55 deletions
+15 -14
View File
@@ -3,8 +3,6 @@ import React, { useState } from 'react';
import ReactFlow, {
removeElements,
addEdge,
MiniMap,
Controls,
Background,
OnLoadParams,
EdgeTypesType,
@@ -14,6 +12,8 @@ import ReactFlow, {
ArrowHeadType,
} from 'react-flow-renderer';
import './style.css';
import FloatingEdge from './FloatingEdge';
import FloatingConnectionLine from './FloatingConnectionLine';
import { createElements } from './utils';
@@ -30,22 +30,23 @@ const NodeAsHandleFlow = () => {
const [elements, setElements] = useState<Elements>(initialElements);
const onElementsRemove = (elementsToRemove: Elements) => setElements((els) => removeElements(elementsToRemove, els));
const onConnect = (params: Connection | Edge) =>
setElements((els) => addEdge({ ...params, type: 'floating', arrowHeadType: ArrowHeadType.Arrow }, els));
return (
<ReactFlow
elements={elements}
onElementsRemove={onElementsRemove}
onConnect={onConnect}
onLoad={onLoad}
edgeTypes={edgeTypes}
connectionLineComponent={FloatingConnectionLine}
>
<MiniMap />
<Controls />
<Background />
</ReactFlow>
<div className="floatingedges">
<ReactFlow
elements={elements}
onElementsRemove={onElementsRemove}
onConnect={onConnect}
onLoad={onLoad}
edgeTypes={edgeTypes}
connectionLineComponent={FloatingConnectionLine}
>
<Background />
</ReactFlow>
</div>
);
};