feat(props): add pane mouse handlers closes #2312

This commit is contained in:
moklick
2022-07-25 15:47:34 +02:00
parent 3aa4b30c86
commit ec2dff24a3
5 changed files with 30 additions and 12 deletions
+8 -5
View File
@@ -70,6 +70,8 @@ const onEdgeDoubleClick = (_: ReactMouseEvent, edge: Edge) =>
console.log('edge double click', edge); console.log('edge double click', edge);
const onNodesDelete = (nodes: Node[]) => console.log('nodes delete', nodes); const onNodesDelete = (nodes: Node[]) => console.log('nodes delete', nodes);
const onEdgesDelete = (edges: Edge[]) => console.log('edges delete', edges); const onEdgesDelete = (edges: Edge[]) => console.log('edges delete', edges);
const onPaneMouseMove = (e: ReactMouseEvent) =>
console.log('pane move', e.clientX);
const initialNodes: Node[] = [ const initialNodes: Node[] = [
{ {
@@ -120,9 +122,9 @@ const initialNodes: Node[] = [
<> <>
You can find the docs on{' '} You can find the docs on{' '}
<a <a
href='https://github.com/wbkd/react-flow' href="https://github.com/wbkd/react-flow"
target='_blank' target="_blank"
rel='noopener noreferrer' rel="noopener noreferrer"
> >
Github Github
</a> </a>
@@ -250,10 +252,11 @@ const OverviewFlow = () => {
onEdgeDoubleClick={onEdgeDoubleClick} onEdgeDoubleClick={onEdgeDoubleClick}
fitView fitView
fitViewOptions={{ padding: 0.2 }} fitViewOptions={{ padding: 0.2 }}
attributionPosition='top-right' attributionPosition="top-right"
maxZoom={Infinity} maxZoom={Infinity}
onNodesDelete={onNodesDelete} onNodesDelete={onNodesDelete}
onEdgesDelete={onEdgesDelete} onEdgesDelete={onEdgesDelete}
onPaneMouseMove={onPaneMouseMove}
> >
<MiniMap <MiniMap
nodeStrokeColor={nodeStrokeColor} nodeStrokeColor={nodeStrokeColor}
@@ -261,7 +264,7 @@ const OverviewFlow = () => {
nodeBorderRadius={2} nodeBorderRadius={2}
/> />
<Controls /> <Controls />
<Background color='#aaa' gap={25} /> <Background color="#aaa" gap={25} />
</ReactFlow> </ReactFlow>
); );
}; };
@@ -31,6 +31,9 @@ const selector = (s: ReactFlowState) => s.nodesSelectionActive;
const FlowRenderer = ({ const FlowRenderer = ({
children, children,
onPaneClick, onPaneClick,
onPaneMouseEnter,
onPaneMouseMove,
onPaneMouseLeave,
onPaneContextMenu, onPaneContextMenu,
onPaneScroll, onPaneScroll,
deleteKeyCode, deleteKeyCode,
@@ -99,6 +102,9 @@ const FlowRenderer = ({
<div <div
className="react-flow__pane react-flow__container" className="react-flow__pane react-flow__container"
onClick={onClick} onClick={onClick}
onMouseEnter={onPaneMouseEnter}
onMouseMove={onPaneMouseMove}
onMouseLeave={onPaneMouseLeave}
onContextMenu={onContextMenu} onContextMenu={onContextMenu}
onWheel={onWheel} onWheel={onWheel}
/> />
@@ -64,6 +64,9 @@ const GraphView = ({
zoomOnDoubleClick, zoomOnDoubleClick,
panOnDrag, panOnDrag,
onPaneClick, onPaneClick,
onPaneMouseEnter,
onPaneMouseMove,
onPaneMouseLeave,
onPaneScroll, onPaneScroll,
onPaneContextMenu, onPaneContextMenu,
onEdgeUpdate, onEdgeUpdate,
@@ -85,6 +88,9 @@ const GraphView = ({
return ( return (
<FlowRenderer <FlowRenderer
onPaneClick={onPaneClick} onPaneClick={onPaneClick}
onPaneMouseEnter={onPaneMouseEnter}
onPaneMouseMove={onPaneMouseMove}
onPaneMouseLeave={onPaneMouseLeave}
onPaneContextMenu={onPaneContextMenu} onPaneContextMenu={onPaneContextMenu}
onPaneScroll={onPaneScroll} onPaneScroll={onPaneScroll}
deleteKeyCode={deleteKeyCode} deleteKeyCode={deleteKeyCode}
@@ -115,6 +115,9 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
zoomOnDoubleClick = true, zoomOnDoubleClick = true,
panOnDrag = true, panOnDrag = true,
onPaneClick, onPaneClick,
onPaneMouseEnter,
onPaneMouseMove,
onPaneMouseLeave,
onPaneScroll, onPaneScroll,
onPaneContextMenu, onPaneContextMenu,
children, children,
@@ -185,6 +188,9 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
panOnScrollMode={panOnScrollMode} panOnScrollMode={panOnScrollMode}
panOnDrag={panOnDrag} panOnDrag={panOnDrag}
onPaneClick={onPaneClick} onPaneClick={onPaneClick}
onPaneMouseEnter={onPaneMouseEnter}
onPaneMouseMove={onPaneMouseMove}
onPaneMouseLeave={onPaneMouseLeave}
onPaneScroll={onPaneScroll} onPaneScroll={onPaneScroll}
onPaneContextMenu={onPaneContextMenu} onPaneContextMenu={onPaneContextMenu}
onSelectionContextMenu={onSelectionContextMenu} onSelectionContextMenu={onSelectionContextMenu}
+4 -7
View File
@@ -1,10 +1,4 @@
import React, { import React, { CSSProperties, HTMLAttributes, MouseEvent as ReactMouseEvent, WheelEvent } from 'react';
ButtonHTMLAttributes,
CSSProperties,
HTMLAttributes,
MouseEvent as ReactMouseEvent,
WheelEvent,
} from 'react';
import { import {
OnSelectionChangeFunc, OnSelectionChangeFunc,
@@ -80,6 +74,9 @@ export interface ReactFlowProps extends HTMLAttributes<HTMLDivElement> {
onPaneScroll?: (event?: WheelEvent) => void; onPaneScroll?: (event?: WheelEvent) => void;
onPaneClick?: (event: ReactMouseEvent) => void; onPaneClick?: (event: ReactMouseEvent) => void;
onPaneContextMenu?: (event: ReactMouseEvent) => void; onPaneContextMenu?: (event: ReactMouseEvent) => void;
onPaneMouseEnter?: (event: ReactMouseEvent) => void;
onPaneMouseMove?: (event: ReactMouseEvent) => void;
onPaneMouseLeave?: (event: ReactMouseEvent) => void;
nodeTypes?: NodeTypes; nodeTypes?: NodeTypes;
edgeTypes?: EdgeTypes; edgeTypes?: EdgeTypes;
connectionMode?: ConnectionMode; connectionMode?: ConnectionMode;