Skip to content

Commit e29fb57

Browse files
committed
add minimap support for React Flow v12
1 parent 539e7e6 commit e29fb57

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/extensions/react-flow/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from "./edges/EdgeDefaultV12";
1717
export * from "./markers/ReactFlowMarkers";
1818
export * from "./minimap/MiniMap";
1919
export * from "./minimap/MiniMapV10";
20+
export * from "./minimap/MiniMapV12";
2021
export * from "./minimap/utils";
2122
export * from "./versionsupport";
2223

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, { memo } from "react";
2+
import { MiniMap as ReactFlowMiniMap, MiniMapProps as ReactFlowMiniMapProps } from "@xyflow/react";
3+
4+
import { miniMapUtils } from "../minimap/utils";
5+
6+
export interface MiniMapV10Props extends Omit<ReactFlowMiniMapProps, "maskColor"> {
7+
/**
8+
* Enable navigating the react-flow canvas by dragging and clicking on the mini-map.
9+
*/
10+
enableNavigation?: boolean;
11+
/**
12+
* Properties are forwarded to the HTML `div` element used as minimap wrapper.
13+
* Data attributes for test ids could be included here.
14+
*/
15+
wrapperProps?: Omit<
16+
React.HTMLAttributes<HTMLDivElement>,
17+
"onMouseDown" | "onMouseUp" | "onMouseMove" | "onMouseLeave"
18+
>;
19+
}
20+
21+
/**
22+
* Mini-map support for for React Flow v12.
23+
* @deprecated (v26) will be removed when `MiniMap` supports v12 directly
24+
*/
25+
export const MiniMapV12 = memo(
26+
({
27+
enableNavigation = false,
28+
nodeClassName = miniMapUtils.nodeClassName,
29+
nodeColor = miniMapUtils.nodeColor,
30+
nodeStrokeColor = miniMapUtils.borderColor,
31+
wrapperProps,
32+
...minimapProps
33+
}: MiniMapV10Props) => {
34+
return (
35+
<div
36+
{...wrapperProps}
37+
style={enableNavigation ? { ...(wrapperProps?.style ?? {}), cursor: "grab" } : wrapperProps?.style}
38+
>
39+
<ReactFlowMiniMap
40+
nodeClassName={nodeClassName}
41+
nodeColor={nodeColor}
42+
nodeStrokeColor={nodeStrokeColor}
43+
{...minimapProps}
44+
zoomable={enableNavigation}
45+
pannable={enableNavigation}
46+
/>
47+
</div>
48+
);
49+
}
50+
);

0 commit comments

Comments
 (0)