ruv commited on
Commit
7bce4da
·
verified ·
1 Parent(s): 074d4cd

Create CustomNode.jsx

Browse files
Files changed (1) hide show
  1. src/CustomNode.jsx +76 -0
src/CustomNode.jsx ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { memo } from 'react';
2
+ import { Handle, useReactFlow, useStoreApi, Position } from 'reactflow';
3
+
4
+ const options = [
5
+ {
6
+ value: 'smoothstep',
7
+ label: 'Smoothstep',
8
+ },
9
+ {
10
+ value: 'step',
11
+ label: 'Step',
12
+ },
13
+ {
14
+ value: 'default',
15
+ label: 'Bezier (default)',
16
+ },
17
+ {
18
+ value: 'straight',
19
+ label: 'Straight',
20
+ },
21
+ ];
22
+
23
+ function Select({ value, handleId, nodeId }) {
24
+ const { setNodes } = useReactFlow();
25
+ const store = useStoreApi();
26
+
27
+ const onChange = (evt) => {
28
+ const { nodeInternals } = store.getState();
29
+ setNodes(
30
+ Array.from(nodeInternals.values()).map((node) => {
31
+ if (node.id === nodeId) {
32
+ node.data = {
33
+ ...node.data,
34
+ selects: {
35
+ ...node.data.selects,
36
+ [handleId]: evt.target.value,
37
+ },
38
+ };
39
+ }
40
+
41
+ return node;
42
+ })
43
+ );
44
+ };
45
+
46
+ return (
47
+ <div className="custom-node__select">
48
+ <div>Edge Type</div>
49
+ <select className="nodrag" onChange={onChange} value={value}>
50
+ {options.map((option) => (
51
+ <option key={option.value} value={option.value}>
52
+ {option.label}
53
+ </option>
54
+ ))}
55
+ </select>
56
+ <Handle type="source" position={Position.Right} id={handleId} />
57
+ </div>
58
+ );
59
+ }
60
+
61
+ function CustomNode({ id, data }) {
62
+ return (
63
+ <>
64
+ <div className="custom-node__header">
65
+ This is a <strong>custom node</strong>
66
+ </div>
67
+ <div className="custom-node__body">
68
+ {Object.keys(data.selects).map((handleId) => (
69
+ <Select key={handleId} nodeId={id} value={data.selects[handleId]} handleId={handleId} />
70
+ ))}
71
+ </div>
72
+ </>
73
+ );
74
+ }
75
+
76
+ export default memo(CustomNode);