Add an optional 'MiniMapNode' field to 'MiniMapProps'.

This lets users supply a custom SVG node to render in the minimap instead of the default rectangle.
This commit is contained in:
Hayleigh Thompson
2023-03-09 14:25:23 +00:00
parent 46f3f81dc4
commit 1415ed003e
2 changed files with 6 additions and 2 deletions
+4 -1
View File
@@ -64,6 +64,9 @@ function MiniMap({
pannable = false,
zoomable = false,
ariaLabel = 'React Flow mini map',
// Rename the field to avoid clashes with the default `MiniMapNode` component.
// Fallback to that component if none is provided.
MiniMapNode: CustomMiniMapNode = MiniMapNode,
}: MiniMapProps) {
const store = useStoreApi();
const svg = useRef<SVGSVGElement>(null);
@@ -176,7 +179,7 @@ function MiniMap({
const { x, y } = getNodePositionWithOrigin(node, nodeOrigin).positionAbsolute;
return (
<MiniMapNode
<CustomMiniMapNode
key={node.id}
x={x}
y={y}
+2 -1
View File
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { CSSProperties, HTMLAttributes, MouseEvent } from 'react';
import type { ComponentType, CSSProperties, HTMLAttributes, MouseEvent } from 'react';
import type { Node, PanelPosition, XYPosition } from '@reactflow/core';
export type GetMiniMapNodeAttribute<NodeData = any> = (node: Node<NodeData>) => string;
@@ -19,6 +19,7 @@ export type MiniMapProps<NodeData = any> = Omit<HTMLAttributes<SVGSVGElement>, '
pannable?: boolean;
zoomable?: boolean;
ariaLabel?: string | null;
MiniMapNode?: ComponentType<MiniMapNodeProps>;
};
export interface MiniMapNodeProps {