chore(examples): add onEdgeUpdate

This commit is contained in:
moklick
2021-03-14 15:32:46 +01:00
parent 83da698aa4
commit 47f536967c
+10
View File
@@ -11,6 +11,7 @@ import ReactFlow, {
ElementId, ElementId,
ConnectionLineType, ConnectionLineType,
ConnectionMode, ConnectionMode,
updateEdge,
} from 'react-flow-renderer'; } from 'react-flow-renderer';
import CustomNode from './CustomNode'; import CustomNode from './CustomNode';
@@ -30,6 +31,12 @@ const initialElements: Elements = [
type: 'custom', type: 'custom',
position: { x: 450, y: 100 }, position: { x: 450, y: 100 },
}, },
{
id: 'e1-2',
source: '2',
target: '3',
sourceHandle: 'right',
},
]; ];
const nodeTypes: NodeTypesType = { const nodeTypes: NodeTypesType = {
@@ -44,6 +51,8 @@ const UpdateNodeInternalsFlow = () => {
const onConnect = (params: Connection | Edge) => const onConnect = (params: Connection | Edge) =>
setElements((els) => addEdge({ ...params, type: 'smoothstep' }, els)); setElements((els) => addEdge({ ...params, type: 'smoothstep' }, els));
const { project } = useZoomPanHelper(); const { project } = useZoomPanHelper();
const onEdgeUpdate = (oldEdge: Edge, newConnection: Connection) =>
setElements((els) => updateEdge(oldEdge, newConnection, els));
const onPaneClick = useCallback( const onPaneClick = useCallback(
(evt) => (evt) =>
@@ -65,6 +74,7 @@ const UpdateNodeInternalsFlow = () => {
onPaneClick={onPaneClick} onPaneClick={onPaneClick}
connectionLineType={ConnectionLineType.SmoothStep} connectionLineType={ConnectionLineType.SmoothStep}
connectionMode={ConnectionMode.Loose} connectionMode={ConnectionMode.Loose}
onEdgeUpdate={onEdgeUpdate}
/> />
); );
}; };