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