# Node card

Compose a node shell from the same Card layout parts.

## Preview

node-card-preview-1.jsx

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

export default function Example() {
  const { scene, stacked } = useStackedScene();
  return (
    <div
      data-preview-wide
      ref={scene}
      data-stacked={stacked || undefined}
      className="creative-node-demo"
    >
      <GenerationCard verticalPorts={stacked} />
    </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,
  };
}

function GenerationCard({
  selected = false,
  status = "idle",
  compact = false,
  verticalPorts = false,
}) {
  return (
    <NodeCard.Root
      variant="outline"
      className="graph-node-demo__card"
      selected={false}
      status={"idle"}
      aria-label="Image generation"
    >
      <NodeCard.Header>
        <NodeCard.Title>Image generation</NodeCard.Title>
        <NodeCard.Description>Spring campaign</NodeCard.Description>
      </NodeCard.Header>
      <NodeCard.Content>
        <img
          className="graph-node-demo__media"
          src="/graph-examples/studio-direction.jpg"
          alt="A painted house near the Mediterranean shore"
          draggable={false}
        />
      </NodeCard.Content>
      <NodeCard.Footer>
        <span>{"Studio image"}</span>
        <span>16:9</span>
      </NodeCard.Footer>
      <NodePortGroup
        side={verticalPorts ? "top" : "left"}
        gap={verticalPorts ? 96 : 32}
      >
        <NodePort
          label="Text"
          direction="input"
          variant="core"
          showLabel={undefined}
          dataType="text"
          connected
        />
        <NodePort
          label="Image"
          direction="input"
          variant="core"
          showLabel={undefined}
          dataType="image"
          connected
        />
      </NodePortGroup>
      <NodePortGroup side={verticalPorts ? "bottom" : "right"}>
        <NodePort
          label="Image"
          direction="output"
          variant="core"
          dataType="image"
          connected={true}
        />
      </NodePortGroup>
    </NodeCard.Root>
  );
}

```

node-card-preview-1.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.graph-node-demo__card {
  position: relative;
  width: 320px;
  max-width: 100%;
  gap: 12px;
}
.graph-node-demo__media {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.creative-node-demo {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  width: 680px;
  max-width: 100%;
  padding: 40px 112px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-node-demo .graph-node-demo__card {
  width: 320px;
  max-width: 100%;
}
.creative-node-demo .ui-graph-node__header {
  flex-direction: column;
  gap: 4px;
}
.creative-node-demo .ui-graph-node__content {
  padding: 0;
}
.creative-node-demo .ui-graph-node__description {
  font-size: 12px;
}
@media (max-width: 560px) {
  .creative-node-demo {
    padding: 40px 72px;
  }
}
.creative-node-demo {
  padding-inline: min(112px, 20%);
}
.creative-node-demo .ui-graph-node__header {
  padding-inline-end: 0;
}
@media (max-width: 560px) {
  .creative-node-demo {
    padding-inline: min(72px, 20%);
  }
}
.creative-node-demo[data-stacked] {
  padding-inline: 24px;
  padding-top: 64px;
}

```

## Design guidance

Use NodeCard only when a graph node needs selected, dragging or status styling. It is a thin adapter over the real Card parts; it does not provide geometry, ports or graph behavior. Use Card with NodePortGroup for an ordinary prompt or media node, and LayerCard for stacked model configuration. Selected and status values are caller facts. Disabled styling does not disable child controls.

## Installation

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

NodeCard and Card are React components with no React Flow runtime dependency. React Flow is an optional caller integration; its renderer may compose this owner inside the native node element.

## Basic usage

```tsx
import { NodeCard } from "@collectivecreation/ghost-ui/components/node-card";

<NodeCard.Root variant="outline">
<NodeCard.Header><NodeCard.Title>Research</NodeCard.Title></NodeCard.Header>
<NodeCard.Content>Preparing the source review</NodeCard.Content>
<NodeCard.Footer>In progress</NodeCard.Footer>
</NodeCard.Root>
```

## Structures

- NodeCard.Root
  - NodeCard.Header (optional)
    - NodeCard.Title
    - NodeCard.Description (optional)
  - NodeCard.Content (optional)
  - NodeCard.Footer (optional)
    - NodeCard.Actions (optional)

## Examples

### Card alternatives

The preview uses NodeCard for a real image direction task. These alternatives show plain Card with the same ports and LayerCard for configuration. Choose the adapter only when its graph state styling is needed.

node-card-card-alternatives-2.jsx

```jsx
import { Card } from "@/components/ui/card";
import { LayerCard } from "@/components/ui/layer-card";
import { NodePort, NodePortGroup } from "@/components/ui/node-port";
import { useLayoutEffect, useRef, useState } from "react";

export default function Example() {
  const { scene, stacked } = useStackedScene();
  return (
    <div
      data-preview-wide
      ref={scene}
      className="graph-node-demo__alternatives"
    >
      <Card.Root variant="outline" className="graph-node-demo__card">
        <Card.Header>
          <Card.Title>Creative brief</Card.Title>
        </Card.Header>
        <Card.Content>
          <p>Soft coastal light. Natural textures with room to breathe.</p>
        </Card.Content>
        <NodePortGroup side={stacked ? "bottom" : "right"}>
          <NodePort
            label="Text"
            direction="output"
            variant="core"
            dataType="text"
          />
        </NodePortGroup>
      </Card.Root>
      <LayerCard
        variant="compact"
        className="creative-node-layer"
        aria-label="Model configuration"
      >
        <LayerCard.Secondary>Image settings</LayerCard.Secondary>
        <LayerCard.Primary>
          <p>Studio image</p>
          <p>Landscape · 16:9</p>
        </LayerCard.Primary>
        <NodePortGroup side="bottom">
          <NodePort label="Settings" direction="output" variant="core" />
        </NodePortGroup>
      </LayerCard>
    </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-card-card-alternatives-2.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.graph-node-demo__card {
  position: relative;
  width: 320px;
  max-width: 100%;
  gap: 12px;
}
.graph-node-demo__alternatives {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  width: 760px;
  max-width: 100%;
  padding: 24px;
}
.graph-node-demo__alternatives > .graph-node-demo__card {
  width: auto;
}
.graph-node-demo__alternatives .ui-layer-card {
  min-width: 0;
}
@media (max-width: 560px) {
  .graph-node-demo__alternatives {
    grid-template-columns: minmax(0, 1fr);
  }
}
.graph-node-demo__alternatives {
  box-sizing: border-box;
  gap: 64px;
  padding: 40px 72px 64px;
}
.graph-node-demo__alternatives p {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  font-weight: 400;
}
.creative-node-layer {
  position: relative;
  overflow: visible;
  align-self: start;
}
.creative-node-layer .ui-layer-card__primary {
  display: grid;
  gap: 8px;
}
.graph-node-demo__alternatives {
  padding-inline: min(72px, 12%);
}
.graph-node-demo__alternatives {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}

```

### Node appearance

Selected, running and error are caller-supplied appearance states. They do not execute a model or disable child controls. Choose a state to inspect the same card.

node-card-node-appearance-3.jsx

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

export default function Example() {
  const { scene, stacked } = useStackedScene();
  const [state, setState] = useState2("selected");
  return (
    <div
      data-preview-wide
      ref={scene}
      data-stacked={stacked || undefined}
      className="creative-node-demo creative-node-demo--states"
    >
      <GenerationCard
        verticalPorts={stacked}
        selected={state === "selected"}
        status={state === "selected" ? "idle" : state}
      />
      <ButtonGroup aria-label="Node appearance">
        {["idle", "selected", "running", "error"].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,
  };
}

function GenerationCard({
  selected = false,
  status = "idle",
  compact = false,
  verticalPorts = false,
}) {
  return (
    <NodeCard.Root
      variant="outline"
      className="graph-node-demo__card"
      selected={selected}
      status={status}
      aria-label="Image generation"
    >
      <NodeCard.Header>
        <NodeCard.Title>Image generation</NodeCard.Title>
        <NodeCard.Description>Spring campaign</NodeCard.Description>
      </NodeCard.Header>
      <NodeCard.Content>
        <img
          className="graph-node-demo__media"
          src="/graph-examples/studio-direction.jpg"
          alt="A painted house near the Mediterranean shore"
          draggable={false}
        />
      </NodeCard.Content>
      <NodeCard.Footer>
        <span>
          {status === "running"
            ? "Generating\u2026"
            : status === "error"
              ? "Generation failed. Try again."
              : "Studio image"}
        </span>
        <span>16:9</span>
      </NodeCard.Footer>
      <NodePortGroup
        side={verticalPorts ? "top" : "left"}
        gap={verticalPorts ? 96 : 32}
      >
        <NodePort
          label="Text"
          direction="input"
          variant="core"
          showLabel={undefined}
          dataType="text"
          connected
        />
        <NodePort
          label="Image"
          direction="input"
          variant="core"
          showLabel={undefined}
          dataType="image"
          connected
        />
      </NodePortGroup>
      <NodePortGroup side={verticalPorts ? "bottom" : "right"}>
        <NodePort
          label="Image"
          direction="output"
          variant="core"
          dataType="image"
          connected={status === "idle"}
        />
      </NodePortGroup>
    </NodeCard.Root>
  );
}

```

node-card-node-appearance-3.css

```css
/* apps/web/src/demos/library/graph-creative-demo.css */
.graph-node-demo__card {
  position: relative;
  width: 320px;
  max-width: 100%;
  gap: 12px;
}
.graph-node-demo__media {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.creative-node-demo {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  width: 680px;
  max-width: 100%;
  padding: 40px 112px;
  color: var(--foreground);
  font-weight: 400;
}
.creative-node-demo .graph-node-demo__card {
  width: 320px;
  max-width: 100%;
}
.creative-node-demo .ui-graph-node__header {
  flex-direction: column;
  gap: 4px;
}
.creative-node-demo .ui-graph-node__content {
  padding: 0;
}
.creative-node-demo .ui-graph-node__description {
  font-size: 12px;
}
.creative-node-demo--states > .ui-button-group {
  flex-wrap: wrap;
  justify-content: center;
}
@media (max-width: 560px) {
  .creative-node-demo {
    padding: 40px 72px;
  }
}
.creative-node-demo {
  padding-inline: min(112px, 20%);
}
.creative-node-demo .ui-graph-node__header {
  padding-inline-end: 0;
}
@media (max-width: 560px) {
  .creative-node-demo {
    padding-inline: min(72px, 20%);
  }
}
.creative-node-demo[data-stacked] {
  padding-inline: 24px;
  padding-top: 64px;
}

```

## API reference

NodeCard API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| NodeCard.Root | Card root props plus graph states | — | Forwards Card layout, variant, density, native attributes and div ref. Density defaults to compact. |
| selected / interactive / stagedParent | boolean | false | Independent appearance states retained for Diagram and custom renderers. |
| disabled / dragging | boolean | false | Presentation only. Disable descendant controls and graph handles at their owners. |
| status | 'idle' \| 'running' \| 'success' \| 'error' | 'idle' | Caller supplied node appearance. It does not trigger work or authorize a descendant action. |
| NodeCard.Header / Title / Description / Content / Footer / Actions | Card part props | — | Optional layout slots that retain Card native attributes and render composition. |
