feat(Minimap): add nodeComponent prop

This commit is contained in:
Abbey Yacoe
2025-09-04 11:23:25 +02:00
parent 4783957dbf
commit 24350a70e7
6 changed files with 132 additions and 15 deletions

View File

@@ -7,6 +7,7 @@
'add-node-on-drop',
'color-mode',
'custom-connection-line',
'custom-minimap',
'customnode',
'dagre',
'detached-handle',

View File

@@ -0,0 +1,48 @@
<script lang="ts">
import {
SvelteFlow,
Background,
Controls,
MiniMap,
type Node,
type Edge,
} from '@xyflow/svelte';
import '@xyflow/svelte/dist/style.css';
import CustomMiniMapNode from './CustomMiniMapNode.svelte';
let nodes = $state.raw<Node[]>([]);
let edges = $state.raw<Edge[]>([]);
function addRandomNode() {
const nodeId = (nodes.length + 1).toString();
const newNode: Node = {
id: nodeId,
data: { label: `Node: ${nodeId}` },
position: {
x: Math.random() * (typeof window !== 'undefined' ? window.innerWidth : 800),
y: Math.random() * (typeof window !== 'undefined' ? window.innerHeight : 600),
},
type: 'default'
};
nodes = [...nodes, newNode];
}
</script>
<SvelteFlow
bind:nodes
bind:edges
onlyRenderVisibleElements={true}
>
<Controls />
<Background />
<MiniMap nodeComponent={CustomMiniMapNode} />
<button
type="button"
onclick={addRandomNode}
style="position: absolute; left: 10px; top: 10px; z-index: 4;"
>
add node
</button>
</SvelteFlow>

View File

@@ -0,0 +1,22 @@
<script lang="ts">
let {
x,
y,
width,
height,
selected,
}: {
x: number;
y: number;
width: number;
height: number;
selected?: boolean;
} = $props();
</script>
<circle
cx={x + width / 2}
cy={y + height / 2}
r={Math.min(width, height) - 2}
fill={selected ? "#ff6b6b" : "#ffcc00"}
/>