Skip to content

Commit 56299de

Browse files
committedMay 29, 2024
refractor menu
1 parent b33bd22 commit 56299de

File tree

3 files changed

+14
-56
lines changed

3 files changed

+14
-56
lines changed
 

‎crewai-reactflow/src/App.js

+5-19
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,19 @@ import ReactFlow, {
1111
useEdgesState,
1212
} from 'reactflow';
1313
import 'reactflow/dist/style.css';
14+
import './ContextMenu.css'; // Import the CSS for the context menu
15+
import ContextMenu from './ContextMenu'; // Import the ContextMenu component
1416

1517
const initialNodes = [
1618
{
1719
id: '1',
1820
type: 'input',
1921
data: { label: 'Node 1' },
2022
position: { x: 250, y: 5 },
21-
draggable: true, // Ensure node is draggable
23+
draggable: true,
2224
},
2325
];
2426

25-
const ContextMenu = ({ x, y, onAddNode }) => (
26-
<div
27-
style={{
28-
position: 'absolute',
29-
top: y,
30-
left: x,
31-
backgroundColor: 'white',
32-
border: '1px solid black',
33-
padding: '10px',
34-
zIndex: 1000,
35-
}}
36-
>
37-
<button onClick={onAddNode}>Add Node</button>
38-
</div>
39-
);
40-
4127
const Flow = () => {
4228
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
4329
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
@@ -54,8 +40,8 @@ const Flow = () => {
5440
const newNode = {
5541
id: `${+new Date()}`,
5642
data: { label: `Node ${nodes.length + 1}` },
57-
position: { x: 250, y: 5 }, // Fixed position
58-
draggable: true, // Ensure new nodes are draggable
43+
position: { x: 250, y: 5 },
44+
draggable: true,
5945
};
6046

6147
setNodes((nds) => nds.concat(newNode));

‎crewai-reactflow/src/ContextMenu.css

+3-21
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,8 @@
22

33
.context-menu {
44
position: absolute;
5-
z-index: 1000;
6-
background: white;
7-
border: 1px solid #ccc;
5+
background-color: white;
6+
border: 1px solid black;
87
padding: 10px;
9-
border-radius: 5px;
10-
box-shadow: 0 2px 5px rgba(0,0,0,0.15);
11-
}
12-
13-
.context-menu button {
14-
display: block;
15-
width: 100%;
16-
padding: 5px 10px;
17-
margin-bottom: 5px;
18-
background: #f0f0f0;
19-
border: 1px solid #ccc;
20-
border-radius: 3px;
21-
cursor: pointer;
22-
text-align: left;
23-
}
24-
25-
.context-menu button:hover {
26-
background: #e0e0e0;
8+
z-index: 1000;
279
}

‎crewai-reactflow/src/ContextMenu.js

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
// ContextMenu.js
22

33
import React from 'react';
4-
import './ContextMenu.css';
4+
import './ContextMenu.css'; // Import the CSS for the context menu
55

6-
const ContextMenu = ({ menuPosition, onAddNode }) => {
7-
if (!menuPosition) return null;
8-
9-
return (
10-
<div
11-
className="context-menu"
12-
style={{
13-
top: menuPosition.y,
14-
left: menuPosition.x,
15-
}}
16-
>
17-
<button onClick={onAddNode}>Add Node</button>
18-
</div>
19-
);
20-
};
6+
const ContextMenu = ({ x, y, onAddNode }) => (
7+
<div className="context-menu" style={{ top: y, left: x }}>
8+
<button onClick={onAddNode}>Add Node</button>
9+
</div>
10+
);
2111

2212
export default ContextMenu;

0 commit comments

Comments
 (0)
Failed to load comments.