Anchor Port
Mark input, output, and bidirectional ports on React canvas nodes. Anchor Port is a color-coded marker with side and state variants. Install via the shadcn CLI.
What it is & when to use
Anchor Port is a small presentational marker for the connection points on a canvas node. It renders a colored dot that signals whether a port is an input, an output, or bidirectional, using a distinct tone for each. Side props place it on the top, right, bottom, or left edge, and state props show it as idle, active, or blocked. It carries an image role and a descriptive label, so screen readers announce each port. Reach for it when wiring node-based editors or flow diagrams.
Browse all UtilityPreview
Switch between light and dark to inspect the embedded Storybook preview.
Installation
pnpm dlx shadcn@latest add https://ui.vllnt.com/r/anchor-port.jsonStorybook
Explore all variants, controls, and accessibility checks in the interactive Storybook playground.
View in StorybookCode
import { cn } from "../../lib/utils";
export type AnchorPortProps = React.ComponentPropsWithoutRef<"span"> & {
side?: "bottom" | "left" | "right" | "top";
state?: "active" | "blocked" | "idle";
tone?: "bidirectional" | "input" | "output";
};
const toneClasses: Record<NonNullable<AnchorPortProps["tone"]>, string> = {
bidirectional:
"border-violet-500/40 bg-violet-500/15 text-violet-700 dark:text-violet-300",
input: "border-sky-500/40 bg-sky-500/15 text-sky-700 dark:text-sky-300",
output:
"border-emerald-500/40 bg-emerald-500/15 text-emerald-700 dark:text-emerald-300",
};
const stateClasses: Record<NonNullable<AnchorPortProps["state"]>, string> = {
active: "scale-100 opacity-100",
blocked: "opacity-60 saturate-50",
idle: "opacity-80",
};
const sideClasses: Record<NonNullable<AnchorPortProps["side"]>, string> = {
bottom: "self-end",
left: "self-start",
right: "self-end",
top: "self-start",
};
const AnchorPort = ({
className,
ref,
side = "right",
state = "idle",
tone = "bidirectional",
...props
}: AnchorPortProps & { ref?: React.Ref<HTMLSpanElement> }) => (
<span
aria-label={props["aria-label"] ?? `${tone} ${side} port ${state}`}
className={cn(
"inline-flex size-7 items-center justify-center rounded-full border shadow-sm",
toneClasses[tone],
stateClasses[state],
sideClasses[side],
className,
)}
data-side={side}
data-state={state}
data-tone={tone}
ref={ref}
role="img"
{...props}
>
<span className="size-2.5 rounded-full bg-current" />
</span>
);
AnchorPort.displayName = "AnchorPort";
export { AnchorPort };
Frequently asked questions
- What is Anchor Port?
- Anchor Port is a React component that renders a small color-coded marker for the connection points on a canvas node, signaling whether a port is an input, an output, or a bidirectional link. It is pure presentation — the host owns wiring and drag logic.
- How do I add Anchor Port?
- Run `pnpm dlx shadcn@latest add https://ui.vllnt.com/r/anchor-port.json` to install it into your React project via the shadcn CLI, then render the AnchorPort element on a node edge.
- What variants does Anchor Port support?
- Anchor Port has three tones — input, output, and bidirectional — each with its own color, four side placements (top, right, bottom, left), and three states: idle, active, and blocked. It renders with an image role and a descriptive aria-label by default.