diff --git a/example/src/Undirectional/CustomNode.tsx b/example/src/Undirectional/CustomNode.tsx new file mode 100644 index 00000000..5b0c7b48 --- /dev/null +++ b/example/src/Undirectional/CustomNode.tsx @@ -0,0 +1,19 @@ +import React, { memo, FC, CSSProperties } from 'react'; + +import { Handle, Position, NodeProps } from 'react-flow-renderer'; + +const nodeStyles: CSSProperties = { padding: '10px 15px', border: '1px solid #ddd' }; + +const CustomNode: FC = () => { + return ( +
+
node
+ + + + +
+ ); +}; + +export default memo(CustomNode); diff --git a/example/src/Undirectional/index.tsx b/example/src/Undirectional/index.tsx new file mode 100644 index 00000000..f5251275 --- /dev/null +++ b/example/src/Undirectional/index.tsx @@ -0,0 +1,78 @@ +import React, { useState, useCallback } from 'react'; + +import ReactFlow, { + NodeTypesType, + addEdge, + useZoomPanHelper, + ReactFlowProvider, + Elements, + Connection, + Edge, + ElementId, + ConnectionLineType, + ConnectionMode, +} from 'react-flow-renderer'; +import CustomNode from './CustomNode'; + +const initialElements: Elements = [ + { + id: '1', + type: 'custom', + position: { x: 150, y: 100 }, + }, + { + id: '2', + type: 'custom', + position: { x: 300, y: 100 }, + }, + { + id: '3', + type: 'custom', + position: { x: 450, y: 100 }, + }, +]; + +const nodeTypes: NodeTypesType = { + custom: CustomNode, +}; + +let id = 4; +const getId = (): ElementId => `${id++}`; + +const UpdateNodeInternalsFlow = () => { + const [elements, setElements] = useState(initialElements); + const onConnect = (params: Connection | Edge) => + setElements((els) => addEdge({ ...params, type: 'smoothstep' }, els)); + const { project } = useZoomPanHelper(); + + const onPaneClick = useCallback( + (evt) => + setElements((els) => + els.concat({ + id: getId(), + position: project({ x: evt.clientX, y: evt.clientY - 40 }), + type: 'custom', + }) + ), + [project] + ); + + return ( + + ); +}; + +const WrappedFlow = () => ( + + + +); + +export default WrappedFlow; diff --git a/example/src/UseUpdateNodeInternals/index.tsx b/example/src/UseUpdateNodeInternals/index.tsx index 135e5cb2..8840d338 100644 --- a/example/src/UseUpdateNodeInternals/index.tsx +++ b/example/src/UseUpdateNodeInternals/index.tsx @@ -22,7 +22,6 @@ const initialElements: Elements = [ type: 'custom', data: { label: 'Node 1', handleCount: initialHandleCount }, position: { x: 250, y: 5 }, - className: 'light', }, ]; diff --git a/example/src/index.tsx b/example/src/index.tsx index 9c6b930b..017accad 100644 --- a/example/src/index.tsx +++ b/example/src/index.tsx @@ -23,6 +23,7 @@ import Layout from './Layouting'; import SwitchFlows from './Switch'; import UseZoomPanHelper from './UseZoomPanHelper'; import UseUpdateNodeInternals from './UseUpdateNodeInternals'; +import Undirectional from './Undirectional'; import './index.css'; @@ -111,6 +112,10 @@ const routes = [ path: '/useupdatenodeinternals', component: UseUpdateNodeInternals, }, + { + path: '/undirectional', + component: Undirectional, + }, ]; const Header = withRouter(({ history, location }) => {