Labeled Handle
A handle with a label that can be used to display additional information.
Installation
Make sure to follow the prerequisites before installing the component.
npx shadcn@latest add https://ui.reactflow.dev/labeled-handle
Usage
1. Copy the component into your app
import React, { memo } from "react";
import { NodeProps, Position } from "@xyflow/react";
import { LabeledHandle } from "@/components/labeled-handle";
import { BaseNode } from "@/components/base-node";
const LabeledHandleDemo = memo(({ selected }: NodeProps) => {
return (
<BaseNode className="flex px-0 py-5" selected={selected}>
<LabeledHandle
id="target-1"
title="Some Input"
type="target"
position={Position.Left}
/>
<LabeledHandle
id="source-1"
title="Some Output"
type="source"
position={Position.Right}
/>
</BaseNode>
);
});
export default LabeledHandleDemo;
2. Connect the component with your React Flow application.
import { Background, ReactFlow } from "@xyflow/react";
import LabeledHandleDemo from "./component-example";
const defaultNodes = [
{
id: "1",
position: { x: 200, y: 200 },
data: {},
type: "labeledHandle",
},
];
const nodeTypes = {
labeledHandle: LabeledHandleDemo,
};
export default function App() {
return (
<div className="h-full w-full">
<ReactFlow defaultNodes={defaultNodes} nodeTypes={nodeTypes} fitView>
<Background />
</ReactFlow>
</div>
);
}
Last updated on