Skip to Content
示例Edges

连接线

连接线是当你点击并从一个句柄拖出时看到的线。它表示一个可能的边,并且可以吸附到附近的有效句柄上。 你可以通过传递一个渲染该线的 React 组件来实现你自己的连接线。你可以在自定义连接线文档中找到传递的属性。

🌐 A Connection Line is what you see when you click and drag out from a handle. It represents a possible edge and can snap to valid handles in close proximity. You can implement your own Connection Line by passing a React component rendering the line. You can find the passed props in the custom connection line docs.

import React, { useCallback } from 'react'; import { ReactFlow, useNodesState, useEdgesState, addEdge, Background, } from '@xyflow/react'; import '@xyflow/react/dist/style.css'; import CustomNode from './CustomNode'; import ConnectionLine from './ConnectionLine'; const initialNodes = [ { id: 'connectionline-1', type: 'custom', data: { label: 'Node 1' }, position: { x: 250, y: 5 }, }, ]; const nodeTypes = { custom: CustomNode, }; const ConnectionLineFlow = () => { const [nodes, _, onNodesChange] = useNodesState(initialNodes); const [edges, setEdges, onEdgesChange] = useEdgesState([]); const onConnect = useCallback( (params) => setEdges((eds) => addEdge(params, eds)), [], ); return ( <ReactFlow nodes={nodes} edges={edges} nodeTypes={nodeTypes} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} connectionLineComponent={ConnectionLine} onConnect={onConnect} fitView fitViewOptions={{ padding: 0.2, }} > <Background /> </ReactFlow> ); }; export default ConnectionLineFlow;
Last updated on