chore(examples): cleanup

This commit is contained in:
moklick
2023-02-13 16:21:50 +01:00
parent 5fee3fbcc0
commit 6e6720579e
2 changed files with 22 additions and 17 deletions

View File

@@ -8,6 +8,7 @@ import ReactFlow, {
Node,
Edge,
useReactFlow,
Panel,
} from 'reactflow';
const onNodeDrag = (_: MouseEvent, node: Node) => console.log('drag', node);
@@ -98,20 +99,12 @@ const BasicFlow = () => {
<MiniMap />
<Controls />
<div style={{ position: 'absolute', right: 10, top: 10, zIndex: 4 }}>
<button onClick={resetTransform} style={{ marginRight: 5 }}>
reset transform
</button>
<button onClick={updatePos} style={{ marginRight: 5 }}>
change pos
</button>
<button onClick={toggleClassnames} style={{ marginRight: 5 }}>
toggle classnames
</button>
<button onClick={logToObject} style={{ marginRight: 5 }}>
toObject
</button>
</div>
<Panel position="top-right">
<button onClick={resetTransform}>reset transform</button>
<button onClick={updatePos}>change pos</button>
<button onClick={toggleClassnames}>toggle classnames</button>
<button onClick={logToObject}>toObject</button>
</Panel>
</ReactFlow>
);
};

View File

@@ -2,7 +2,7 @@ import { Handle, NodeProps, Position, ReactFlowState, useStore } from 'reactflow
const connectionNodeIdSelector = (state: ReactFlowState) => state.connectionNodeId;
export default function CustomNode({ id }: NodeProps) {
export default function CustomNode({ id, isConnectable }: NodeProps) {
const connectionNodeId = useStore(connectionNodeIdSelector);
const isTarget = connectionNodeId && connectionNodeId !== id;
@@ -18,8 +18,20 @@ export default function CustomNode({ id }: NodeProps) {
backgroundColor: isTarget ? '#ffcce3' : '#ccd9f6',
}}
>
<Handle className="targetHandle" style={{ zIndex: 2 }} position={Position.Right} type="source" />
<Handle className="targetHandle" style={targetHandleStyle} position={Position.Left} type="target" />
<Handle
className="targetHandle"
style={{ zIndex: 2 }}
position={Position.Right}
type="source"
isConnectable={isConnectable}
/>
<Handle
className="targetHandle"
style={targetHandleStyle}
position={Position.Left}
type="target"
isConnectable={isConnectable}
/>
{label}
</div>
</div>