|
| 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