Skip to Content
示例Styling

基本样式

React Flow 带有默认样式和基础样式。此示例展示了基础样式的外观。每个流程都必须使用基础样式才能正常工作。 你可以在主题指南中找到更多信息。

🌐 React Flow comes with a default style and a base style. This example shows how the base style looks. The base style is mandatory for every flow to work. You can find more information in the theming guide.

import React, { useCallback } from 'react'; import { ReactFlow, Background, Controls, MiniMap, useNodesState, useEdgesState, addEdge, Position, } from '@xyflow/react'; import '@xyflow/react/dist/base.css'; const nodeDefaults = { sourcePosition: Position.Right, targetPosition: Position.Left, }; const initialNodes = [ { id: '1', position: { x: 0, y: 150 }, data: { label: 'base style 1' }, ...nodeDefaults, }, { id: '2', position: { x: 250, y: 0 }, data: { label: 'base style 2' }, ...nodeDefaults, }, { id: '3', position: { x: 250, y: 150 }, data: { label: 'base style 3' }, ...nodeDefaults, }, { id: '4', position: { x: 250, y: 300 }, data: { label: 'base style 4' }, ...nodeDefaults, }, ]; const initialEdges = [ { id: 'e1-2', source: '1', target: '2', }, { id: 'e1-3', source: '1', target: '3', }, { id: 'e1-4', source: '1', target: '4', }, ]; const Flow = () => { const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); const onConnect = useCallback( (params) => setEdges((els) => addEdge(params, els)), [], ); return ( <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} fitView > <Background /> <Controls /> <MiniMap /> </ReactFlow> ); }; export default Flow;
Last updated on