Merge branch 'feat/node-toolbar' of github.com:wbkd/react-flow into feat/node-toolbar
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import ReactFlow, { BaseEdge, EdgeLabelRenderer, EdgeProps, getSmoothStepPath, ReactFlowProvider } from 'reactflow';
|
||||
import * as simpleflow from '../../fixtures/simpleflow';
|
||||
|
||||
function CustomEdge(props: EdgeProps) {
|
||||
const [path, labelX, labelY] = getSmoothStepPath(props);
|
||||
return (
|
||||
<>
|
||||
<BaseEdge path={path} labelX={labelX} labelY={labelY} />
|
||||
<EdgeLabelRenderer>
|
||||
<div className="label">{props.id}</div>
|
||||
</EdgeLabelRenderer>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const simpleflow1 = { ...simpleflow };
|
||||
simpleflow1.edges = [...simpleflow1.edges];
|
||||
simpleflow1.edges[0] = { ...simpleflow1.edges[0], id: 'edge1' };
|
||||
|
||||
const simpleflow2 = { ...simpleflow };
|
||||
simpleflow2.edges = [...simpleflow2.edges];
|
||||
simpleflow2.edges[0] = { ...simpleflow2.edges[0], id: 'edge2' };
|
||||
|
||||
describe('<ReactFlow />: Multiple Instances', () => {
|
||||
describe('render EdgeLabelRenderer', () => {
|
||||
beforeEach(() => {
|
||||
cy.mount(
|
||||
<>
|
||||
<ReactFlowProvider>
|
||||
<ReactFlow
|
||||
defaultNodes={simpleflow1.nodes}
|
||||
edgeTypes={{ default: CustomEdge }}
|
||||
defaultEdges={simpleflow1.edges}
|
||||
/>
|
||||
</ReactFlowProvider>
|
||||
<ReactFlowProvider>
|
||||
<ReactFlow
|
||||
defaultNodes={simpleflow2.nodes}
|
||||
edgeTypes={{ default: CustomEdge }}
|
||||
defaultEdges={simpleflow2.edges}
|
||||
/>
|
||||
</ReactFlowProvider>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
it('Each ReactFlow instance has one edge label in EdgeLabelRenderer', () => {
|
||||
cy.get('.react-flow__edgelabel-renderer').should('have.length', 2);
|
||||
|
||||
cy.get('.react-flow__edgelabel-renderer')
|
||||
.eq(0)
|
||||
.within(() => {
|
||||
cy.get('.label').should('have.length', 1).should('contain.text', 'edge1');
|
||||
});
|
||||
|
||||
cy.get('.react-flow__edgelabel-renderer')
|
||||
.eq(1)
|
||||
.within(() => {
|
||||
cy.get('.label').should('have.length', 1).should('contain.text', 'edge2');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -8,6 +8,7 @@ import ReactFlow, {
|
||||
Node,
|
||||
Edge,
|
||||
useReactFlow,
|
||||
NodeOrigin,
|
||||
} from 'reactflow';
|
||||
|
||||
const onNodeDrag = (_: MouseEvent, node: Node) => console.log('drag', node);
|
||||
@@ -47,6 +48,8 @@ const initialEdges: Edge[] = [
|
||||
{ id: 'e1-3', source: '1', target: '3' },
|
||||
];
|
||||
|
||||
const nodeOrigin: NodeOrigin = [0.5, 0.5];
|
||||
|
||||
const defaultEdgeOptions = { zIndex: 0 };
|
||||
|
||||
const BasicFlow = () => {
|
||||
@@ -91,6 +94,7 @@ const BasicFlow = () => {
|
||||
fitView
|
||||
defaultEdgeOptions={defaultEdgeOptions}
|
||||
selectNodesOnDrag={false}
|
||||
nodeOrigin={nodeOrigin}
|
||||
>
|
||||
<Background variant={BackgroundVariant.Dots} />
|
||||
<MiniMap />
|
||||
@@ -106,7 +110,9 @@ const BasicFlow = () => {
|
||||
<button onClick={toggleClassnames} style={{ marginRight: 5 }}>
|
||||
toggle classnames
|
||||
</button>
|
||||
<button onClick={logToObject} style={{ marginRight: 5 }}>toObject</button>
|
||||
<button onClick={logToObject} style={{ marginRight: 5 }}>
|
||||
toObject
|
||||
</button>
|
||||
</div>
|
||||
</ReactFlow>
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ import ReactFlow, {
|
||||
Edge,
|
||||
NodeTypes,
|
||||
Position,
|
||||
NodeOrigin,
|
||||
} from 'reactflow';
|
||||
|
||||
import CustomNode from './CustomNode';
|
||||
@@ -20,14 +21,14 @@ const initialNodes: Node[] = [
|
||||
id: '1',
|
||||
type: 'custom',
|
||||
data: { label: 'toolbar top', toolbarPosition: Position.Top },
|
||||
position: { x: 0, y: 0 },
|
||||
position: { x: 0, y: 50 },
|
||||
className: 'react-flow__node-default',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'custom',
|
||||
data: { label: 'toolbar right', toolbarPosition: Position.Right },
|
||||
position: { x: 400, y: 0 },
|
||||
position: { x: 300, y: 0 },
|
||||
className: 'react-flow__node-default',
|
||||
},
|
||||
{
|
||||
@@ -48,7 +49,7 @@ const initialNodes: Node[] = [
|
||||
id: '5',
|
||||
type: 'custom',
|
||||
data: { label: 'toolbar always open', toolbarPosition: Position.Top, toolbarVisible: true },
|
||||
position: { x: 0, y: 150 },
|
||||
position: { x: 0, y: 200 },
|
||||
className: 'react-flow__node-default',
|
||||
},
|
||||
];
|
||||
@@ -60,6 +61,7 @@ const initialEdges: Edge[] = [
|
||||
];
|
||||
|
||||
const defaultEdgeOptions = { zIndex: 0 };
|
||||
const nodeOrigin: NodeOrigin = [0.5, 0.5];
|
||||
|
||||
export default function NodeToolbarExample() {
|
||||
return (
|
||||
@@ -72,6 +74,7 @@ export default function NodeToolbarExample() {
|
||||
fitView
|
||||
defaultEdgeOptions={defaultEdgeOptions}
|
||||
nodeTypes={nodeTypes}
|
||||
nodeOrigin={nodeOrigin}
|
||||
>
|
||||
<Background variant={BackgroundVariant.Dots} />
|
||||
<MiniMap />
|
||||
|
||||
Reference in New Issue
Block a user