{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "graph-node",
  "title": "Graph Node",
  "description": "The parts of a node for graph and flow editors, as plain markup: a box, a card, header, content and footer, with room on either side for connectors. Four sizes, fixed and fluid widths, palette tones, a subflow variant, and statuses with a badge for showing a call as it plays. No canvas, wires or script.",
  "dependencies": [
    "@base-ui/react@^1.8.0",
    "class-variance-authority@^0.7.1",
    "lucide-react@^1.41.0"
  ],
  "registryDependencies": [
    "button",
    "@pipecat/graph-tone"
  ],
  "files": [
    {
      "path": "src/components/graph/node.tsx",
      "content": "\"use client\";\n\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { Maximize2Icon } from \"lucide-react\";\n\nimport {\n  type GraphTone,\n  graphToneStyle,\n} from \"@/components/pipecat/graph/tone\";\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\n\n/*\n * A node's sizes are variables on its root, in steps of the theme's spacing.\n * `fluid` changes the width alone: the content column takes the slack and\n * everything else keeps its size.\n */\nconst nodeVariants = cva(\n  [\n    \"group/node @container/node relative isolate grid\",\n    \"grid-cols-[auto_minmax(0,1fr)_auto] grid-rows-[auto_minmax(0,1fr)_auto]\",\n    \"[grid-template-areas:'header_header_header'_'left_content_right'_'footer_footer_footer']\",\n    // The body gives up its padding on a side that meets a header or a footer.\n    \"[--node-body-pb:var(--node-py)] [--node-body-pt:var(--node-py)] has-data-[slot=node-footer]:[--node-body-pb:0px] has-data-[slot=node-header]:[--node-body-pt:0px]\",\n    // A status takes the node's own tone until it is given one. The tint is\n    // its soft shade, mixed from the tone if none is pinned.\n    \"[--node-status-soft:var(--graph-tone-soft)] [--node-status-tint:var(--node-status-soft,color-mix(in_oklab,var(--node-status)_14%,var(--card)))] [--node-status:var(--graph-tone,var(--graph-neutral))]\",\n  ],\n  {\n    variants: {\n      size: {\n        sm: [\n          \"[--node-width:--spacing(48)] [--node-radius:var(--radius)]\",\n          \"[--node-gap:--spacing(1.5)] [--node-px:--spacing(2.5)] [--node-py:--spacing(2)]\",\n          \"[--node-text:--spacing(3)] [--node-text-header:--spacing(3)] [--node-text-description:--spacing(2.75)]\",\n        ],\n        md: [\n          \"[--node-width:--spacing(60)] [--node-radius:calc(var(--radius)*1.4)]\",\n          \"[--node-gap:--spacing(2)] [--node-px:--spacing(3)] [--node-py:--spacing(2.5)]\",\n          \"[--node-text:--spacing(3.5)] [--node-text-header:--spacing(3.5)] [--node-text-description:--spacing(3)]\",\n        ],\n        lg: [\n          \"[--node-width:--spacing(72)] [--node-radius:calc(var(--radius)*1.4)]\",\n          \"[--node-gap:--spacing(2.5)] [--node-px:--spacing(4)] [--node-py:--spacing(3)]\",\n          \"[--node-text:--spacing(4)] [--node-text-header:--spacing(4)] [--node-text-description:--spacing(3.5)]\",\n        ],\n        xl: [\n          \"[--node-width:--spacing(88)] [--node-radius:calc(var(--radius)*1.8)]\",\n          \"[--node-gap:--spacing(3)] [--node-px:--spacing(5)] [--node-py:--spacing(4)]\",\n          \"[--node-text:--spacing(4.5)] [--node-text-header:--spacing(4.5)] [--node-text-description:--spacing(4)]\",\n        ],\n      },\n      fluid: {\n        false: \"w-(--node-width)\",\n        true: \"w-full\",\n      },\n      variant: {\n        default: \"\",\n        // Two cards peeking out below, in the node's tone: it holds a graph of its own.\n        subflow: [\n          \"before:absolute before:inset-x-4 before:-bottom-3.5 before:-z-1 before:h-8 before:rounded-(--node-radius) before:bg-graph-tone-mid/50\",\n          \"after:absolute after:inset-x-2 after:-bottom-2 after:-z-1 after:h-8 after:rounded-(--node-radius) after:bg-graph-tone-mid\",\n        ],\n      },\n    },\n    defaultVariants: { size: \"md\", fluid: false, variant: \"default\" },\n  },\n);\n\nexport type NodeSize = NonNullable<VariantProps<typeof nodeVariants>[\"size\"]>;\n\n/** What a call is doing at a node while it plays. */\nexport type NodeStatus = \"idle\" | \"active\" | \"guard\" | \"error\";\n\n/** The tone a status takes unless the node names one. The rest take the node's own. */\nconst STATUS_TONES: Partial<Record<NodeStatus, GraphTone>> = {\n  guard: \"amber\",\n  error: \"red\",\n};\n\n/** A status's tone under names of its own, so the node's tone stays as it is. */\nfunction statusToneStyle(tone: GraphTone | undefined) {\n  const scope = graphToneStyle(tone) as Record<string, string> | undefined;\n  return (\n    scope && {\n      \"--node-status\": scope[\"--graph-tone\"],\n      \"--node-status-soft\": scope[\"--graph-tone-soft\"],\n    }\n  );\n}\n\nexport interface GraphNodeProps extends useRender.ComponentProps<\"div\"> {\n  /** Width, padding, type and connector sizes. */\n  size?: NodeSize;\n  /** Fill the parent's width. Type, padding and connectors keep their size. */\n  fluid?: boolean;\n  /** `subflow` draws a stack of cards behind the node. */\n  variant?: NonNullable<VariantProps<typeof nodeVariants>[\"variant\"]>;\n  /** The palette tone the node's parts take: ports, the stack, `bg-graph-tone-soft`. */\n  tone?: GraphTone;\n  /**\n   * What a call is doing here, shown on the card: `active` rings it and\n   * pulses, `guard` and `error` ring and tint it. An error also shakes it once.\n   */\n  status?: NodeStatus;\n  /**\n   * The tone of the status, apart from the node's. Amber for a guard and red\n   * for an error unless set; otherwise the node's own.\n   */\n  statusTone?: GraphTone;\n}\n\n/**\n * The node's box: its width, its sizes and the tracks its parts sit on. It\n * paints nothing and is the size container, so it needs a width from `size`\n * or its parent, never from its content.\n */\nexport function GraphNode({\n  size = \"md\",\n  fluid = false,\n  variant = \"default\",\n  tone,\n  status = \"idle\",\n  statusTone = STATUS_TONES[status],\n  className,\n  render,\n  ...props\n}: GraphNodeProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(nodeVariants({ size, fluid, variant }), className),\n        style: {\n          ...graphToneStyle(tone),\n          ...statusToneStyle(statusTone),\n        },\n      },\n      props,\n    ),\n    state: {\n      slot: \"node\",\n      size,\n      fluid,\n      variant,\n      tone,\n      // On the node only while it has one, so `data-status` means \"not idle\".\n      status: status === \"idle\" ? undefined : status,\n    },\n  });\n}\n\nexport type NodeCardProps = useRender.ComponentProps<\"div\">;\n\n/**\n * The surface. A subgrid of the node, so parts line up whether they sit inside\n * the card or beside it. Leave overflow visible: ports straddle its edge.\n */\nexport function NodeCard({ className, render, ...props }: NodeCardProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(\n          // Its own line height, so a node reads the same wherever it is placed,\n          // and long words wrap rather than spill out of a fixed width.\n          \"bg-card text-card-foreground ring-foreground/10 relative col-span-full row-span-full grid grid-cols-subgrid grid-rows-subgrid rounded-(--node-radius) text-(length:--node-text) leading-snug wrap-break-word ring-1\",\n          // What each status does to the card, spelled out so one can be restyled alone.\n          \"transition-[box-shadow,background-color] duration-200\",\n          \"group-data-[status=active]/node:animate-node-glow group-data-[status=active]/node:ring-3 group-data-[status=active]/node:ring-(--node-status)\",\n          \"group-data-[status=guard]/node:bg-(--node-status-tint) group-data-[status=guard]/node:ring-3 group-data-[status=guard]/node:ring-(--node-status)\",\n          \"group-data-[status=error]/node:animate-node-shake group-data-[status=error]/node:bg-(--node-status-tint) group-data-[status=error]/node:ring-3 group-data-[status=error]/node:ring-(--node-status)\",\n          \"motion-reduce:group-data-[status=active]/node:animate-none motion-reduce:group-data-[status=error]/node:animate-none\",\n          // Forced colours drop the ring and would draw the pulse solid: a plain outline instead.\n          \"forced-colors:group-data-status/node:outline-2 forced-colors:group-data-[status=active]/node:animate-none\",\n          className,\n        ),\n      },\n      props,\n    ),\n    state: { slot: \"node-card\" },\n  });\n}\n\nexport type NodeHeaderProps = useRender.ComponentProps<\"div\">;\n\nexport function NodeHeader({ className, render, ...props }: NodeHeaderProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(\n          \"grid min-w-0 auto-rows-min items-center gap-x-(--node-gap) gap-y-[calc(var(--node-gap)/4)] rounded-t-(--node-radius) px-(--node-px) py-(--node-py) text-(length:--node-text-header) [grid-area:header] has-data-[slot=node-action]:grid-cols-[minmax(0,1fr)_auto]\",\n          className,\n        ),\n      },\n      props,\n    ),\n    state: { slot: \"node-header\" },\n  });\n}\n\nexport type NodeTitleProps = useRender.ComponentProps<\"div\">;\n\nexport function NodeTitle({ className, render, ...props }: NodeTitleProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(\"font-heading min-w-0 truncate font-medium\", className),\n      },\n      props,\n    ),\n    state: { slot: \"node-title\" },\n  });\n}\n\nexport type NodeDescriptionProps = useRender.ComponentProps<\"div\">;\n\nexport function NodeDescription({\n  className,\n  render,\n  ...props\n}: NodeDescriptionProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(\n          \"text-muted-foreground min-w-0 text-(length:--node-text-description)\",\n          className,\n        ),\n      },\n      props,\n    ),\n    state: { slot: \"node-description\" },\n  });\n}\n\nexport type NodeActionProps = useRender.ComponentProps<\"div\">;\n\n/** Trailing controls in a header, beside the title and description. */\nexport function NodeAction({ className, render, ...props }: NodeActionProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(\n          \"col-start-2 row-span-2 row-start-1 flex items-center gap-(--node-gap) self-start justify-self-end\",\n          className,\n        ),\n      },\n      props,\n    ),\n    state: { slot: \"node-action\" },\n  });\n}\n\n/** An icon-only button needs a name: one of these has to be given. */\ntype Named =\n  | { \"aria-label\": string }\n  | { \"aria-labelledby\": string }\n  | { children: React.ReactNode };\n\nexport type NodeExpandProps = React.ComponentProps<typeof Button> & Named;\n\n/**\n * The button that opens a subflow node, tinted with the node's tone. It goes\n * in `NodeAction`; name what it opens with `aria-label`.\n */\nexport function NodeExpand({ className, children, ...props }: NodeExpandProps) {\n  return (\n    <Button\n      variant=\"secondary\"\n      size=\"icon-sm\"\n      {...props}\n      data-slot=\"node-expand\"\n      className={cn(\n        \"bg-graph-tone-soft text-graph-tone-ink hover:bg-graph-tone-mid/50 aria-expanded:bg-graph-tone-mid/50 aria-expanded:text-graph-tone-ink\",\n        className,\n      )}\n    >\n      {children ?? <Maximize2Icon aria-hidden />}\n    </Button>\n  );\n}\n\nexport type NodeStatusBadgeProps = useRender.ComponentProps<\"span\">;\n\n/**\n * The chip on a node's top edge that says what it is doing. Its dot is in the\n * node's status tone, and it pops in when it is added.\n */\nexport function NodeStatusBadge({\n  className,\n  render,\n  ...props\n}: NodeStatusBadgeProps) {\n  return useRender({\n    defaultTagName: \"span\",\n    render,\n    props: mergeProps<\"span\">(\n      {\n        className: cn(\n          \"bg-foreground text-background absolute top-0 right-(--node-px) z-1 max-w-[calc(100%-var(--node-px)*2)] -translate-y-1/2 truncate rounded-full px-[0.8em] py-[0.35em] text-(length:--node-text-description) leading-tight font-medium shadow-sm forced-colors:outline\",\n          // The dot leans towards the text's colour, so it shows on the chip in either theme.\n          \"before:mr-[0.5em] before:inline-block before:size-[0.5em] motion-safe:before:animate-pulse before:rounded-full before:bg-[color-mix(in_oklab,var(--node-status)_70%,var(--background))] before:align-[0.1em]\",\n          \"transition-[scale,opacity] duration-200 ease-[cubic-bezier(0.34,1.56,0.64,1)] motion-reduce:transition-none starting:scale-50 starting:opacity-0\",\n          className,\n        ),\n      },\n      props,\n    ),\n    state: { slot: \"node-status-badge\" },\n  });\n}\n\nexport type NodeContentProps = useRender.ComponentProps<\"div\">;\n\nexport function NodeContent({ className, render, ...props }: NodeContentProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(\n          \"flex min-w-0 flex-col gap-(--node-gap) px-(--node-px) pt-(--node-body-pt) pb-(--node-body-pb) [grid-area:content]\",\n          className,\n        ),\n      },\n      props,\n    ),\n    state: { slot: \"node-content\" },\n  });\n}\n\nexport type NodeFooterProps = useRender.ComponentProps<\"div\">;\n\nexport function NodeFooter({ className, render, ...props }: NodeFooterProps) {\n  return useRender({\n    defaultTagName: \"div\",\n    render,\n    props: mergeProps<\"div\">(\n      {\n        className: cn(\n          \"flex min-w-0 items-center gap-(--node-gap) rounded-b-(--node-radius) px-(--node-px) py-(--node-py) [grid-area:footer]\",\n          className,\n        ),\n      },\n      props,\n    ),\n    state: { slot: \"node-footer\" },\n  });\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/graph/node.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "animate-node-glow": "node-glow 1.8s ease-out infinite",
      "animate-node-shake": "node-shake 0.45s ease-in-out"
    }
  },
  "css": {
    "@keyframes node-glow": {
      "0%": {
        "outline": "0 solid color-mix(in oklab, var(--node-status) 50%, transparent)",
        "outline-offset": "3px"
      },
      "70%": {
        "outline": "14px solid transparent",
        "outline-offset": "3px"
      },
      "100%": {
        "outline": "0 solid transparent",
        "outline-offset": "3px"
      }
    },
    "@keyframes node-shake": {
      "20%": {
        "translate": "-6px"
      },
      "40%": {
        "translate": "6px"
      },
      "60%": {
        "translate": "-4px"
      },
      "80%": {
        "translate": "4px"
      }
    }
  },
  "docs": "Compose GraphNode > NodeCard > NodeHeader, NodeContent and NodeFooter; add connectors with @pipecat/graph-node-connector. GraphNode is a size container: give it a width with size, or fluid to fill its parent. Give a node a tone to colour it from the graph palette. During playback set status (active, guard, error) and statusTone on GraphNode, and put a NodeStatusBadge inside it to say the status in words. Restyle through className and the --node-* variables; every part takes Base UI's render prop.",
  "categories": [
    "graph"
  ],
  "type": "registry:component"
}