diff --git a/docs/guide/demos/flowEditor/btnGroup.tsx b/docs/guide/demos/flowEditor/btnGroup.tsx index 388ec83..10e9eae 100644 --- a/docs/guide/demos/flowEditor/btnGroup.tsx +++ b/docs/guide/demos/flowEditor/btnGroup.tsx @@ -1,5 +1,36 @@ -export const BtnGroup = (props) => { - const { editor } = props; +import { useFlowEditor } from '@ant-design/pro-flow'; +import { useCallback, useEffect, useState } from 'react'; + +export const BtnGroup = () => { + const editor = useFlowEditor(); + const [count, setCount] = useState(0); + + const addMockNode = useCallback(() => { + if (editor) { + const id = Math.random(); + + editor.addNode({ + id: `a${id}`, + type: 'StringNode', + position: { x: count * 200, y: 100 }, + data: { + title: 'String Node', + handles: { + source: 'a1-source', + target: 'a1-target', + }, + }, + }); + + setCount((c) => c + 1); + } + }, [editor, count]); + + useEffect(() => { + if (editor) { + addMockNode(); + } + }, []); return ( <> @@ -18,27 +49,7 @@ export const BtnGroup = (props) => { 取消全选
- +