@@ -11,33 +11,19 @@ import ReactFlow, {
11
11
useEdgesState ,
12
12
} from 'reactflow' ;
13
13
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
14
16
15
17
const initialNodes = [
16
18
{
17
19
id : '1' ,
18
20
type : 'input' ,
19
21
data : { label : 'Node 1' } ,
20
22
position : { x : 250 , y : 5 } ,
21
- draggable : true , // Ensure node is draggable
23
+ draggable : true ,
22
24
} ,
23
25
] ;
24
26
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
-
41
27
const Flow = ( ) => {
42
28
const [ nodes , setNodes , onNodesChange ] = useNodesState ( initialNodes ) ;
43
29
const [ edges , setEdges , onEdgesChange ] = useEdgesState ( [ ] ) ;
@@ -54,8 +40,8 @@ const Flow = () => {
54
40
const newNode = {
55
41
id : `${ + new Date ( ) } ` ,
56
42
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 ,
59
45
} ;
60
46
61
47
setNodes ( ( nds ) => nds . concat ( newNode ) ) ;
0 commit comments