node-wrapper.tsx

Overview

The node-wrapper.tsx file defines a React functional component named NodeWrapper. This component serves as a styled container wrapper, designed to encapsulate arbitrary child elements within a visually distinct box. It primarily applies conditional styling based on a selected state, enabling UI elements to reflect selection or focus visually.

This component is intended for use in UI layouts where nodes or items need to be presented with consistent styling and selection indication, such as in tree views, node graphs, or card-based interfaces.


Detailed Explanation

Imports


Type Definitions

type IProps = HTMLAttributes<HTMLDivElement> & { selected?: boolean };

NodeWrapper Component

export function NodeWrapper({ children, className, selected }: IProps) {
  return (
    <section
      className={cn(
        'bg-text-title-invert p-2.5 rounded-sm w-[200px] text-xs',
        { 'border border-accent-primary': selected },
        className,
      )}
    >
      {children}
    </section>
  );
}

Parameters

Return Value

Functionality

Usage Example

<NodeWrapper selected={true} className="my-custom-class">
  <p>This node is selected and styled accordingly.</p>
</NodeWrapper>

<NodeWrapper>
  <p>This node is not selected.</p>
</NodeWrapper>

Implementation Details


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class NodeWrapper {
        +IProps props
        +children: ReactNode
        +className?: string
        +selected?: boolean
        +NodeWrapper({children, className, selected})
    }
    class IProps {
        +selected?: boolean
        +[HTML div attributes]
    }
    NodeWrapper --> IProps

Summary

node-wrapper.tsx exports a simple, reusable React component for wrapping content in a styled container. It supports selection highlighting and flexible styling through props. This component is useful for UI patterns requiring consistent node presentation with visual selection states, integrating seamlessly with CSS utility frameworks and React’s attribute system.