import * as LucideIcons from "lucide-react"; import type { NodeTypeInfo } from "./types"; import { getIconForType } from "./types"; type LucideIconComponent = React.ComponentType<{ size?: number; color?: string; strokeWidth?: number; className?: string; }>; function getLucideIcon(iconName: string): LucideIconComponent { const icons = LucideIcons as unknown as Record; const icon = icons[iconName]; if (!icon) { console.warn(`[getLucideIcon] Icon "${iconName}" not found, using Circle`); } return icon || icons.Circle; } const POSITION_CLASSES = { "bottom-left": "bottom-4 left-4", "bottom-right": "bottom-4 right-4", "top-left": "top-4 left-4", "top-right": "top-4 right-4", }; export interface LegendProps { nodeTypes: NodeTypeInfo[]; selectedNodeType: string | null; onNodeTypeClick: (typeKey: string) => void; onClearSelection: () => void; maxVisibleTypes?: number; position?: keyof typeof POSITION_CLASSES; } export function GraphViewerLegend({ nodeTypes, selectedNodeType, onNodeTypeClick, onClearSelection, maxVisibleTypes = 12, position = "bottom-left", }: LegendProps) { if (!nodeTypes || nodeTypes.length === 0) { return null; } const visibleTypes = nodeTypes.slice(0, maxVisibleTypes); const remainingCount = nodeTypes.length - maxVisibleTypes; return (

Node Types ({nodeTypes.length}) {selectedNodeType && ( )}

{visibleTypes.map((nodeType) => { const iconName = getIconForType(nodeType.externalId); const IconComponent = getLucideIcon(iconName); const typeKey = `${nodeType.space}:${nodeType.externalId}`; const isSelected = selectedNodeType === typeKey; return ( ); })} {remainingCount > 0 && ( +{remainingCount} more )}
); }