# Node port

Show a typed graph endpoint with an accessible caller action.

## Preview

node-port-preview-1.jsx

```jsx
import {
  useLayoutEffect as useLayoutEffect2,
  useRef as useRef2,
  useState as useState2,
} from "react";
import { IconButton } from "@/components/ui/button";
import { MoreHorizontal } from "lucide-react";
import { DropdownMenu } from "@/components/ui/dropdown-menu";
import { NodeCard } from "@/components/ui/node-card";
import { EdgePath } from "@/components/ui/edge-path";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";

export default function Example() {
  const [connected, setConnected] = useState2(true);
  const [referenceConnected, setReferenceConnected] = useState2(false);
  return (
    <div data-preview-wide className="creative-port-demo">
      <PortScene
        connected={connected}
        referenceConnected={referenceConnected}
        onChange={setConnected}
        onReferenceChange={setReferenceConnected}
      />
    </div>
  );
}

function PortActions({
  label,
  connected,
  onChange,
  open,
  onOpenChange,
  anchorRef,
}) {
  return (
    <DropdownMenu.Root open={open} onOpenChange={onOpenChange}>
      {anchorRef ? null : (
        <DropdownMenu.Trigger
          render={
            <IconButton
              icon={<MoreHorizontal />}
              size="icon-xs"
              variant="ghost"
              aria-label={`${label} actions`}
            />
          }
        />
      )}
      <DropdownMenu.Portal>
        <DropdownMenu.Positioner align="end" anchor={anchorRef}>
          <DropdownMenu.Popup aria-label={`${label} actions`}>
            {connected ? (
              <DropdownMenu.Item onClick={() => onChange(false)}>
                Disconnect
              </DropdownMenu.Item>
            ) : (
              <DropdownMenu.Item onClick={() => onChange(true)}>
                {label === "Reference"
                  ? "Add reference source"
                  : "Connect Brief"}
              </DropdownMenu.Item>
            )}
          </DropdownMenu.Popup>
        </DropdownMenu.Positioner>
      </DropdownMenu.Portal>
    </DropdownMenu.Root>
  );
}

function PortScene({
  connected,
  referenceConnected = false,
  compact = false,
  onChange,
  onReferenceChange = () => {},
}) {
  const scene = useRef2(null),
    brief = useRef2(null),
    prompt = useRef2(null),
    source = useRef2(null),
    reference = useRef2(null);
  const [stacked, setStacked] = useState2(false);
  const [activePort, setActivePort] = useState2(null);
  const [wires, setWires] = useState2({
    width: 1,
    height: 1,
  });
  useLayoutEffect2(() => {
    const measure = () => {
      const bounds = scene.current?.getBoundingClientRect();
      if (!bounds?.width || !bounds.height) return;
      setStacked(bounds.width < 520);
      const path = (from, to) => {
        if (!from || !to) return;
        const a = from.getBoundingClientRect(),
          b = to.getBoundingClientRect();
        const x = a.left + a.width / 2 - bounds.left,
          y = a.top + a.height / 2 - bounds.top,
          endX = b.left + b.width / 2 - bounds.left,
          endY = b.top + b.height / 2 - bounds.top;
        if (stacked && referenceConnected && from === brief.current)
          return `M${x} ${y} V${y + 24} H-12 V${endY - 40} H${endX} V${endY}`;
        if (stacked) {
          const bend = Math.max(24, Math.abs(endY - y) / 2);
          return `M${x} ${y} C${x} ${y + bend} ${endX} ${endY - bend} ${endX} ${endY}`;
        }
        return `M${x} ${y} C${x + Math.max(40, Math.abs(endX - x) / 2)} ${y} ${endX - Math.max(40, Math.abs(endX - x) / 2)} ${endY} ${endX} ${endY}`;
      };
      setWires({
        width: bounds.width,
        height: bounds.height,
        brief: connected ? path(brief.current, prompt.current) : undefined,
        reference: referenceConnected
          ? path(source.current, reference.current)
          : undefined,
      });
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) {
      observer.observe(scene.current);
      for (const child of scene.current.children)
        if (child instanceof HTMLElement) observer.observe(child);
    }
    return () => observer.disconnect();
  }, [connected, referenceConnected, false, stacked]);
  return (
    <div
      ref={scene}
      className="creative-port-scene"
      data-reference={referenceConnected || undefined}
      data-stacked={stacked || undefined}
    >
      <svg
        className="creative-port-scene__wire"
        width={wires.width}
        height={wires.height}
        viewBox={`0 0 ${wires.width} ${wires.height}`}
        aria-hidden="true"
      >
        {wires.brief && <EdgePath d={wires.brief} dataType="text" />}
        {wires.reference && <EdgePath d={wires.reference} dataType="image" />}
      </svg>
      <NodeCard.Root variant="outline">
        <NodeCard.Header>
          <NodeCard.Title>Creative brief</NodeCard.Title>
        </NodeCard.Header>
        <NodeCard.Content>
          <p className="graph-creative-demo__prompt">
            {"Soft morning light. Natural textures with room to breathe."}
          </p>
        </NodeCard.Content>
        <NodePortGroup side={stacked ? "bottom" : "right"}>
          <NodePort
            onActivate={() => setActivePort("brief")}
            indicatorRef={brief}
            label="Brief"
            direction="output"
            variant="core"
            dataType="text"
            connected={connected}
            menuOpen={activePort === "brief"}
          >
            <PortActions
              label="Brief"
              connected={connected}
              onChange={onChange}
              open={activePort === "brief"}
              onOpenChange={(open) => setActivePort(open ? "brief" : null)}
              anchorRef={brief}
            />
          </NodePort>
        </NodePortGroup>
      </NodeCard.Root>
      <NodeCard.Root className="creative-port-scene__target" variant="outline">
        <NodeCard.Header>
          <NodeCard.Title>Image generation</NodeCard.Title>
        </NodeCard.Header>
        <NodeCard.Content>
          <img
            src="/graph-examples/studio-direction.jpg"
            alt="Generated studio image with natural textures"
            draggable={false}
          />
        </NodeCard.Content>
        <NodePortGroup side={stacked ? "top" : "left"} gap={stacked ? 112 : 44}>
          <NodePort
            onActivate={() => setActivePort("prompt")}
            indicatorRef={prompt}
            label="Text"
            direction="input"
            variant="core"
            dataType="text"
            connected={connected}
            menuOpen={activePort === "prompt"}
          >
            <PortActions
              label="Prompt"
              connected={connected}
              onChange={onChange}
              open={activePort === "prompt"}
              onOpenChange={(open) => setActivePort(open ? "prompt" : null)}
              anchorRef={prompt}
            />
          </NodePort>
          <NodePort
            onActivate={() => setActivePort("reference")}
            indicatorRef={reference}
            label="Image"
            direction="input"
            variant="core"
            dataType="image"
            connected={referenceConnected}
            menuOpen={activePort === "reference"}
          >
            <PortActions
              label="Reference"
              connected={referenceConnected}
              onChange={onReferenceChange}
              open={activePort === "reference"}
              onOpenChange={(open) => setActivePort(open ? "reference" : null)}
              anchorRef={reference}
            />
          </NodePort>
        </NodePortGroup>
      </NodeCard.Root>
      {referenceConnected && (
        <NodeCard.Root
          className="creative-port-scene__reference"
          variant="outline"
        >
          <NodeCard.Header>
            <NodeCard.Title>Visual reference</NodeCard.Title>
            <PortActions
              label="Reference source"
              connected
              onChange={onReferenceChange}
            />
          </NodeCard.Header>
          <NodeCard.Content>
            <img
              src="/graph-examples/studio-reference.jpg"
              alt="Water lilies and reflections in a painted pond"
              draggable={false}
            />
          </NodeCard.Content>
          <NodePortGroup side={stacked ? "bottom" : "right"}>
            <NodePort
              onActivate={() => setActivePort("source")}
              indicatorRef={source}
              label="Reference"
              direction="output"
              variant="core"
              dataType="image"
              connected
              menuOpen={activePort === "source"}
            >
              <PortActions
                label="Reference source"
                connected
                onChange={onReferenceChange}
                open={activePort === "source"}
                onOpenChange={(open) => setActivePort(open ? "source" : null)}
                anchorRef={source}
              />
            </NodePort>
          </NodePortGroup>
        </NodeCard.Root>
      )}
    </div>
  );
}

```

node-port-preview-1.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.graph-creative-demo {
  position: relative;
  container-type: inline-size;
  width: 880px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--background);
  color: var(--foreground);
  font-weight: 400;
}
.creative-port-demo {
  box-sizing: border-box;
  width: 760px;
  max-width: 100%;
  padding: 24px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-port-scene {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 32px 128px;
  align-items: center;
  min-width: 0;
  min-height: 240px;
}
.creative-port-scene[data-reference] {
  grid-template-rows: auto auto;
}
.creative-port-scene[data-reference] > .creative-port-scene__target {
  grid-column: 2;
  grid-row: 1/span 2;
}
.creative-port-scene__reference {
  grid-column: 1;
  grid-row: 2;
}
.creative-port-scene > .ui-graph-node {
  position: relative;
  z-index: 1;
  min-width: 0;
}
.creative-port-scene img {
  display: block;
  width: 100%;
  height: 132px;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.creative-port-scene p {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 13px;
  line-height: 20px;
}
.creative-port-scene__wire {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}
@media (max-width: 560px) {
  .creative-port-demo {
    padding: 16px 24px;
  }
}
.creative-port-scene[data-stacked] {
  grid-template-columns: minmax(0, 1fr);
  gap: 88px;
  min-height: 0;
}
.creative-port-scene[data-stacked] > .creative-port-scene__target {
  grid-column: 1;
  grid-row: 2;
}
.creative-port-scene[data-stacked][data-reference] > .creative-port-scene__target {
  grid-row: 3;
}
.creative-port-scene[data-stacked] > .creative-port-scene__reference {
  grid-column: 1;
  grid-row: 2;
}
.creative-port-scene__reference .ui-graph-node__header {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding-inline-end: 0;
}
.creative-port-scene__reference .ui-graph-node__content {
  padding: 0;
}

/* apps/web/src/demos/library/node-port-refinement.css */
.creative-port-demo:not(.creative-port-demo--thumbnail) .creative-port-scene:not([data-stacked]) {
  column-gap: 192px;
}
.creative-port-scene[data-stacked] {
  row-gap: 128px;
}

```

## Design guidance

NodePort has two presentations: a small radio-style core port (the default) and an icon inside a larger circle. An empty core has a border and surface fill; a connected core adds an inner bullet. Empty icon ports use an outline glyph in the content color; connected icon ports add a solid inner circle with a white glyph. Keep one presentation per card. NodePortGroup centers circles on the card border, half inside and half outside.

Labels are separate ghost Badges near the circle. They use the content color and default to visible for core inputs and hidden for outputs and icon ports. Set showLabel to override. Text is indigo, image is emerald, model is sky, audio/music is amber, video is rose, and unknown or output types are neutral. Colors follow chart colorways and describe content; they do not decide compatibility. Outputs carry their type but stay neutral while open; once connected they inherit the connection color, and the edge path shares it when given the same dataType. React Flow remains optional. Caller actions appear on hover or focus and stay visible on touch.

## Installation

```sh
npx shadcn@latest add https://ghost-ui.com/r/node-port.json
```

## Basic usage

```tsx
import { Card } from "@collectivecreation/ghost-ui/components/card";
import { NodePort, NodePortGroup } from "@collectivecreation/ghost-ui/components/node-port";

<Card.Root style={{ position: "relative" }}>
<Card.Header><Card.Title>Image generation</Card.Title></Card.Header>
<NodePortGroup side="left">
  <NodePort label="Prompt" direction="input" dataType="text" connected />
</NodePortGroup>
</Card.Root>
```

## Structures

NodePortGroup lays out direct NodePort children. Ports inside fragments or custom wrappers are not counted or assigned offsets. Each row retains its own identity, indicator and optional caller actions.

- NodePort
  - NodePort indicator (internal slot)
  - NodePort ghost label (optional)
  - NodePort children (optional caller actions)

The label badge is the single trigger for its actions: when the badge opens caller actions, a menu mark appears inside the badge pill on hover or focus (always visible on touch). Do not add a separate trigger button next to the badge; the badge and its mark are one combined pill. Render the menu controlled and anchor its positioner at the port indicator (indicatorRef). Keep actions keyboard reachable through the badge and point controls; do not make connection actions hover-only. Disabled is presentation and callers must also disable supplied handles/actions.

For an SVG connection without React Flow, use indicatorRef to measure the rendered point. The caller owns path geometry and should observe the host and measured content. NodePort does not route edges.

For optional React Flow integration, place each real Handle in its port and call useUpdateNodeInternals when count or geometry changes. Handle IDs and connection policy remain caller-owned; the slot does not implement compatibility. Standalone port owners need no React Flow package.

## Examples

### Port presentation

Choose core or icon presentation, toggle the label, and change the circle size. onActivate opens the same caller-owned actions from the circle or its label. The point stays at the card edge when presentation changes.

node-port-port-presentation-2.jsx

```jsx
import { useState as useState2 } from "react";
import { Button } from "@/components/ui/button";
import { NodeCard } from "@/components/ui/node-card";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { ButtonGroup } from "@/components/ui/button-group";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  const { scene, stacked } = useStackedScene();
  const [variant, setVariant] = useState2("core");
  const [showLabel, setShowLabel] = useState2();
  const [size, setSize] = useState2("lg");
  return (
    <div
      data-preview-wide
      ref={scene}
      data-stacked={stacked || undefined}
      className="creative-port-example"
    >
      <NodeCard.Root className="creative-port-example__card" variant="outline">
        <NodeCard.Header>
          <NodeCard.Title>Image generation</NodeCard.Title>
        </NodeCard.Header>
        <NodeCard.Content>
          <p>Studio image · Landscape</p>
        </NodeCard.Content>
        <NodePortGroup side={stacked ? "top" : "left"} gap={stacked ? 80 : 44}>
          {["text", "image", "model"].map((type) => (
            <NodePort
              key={type}
              label={type.charAt(0).toUpperCase() + type.slice(1)}
              direction="input"
              variant={variant}
              showLabel={showLabel}
              size={size}
              dataType={type}
              connected
            />
          ))}
        </NodePortGroup>
        <NodePortGroup side={stacked ? "bottom" : "right"}>
          <NodePort
            label="Image"
            direction="output"
            variant={variant}
            showLabel={showLabel}
            size={size}
            dataType="image"
          />
        </NodePortGroup>
      </NodeCard.Root>
      <div
        className="creative-port-controls"
        role="group"
        aria-label="Port display options"
      >
        <ButtonGroup aria-label="Port presentation">
          {["icon", "core"].map((value) => (
            <Button
              key={value}
              size="sm"
              variant={variant === value ? "subtle" : "ghost"}
              aria-pressed={variant === value}
              onClick={() => setVariant(value)}
            >
              {value === "icon" ? "Icon" : "Core"}
            </Button>
          ))}
        </ButtonGroup>
        <Button
          size="sm"
          variant="ghost"
          aria-pressed={showLabel ?? variant === "core"}
          onClick={() => setShowLabel(!(showLabel ?? variant === "core"))}
        >
          Label
        </Button>
        <ButtonGroup aria-label="Port size">
          {["sm", "md", "lg", "xl"].map((value) => (
            <Button
              key={value}
              size="sm"
              variant={size === value ? "subtle" : "ghost"}
              aria-pressed={size === value}
              onClick={() => setSize(value)}
            >
              {value === "sm"
                ? "Small"
                : value === "md"
                  ? "Medium"
                  : value === "lg"
                    ? "Large"
                    : "Extra large"}
            </Button>
          ))}
        </ButtonGroup>
      </div>
    </div>
  );
}

function useStackedScene() {
  const scene = useRef(null);
  const [stacked, setStacked] = useState(false);
  useLayoutEffect(() => {
    const measure = () => {
      const width = scene.current?.getBoundingClientRect().width;
      if (width) setStacked(width < 520);
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) observer.observe(scene.current);
    return () => observer.disconnect();
  }, []);
  return {
    scene,
    stacked,
  };
}

```

node-port-port-presentation-2.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-port-example {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
  width: 680px;
  max-width: 100%;
  padding: 64px 112px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-port-example__card {
  position: relative;
  width: 100%;
  min-height: 132px;
  justify-content: center;
}
.creative-port-example__card p {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--muted-foreground);
}
.creative-port-example > .ui-button-group {
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}
@media (max-width: 560px) {
  .creative-port-example {
    gap: 48px;
    padding: 64px 72px;
  }
}
.creative-port-example {
  padding-inline: min(112px, 20%);
}
.creative-port-example__card .ui-graph-node__header {
  padding-inline-end: 0;
}
@media (max-width: 560px) {
  .creative-port-example {
    padding-inline: min(72px, 20%);
  }
}
.creative-port-example[data-stacked] {
  padding-inline: 24px;
  gap: 64px;
}

/* apps/web/src/demos/library/node-port-refinement.css */
.creative-port-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
}
@media (pointer: coarse) {
  .creative-port-controls .ui-button {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
  }
}

```

### Centered port growth

The group adds points symmetrically around the side center. Labels do not change point spacing.

node-port-centered-port-growth-3.jsx

```jsx
import { useState as useState2 } from "react";
import { Button } from "@/components/ui/button";
import { NodeCard } from "@/components/ui/node-card";
import {
  NodePort,
  NodePortGroup,
  getNodePortOffsets,
} from "@/components/ui/node-port";
import { ButtonGroup } from "@/components/ui/button-group";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  const { scene, stacked } = useStackedScene();
  const [count, setCount] = useState2(1);
  const offsets = getNodePortOffsets(count, stacked ? 88 : 44);
  return (
    <div
      data-preview-wide
      ref={scene}
      data-stacked={stacked || undefined}
      className="creative-port-example"
    >
      <NodeCard.Root className="creative-port-example__card" variant="outline">
        <NodeCard.Header>
          <NodeCard.Title>Image generation</NodeCard.Title>
        </NodeCard.Header>
        <NodeCard.Content>
          <p>Compose a product scene</p>
        </NodeCard.Content>
        <NodePortGroup side={stacked ? "top" : "left"}>
          {offsets.map((offset, index) => (
            <NodePort
              key={index}
              dataType="text"
              label={`Prompt ${index + 1}`}
              direction="input"
              offset={offset}
            />
          ))}
        </NodePortGroup>
        <NodePortGroup side={stacked ? "bottom" : "right"}>
          <NodePort
            label="Image"
            direction="output"
            variant="core"
            dataType="image"
          />
        </NodePortGroup>
      </NodeCard.Root>
      <ButtonGroup aria-label="Number of prompt inputs">
        {[1, 2, 3].map((value) => (
          <Button
            key={value}
            size="sm"
            variant={count === value ? "subtle" : "ghost"}
            aria-pressed={count === value}
            onClick={() => setCount(value)}
          >
            {value}
          </Button>
        ))}
      </ButtonGroup>
    </div>
  );
}

function useStackedScene() {
  const scene = useRef(null);
  const [stacked, setStacked] = useState(false);
  useLayoutEffect(() => {
    const measure = () => {
      const width = scene.current?.getBoundingClientRect().width;
      if (width) setStacked(width < 520);
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) observer.observe(scene.current);
    return () => observer.disconnect();
  }, []);
  return {
    scene,
    stacked,
  };
}

```

node-port-centered-port-growth-3.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-port-example {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
  width: 680px;
  max-width: 100%;
  padding: 64px 112px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-port-example__card {
  position: relative;
  width: 100%;
  min-height: 132px;
  justify-content: center;
}
.creative-port-example__card p {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--muted-foreground);
}
.creative-port-example > .ui-button-group {
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}
@media (max-width: 560px) {
  .creative-port-example {
    gap: 48px;
    padding: 64px 72px;
  }
}
.creative-port-example {
  padding-inline: min(112px, 20%);
}
.creative-port-example__card .ui-graph-node__header {
  padding-inline-end: 0;
}
@media (max-width: 560px) {
  .creative-port-example {
    padding-inline: min(72px, 20%);
  }
}
.creative-port-example[data-stacked] {
  padding-inline: 24px;
  gap: 64px;
}

/* apps/web/src/demos/library/node-port-refinement.css */

```

### Port sides

Keep the data direction independent from the side. Choose left/right or top/bottom.

node-port-port-sides-4.jsx

```jsx
import { useState as useState2 } from "react";
import { Button } from "@/components/ui/button";
import { NodeCard } from "@/components/ui/node-card";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { ButtonGroup } from "@/components/ui/button-group";

export default function Example() {
  const [layout, setLayout] = useState2("left-right");
  return (
    <div
      data-preview-wide
      className="creative-port-example creative-port-example--placement"
    >
      <NodeCard.Root className="creative-port-example__card" variant="outline">
        <NodeCard.Header>
          <NodeCard.Title>Creative assistant</NodeCard.Title>
        </NodeCard.Header>
        <NodeCard.Content>
          <p>Summarize the brand direction</p>
        </NodeCard.Content>
        <NodePortGroup side={layout === "left-right" ? "left" : "top"}>
          <NodePort
            label="Brief"
            direction="input"
            variant="core"
            dataType="text"
          />
        </NodePortGroup>
        <NodePortGroup side={layout === "top-bottom" ? "bottom" : "right"}>
          <NodePort
            label="Image"
            direction="output"
            variant="core"
            dataType="image"
          />
        </NodePortGroup>
      </NodeCard.Root>
      <ButtonGroup aria-label="Port side layout">
        {["left-right", "top-bottom"].map((value) => (
          <Button
            key={value}
            size="sm"
            variant={layout === value ? "subtle" : "ghost"}
            aria-pressed={layout === value}
            onClick={() => setLayout(value)}
          >
            {value === "left-right" ? "Left / right" : "Top / bottom"}
          </Button>
        ))}
      </ButtonGroup>
    </div>
  );
}

```

node-port-port-sides-4.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-port-example {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
  width: 680px;
  max-width: 100%;
  padding: 64px 112px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-port-example__card {
  position: relative;
  width: 100%;
  min-height: 132px;
  justify-content: center;
}
.creative-port-example__card p {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--muted-foreground);
}
.creative-port-example > .ui-button-group {
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}
@media (max-width: 560px) {
  .creative-port-example {
    gap: 48px;
    padding: 64px 72px;
  }
}
.creative-port-example {
  padding-inline: min(112px, 20%);
}
.creative-port-example__card .ui-graph-node__header {
  padding-inline-end: 0;
}
@media (max-width: 560px) {
  .creative-port-example {
    padding-inline: min(72px, 20%);
  }
}
.creative-port-example[data-stacked] {
  padding-inline: 24px;
  gap: 64px;
}
.creative-port-example--placement {
  padding-inline: min(112px, 28%);
}

/* apps/web/src/demos/library/node-port-refinement.css */

```

### Connection and recovery

The caller supplies connection state and a specific invalid reason. The recovery keeps the same image input and replaces the incompatible source.

node-port-connection-and-recovery-5.jsx

```jsx
import { useState as useState2 } from "react";
import { Button } from "@/components/ui/button";
import { NodeCard } from "@/components/ui/node-card";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { ButtonGroup } from "@/components/ui/button-group";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  const { scene, stacked } = useStackedScene();
  const [state, setState] = useState2("open");
  return (
    <div
      data-preview-wide
      ref={scene}
      data-stacked={stacked || undefined}
      className="creative-port-example"
    >
      <NodeCard.Root className="creative-port-example__card" variant="outline">
        <NodeCard.Header>
          <NodeCard.Title>Image generation</NodeCard.Title>
        </NodeCard.Header>
        <NodeCard.Content>
          <p>Reference image</p>
          {state === "invalid" && (
            <Button
              size="sm"
              variant="ghost"
              onClick={() => setState("connected")}
            >
              Use an image source
            </Button>
          )}
        </NodeCard.Content>
        <NodePortGroup side="top">
          <NodePort
            label="Image"
            direction="input"
            variant="core"
            dataType="image"
            connected={state === "connected"}
            disabled={state === "disabled"}
            error={
              state === "invalid"
                ? "Text cannot connect to an image input."
                : undefined
            }
          />
        </NodePortGroup>
      </NodeCard.Root>
      <ButtonGroup aria-label="Reference input state">
        {["open", "connected", "invalid", "disabled"].map((value) => (
          <Button
            key={value}
            size="sm"
            variant={state === value ? "subtle" : "ghost"}
            aria-pressed={state === value}
            onClick={() => setState(value)}
          >
            {value.charAt(0).toUpperCase() + value.slice(1)}
          </Button>
        ))}
      </ButtonGroup>
    </div>
  );
}

function useStackedScene() {
  const scene = useRef(null);
  const [stacked, setStacked] = useState(false);
  useLayoutEffect(() => {
    const measure = () => {
      const width = scene.current?.getBoundingClientRect().width;
      if (width) setStacked(width < 520);
    };
    measure();
    const observer = new ResizeObserver(measure);
    if (scene.current) observer.observe(scene.current);
    return () => observer.disconnect();
  }, []);
  return {
    scene,
    stacked,
  };
}

```

node-port-connection-and-recovery-5.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.creative-port-example {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
  width: 680px;
  max-width: 100%;
  padding: 64px 112px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-port-example__card {
  position: relative;
  width: 100%;
  min-height: 132px;
  justify-content: center;
}
.creative-port-example__card p {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--muted-foreground);
}
.creative-port-example > .ui-button-group {
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}
@media (max-width: 560px) {
  .creative-port-example {
    gap: 48px;
    padding: 64px 72px;
  }
}
.creative-port-example {
  padding-inline: min(112px, 20%);
}
.creative-port-example__card .ui-graph-node__header {
  padding-inline-end: 0;
}
@media (max-width: 560px) {
  .creative-port-example {
    padding-inline: min(72px, 20%);
  }
}
.creative-port-example[data-stacked] {
  padding-inline: 24px;
  gap: 64px;
}

/* apps/web/src/demos/library/node-port-refinement.css */

```

## API reference

NodePort API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| label | string | — | Visible and accessible port name. |
| variant | 'core' \| 'icon' | 'core' | Radio-style point or content glyph inside a circle. Keep one variant per card. |
| showLabel | boolean | — | Show a separate ghost Badge. Defaults to true for core inputs and false for outputs and icon ports. |
| size | 'sm' \| 'md' \| 'lg' \| 'xl' | 'md' core, 'lg' icon | Core diameters: 10 / 12 / 16 / 20px. Icon diameters: 20 / 24 / 28 / 32px with 8 / 10 / 12 / 14px glyphs. The activation target is 44px in canvas coordinates; canvas zoom scales its screen size. |
| placement / offset | 'left' \| 'right' \| 'top' \| 'bottom'; number | — | Optional placed position and pixel displacement from the side center. Existing row layout remains the default. |
| icon | ReactNode | — | Optional icon-port glyph. Text uses Type, image uses Image, model uses Cpu, audio/music uses Music, video uses Video; unknown types use a direction-aware arrow. |
| connectedIcon | ReactNode | — | Optional filled representation for a custom connected icon. |
| getNodePortOffsets(count, gap?) | number[] | — | Returns symmetric pixel offsets. Count must be a nonnegative integer; gap must be finite and nonnegative. Gap defaults to 24. |
| error | string | — | Visible caller supplied invalid reason associated with this port. |
| direction | 'input' \| 'output' | — | Sets row alignment and direction context. Outputs render as neutral radio points while open and inherit the connection color once connected. |
| dataType | string | — | Open content type. Known values text, image, model, audio/music and video have chart-aligned colors; unknown values remain neutral, and outputs stay neutral until connected. |
| connected / invalid / disabled | boolean | false | Caller supplied presentation states. Invalid also describes the state accessibly. |
| onActivate | () => void | — | Opens caller-owned actions when the point or badge is activated. Disabled ports do not call it. |
| handle | ReactNode | — | Optional integration handle. Its identity, events and ref are preserved; the port adds accessible connection state and descriptions. |
| indicatorRef | Ref<HTMLSpanElement> | — | Optional ref to the indicator slot for caller-owned geometry. With a native handle, the engine still owns handle measurement. |
| children | ReactNode | — | Optional caller action content (for example a controlled menu). The badge is the single visible trigger and shows a trailing menu mark; anchor menus at the port indicator instead of adding a separate trigger button. |
| NodePortGroup | div props; side, gap, children | — | Centers direct NodePort children on a card side with symmetric offsets. Defaults to 44px side spacing and 64px top/bottom spacing. |
| native div props and ref | HTMLAttributes<HTMLDivElement>; HTMLDivElement | — | Forwarded to the root row. Caller aria-label overrides its default; aria-describedby extends the generated descriptions. |
