toolbar.tsx


Overview

The toolbar.tsx file defines a reusable React component named ToolBar designed to provide a small contextual toolbar with common node actions such as run, duplicate, and delete within a graph or workflow editor interface. The component is part of a larger system handling node-based graph manipulation, likely related to a UI flow or visual programming environment.

This toolbar appears as a tooltip attached to nodes and offers interactive icons with tooltips, enabling users to perform node operations efficiently. The file also includes a small helper component IconWrapper to style the toolbar icons consistently.


Detailed Explanation

Imports


Component: IconWrapper

A simple presentational component to wrap icons with consistent styling and pointer cursor behavior.

Signature

function IconWrapper(props: HTMLAttributes<HTMLDivElement>): JSX.Element

Parameters

Returns

A styled <div> wrapping the icon children with padding, background color, rounded corners, and cursor styling.

Usage Example

<IconWrapper onClick={handleClick}>
  <Copy className="size-3.5" />
</IconWrapper>

Component: ToolBar

The main component providing a tooltip toolbar with node action icons.

Signature

function ToolBar(props: ToolBarProps): JSX.Element

Props (ToolBarProps)

Prop

Type

Description

Optional

Default

selected

`boolean \

undefined`

Indicates if the node is currently selected

Yes

label

string

The label/type of the node (used to handle specific logic like iteration nodes)

No

id

string

Unique identifier of the node

No

showRun

boolean

Whether to show the run/play icon

Yes

true

children

React.ReactNode

The content that triggers the tooltip (usually the node UI element)

Yes

Behavior and Implementation Details

Returns

A tooltip-enabled toolbar component that displays icons for actions relevant to a node in a graph editor interface.

Usage Example

<ToolBar id="node-123" label="CustomOperator" selected={true} showRun={false}>
  {/* Node visual representation */}
  <div>Node Content Here</div>
</ToolBar>

Important Implementation Notes


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component ToolBar {
      +selected: boolean | undefined
      +label: string
      +id: string
      +showRun: boolean
      +children: ReactNode
      +deleteNode()
      +handleDuplicate()
    }

    component IconWrapper {
      +children: ReactNode
      +HTMLAttributes<HTMLDivElement>
    }

    ToolBar --> IconWrapper : uses for icons
    ToolBar --> TooltipNode : wraps toolbar
    TooltipNode --> TooltipTrigger : trigger element (children)
    TooltipNode --> TooltipContent : displays icons
    ToolBar --> useGraphStore : deleteNodeById, deleteIterationNodeById
    ToolBar --> useDuplicateNode : duplicateNode

Summary

The toolbar.tsx file provides a compact, reusable React toolbar component that integrates with a graph editor system to offer node-specific actions including running, duplicating, and deleting nodes. It uses advanced React patterns such as hooks and context/state stores alongside composable tooltip components and iconography to enhance the user experience in managing complex graph-based workflows.