/** * @file Example demonstrating NodeSearchMenu with split pane view mode (UI) */ import * as React from "react"; import type { NodeDefinition } from "../../../../../types/NodeDefinition"; import { NodeSearchMenu, type NodeSearchMenuViewMode } from "../../../../../components/panels/node-search/NodeSearchMenu"; import { I18nProvider } from "../../../../../i18n/context"; import { enMessages } from "../../../../../i18n/en"; import styles from "./NodeSearchMenuExample.module.css"; /** * Sample node definitions with nested categories using "/" separator */ const sampleNodeDefinitions: NodeDefinition[] = [ // Data category with subcategories { type: "data-source", displayName: "Data Source", description: "Load data from external sources", category: "Data", icon: "📥", priority: 1, }, { type: "data-filter", displayName: "Filter", description: "Filter data based on conditions", category: "Data/Transform", icon: "🔍", priority: 1, }, { type: "data-map", displayName: "Map", description: "Transform each element in a collection", category: "Data/Transform", icon: "🔄", priority: 1, }, { type: "data-reduce", displayName: "Reduce", description: "Aggregate data into a single value", category: "Data/Transform", icon: "📊", priority: 1, }, { type: "data-sort", displayName: "Sort", description: "Sort data by specified criteria", category: "Data/Transform/Order", icon: "↕️", priority: 1, }, { type: "data-reverse", displayName: "Reverse", description: "Reverse the order of elements", category: "Data/Transform/Order", icon: "🔃", priority: 1, }, { type: "data-join", displayName: "Join", description: "Combine multiple data sources", category: "Data/Combine", icon: "🔗", priority: 1, }, { type: "data-split", displayName: "Split", description: "Split data into multiple streams", category: "Data/Combine", icon: "✂️", priority: 1, }, // Logic category { type: "logic-if", displayName: "If/Else", description: "Conditional branching", category: "Logic", icon: "❓", priority: 2, }, { type: "logic-switch", displayName: "Switch", description: "Multi-way branching", category: "Logic", icon: "🔀", priority: 2, }, { type: "logic-and", displayName: "AND Gate", description: "Logical AND operation", category: "Logic/Gates", icon: "∧", priority: 2, }, { type: "logic-or", displayName: "OR Gate", description: "Logical OR operation", category: "Logic/Gates", icon: "∨", priority: 2, }, { type: "logic-not", displayName: "NOT Gate", description: "Logical NOT operation", category: "Logic/Gates", icon: "¬", priority: 2, }, // Math category { type: "math-add", displayName: "Add", description: "Add two numbers", category: "Math/Arithmetic", icon: "➕", priority: 3, }, { type: "math-subtract", displayName: "Subtract", description: "Subtract two numbers", category: "Math/Arithmetic", icon: "➖", priority: 3, }, { type: "math-multiply", displayName: "Multiply", description: "Multiply two numbers", category: "Math/Arithmetic", icon: "✖️", priority: 3, }, { type: "math-divide", displayName: "Divide", description: "Divide two numbers", category: "Math/Arithmetic", icon: "➗", priority: 3, }, { type: "math-sin", displayName: "Sine", description: "Calculate sine of an angle", category: "Math/Trigonometry", icon: "〰️", priority: 3, }, { type: "math-cos", displayName: "Cosine", description: "Calculate cosine of an angle", category: "Math/Trigonometry", icon: "〰️", priority: 3, }, { type: "math-random", displayName: "Random", description: "Generate a random number", category: "Math/Random", icon: "🎲", priority: 3, }, // Output category { type: "output-display", displayName: "Display", description: "Display data on screen", category: "Output", icon: "🖥️", priority: 4, }, { type: "output-log", displayName: "Log", description: "Log data to console", category: "Output", icon: "📝", priority: 4, }, { type: "output-export", displayName: "Export", description: "Export data to file", category: "Output/File", icon: "💾", priority: 4, }, // Utilities { type: "util-delay", displayName: "Delay", description: "Add a time delay", category: "Utilities", icon: "⏱️", priority: 5, }, { type: "util-comment", displayName: "Comment", description: "Add a comment node", category: "Utilities", icon: "💬", priority: 5, }, ]; export const NodeSearchMenuExample: React.FC = () => { const [viewMode, setViewMode] = React.useState("split"); const [menuVisible, setMenuVisible] = React.useState(true); const [menuPosition, setMenuPosition] = React.useState({ x: 100, y: 100 }); const [createdNodes, setCreatedNodes] = React.useState([]); const handleCreateNode = React.useCallback((nodeType: string) => { setCreatedNodes((prev) => [...prev, nodeType]); setMenuVisible(false); }, []); const handleClose = React.useCallback(() => { setMenuVisible(false); }, []); const handleCanvasClick = React.useCallback( (e: React.MouseEvent) => { if (!menuVisible) { setMenuPosition({ x: e.clientX, y: e.clientY }); setMenuVisible(true); } }, [menuVisible], ); const dictionaries = React.useMemo(() => ({ en: enMessages }), []); return (
{ if (e.key === "Enter" || e.key === " ") { setMenuVisible(true); } }} >
Click anywhere to open the NodeSearchMenu

Created Nodes Log

{createdNodes.length === 0 ? (
No nodes created yet
) : ( createdNodes.map((nodeType, index) => (
{index + 1}. {nodeType}
)) )}

Nested Categories

This example demonstrates nested categories using "/" separator:

  • Data/Transform
  • Data/Transform/Order
  • Data/Combine
  • Logic/Gates
  • Math/Arithmetic
  • Math/Trigonometry
); };