✨ 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:
@@ -64,6 +64,9 @@ function MiniMap({
|
|||||||
pannable = false,
|
pannable = false,
|
||||||
zoomable = false,
|
zoomable = false,
|
||||||
ariaLabel = 'React Flow mini map',
|
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) {
|
}: MiniMapProps) {
|
||||||
const store = useStoreApi();
|
const store = useStoreApi();
|
||||||
const svg = useRef<SVGSVGElement>(null);
|
const svg = useRef<SVGSVGElement>(null);
|
||||||
@@ -176,7 +179,7 @@ function MiniMap({
|
|||||||
const { x, y } = getNodePositionWithOrigin(node, nodeOrigin).positionAbsolute;
|
const { x, y } = getNodePositionWithOrigin(node, nodeOrigin).positionAbsolute;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MiniMapNode
|
<CustomMiniMapNode
|
||||||
key={node.id}
|
key={node.id}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* 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';
|
import type { Node, PanelPosition, XYPosition } from '@reactflow/core';
|
||||||
|
|
||||||
export type GetMiniMapNodeAttribute<NodeData = any> = (node: Node<NodeData>) => string;
|
export type GetMiniMapNodeAttribute<NodeData = any> = (node: Node<NodeData>) => string;
|
||||||
@@ -19,6 +19,7 @@ export type MiniMapProps<NodeData = any> = Omit<HTMLAttributes<SVGSVGElement>, '
|
|||||||
pannable?: boolean;
|
pannable?: boolean;
|
||||||
zoomable?: boolean;
|
zoomable?: boolean;
|
||||||
ariaLabel?: string | null;
|
ariaLabel?: string | null;
|
||||||
|
MiniMapNode?: ComponentType<MiniMapNodeProps>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface MiniMapNodeProps {
|
export interface MiniMapNodeProps {
|
||||||
|
|||||||
Reference in New Issue
Block a user