categorize-handle.tsx


Overview

categorize-handle.tsx defines a React functional component CategorizeHandle that renders a styled connection handle for use within flow or node-based diagrams built with the @xyflow/react library. The component customizes the position, appearance, and identifier of each handle, facilitating the creation of connectable anchor points on the right side of nodes.

This file primarily serves as a reusable UI element in a larger flow diagram or graph editor system, enabling users to visually and functionally connect different elements via these handles.


Detailed Explanation

Imports


Constants

DEFAULT_HANDLE_STYLE

const DEFAULT_HANDLE_STYLE = {
  width: 6,
  height: 6,
  bottom: -5,
  fontSize: 8,
};

Interface: IProps

interface IProps extends React.PropsWithChildren {
  top: number;
  right: number;
  id: string;
  idx?: number;
}

Component: CategorizeHandle

const CategorizeHandle = ({ top, right, id, children }: IProps) => {
  return (
    <Handle
      type="source"
      position={Position.Right}
      id={id}
      isConnectable
      style={{
        ...DEFAULT_HANDLE_STYLE,
        top: `${top}%`,
        right: `${right}%`,
        background: 'red',
        color: 'black',
      }}
    >
      <span className={styles.categorizeAnchorPointText}>{children || id}</span>
    </Handle>
  );
};

Description

CategorizeHandle is a stateless React functional component that wraps the Handle component from @xyflow/react with custom styles and positioning.

Parameters

Behavior and Styling

Usage Example

<CategorizeHandle top={50} right={10} id="handle-1">
  Custom Label
</CategorizeHandle>

This renders a red handle positioned halfway down (50% from the top) and slightly inset from the right (10%) of the parent node, labeled "Custom Label".

If no children are passed:

<CategorizeHandle top={25} right={5} id="handle-2" />

This renders the handle with "handle-2" as the label text.


Important Implementation Details


Interaction with Other System Parts


Mermaid Component Diagram

componentDiagram
    component CategorizeHandle {
      +top: number
      +right: number
      +id: string
      +children?: ReactNode
      +Render Handle (type="source", position=Right)
      +Apply styles (default + dynamic top/right + red background)
      +Display label (children or id)
    }
    CategorizeHandle --> Handle : uses
    Handle --> Position : uses enum Position.Right

Summary

categorize-handle.tsx provides a customizable, reusable connection handle component for flow diagrams, enabling nodes to expose connection points on their right side. It leverages the @xyflow/react library's Handle component with added styling and labeling to support intuitive graph editing interfaces. This component is a building block within a node-based UI system, facilitating visually distinct and interactable anchor points for edges.