ComponentsNodesTooltip

Tooltip Node

A node that displays a tooltip when hovered. Built on top of the NodeToolbar component that comes with React Flow.

Installation

Make sure to follow the prerequisites before installing the component.

npx shadcn@latest add https://ui-components-git-tooltip-node-refactor-xyflow.vercel.app/tooltip-node

Usage

1. Copy the component into your app

import React, { memo } from "react";
import { NodeProps, Position } from "@xyflow/react";
 
import {
  TooltipNode,
  TooltipContent,
  TooltipTrigger,
} from "@/components/tooltip-node";
 
const Tooltip = memo(({ selected }: NodeProps) => {
  return (
    <TooltipNode selected={selected}>
      <TooltipContent position={Position.Top}>Hidden Content</TooltipContent>
      <TooltipTrigger>Hover</TooltipTrigger>
    </TooltipNode>
  );
});
 
export default Tooltip;

2. Connect the component with your React Flow application.

"use client";
 
import { Background, ReactFlow } from "@xyflow/react";
import DemoWrapper from "@/components/demo-wrapper";
import TooltipNode from "@/registry/components/tooltip-node/demo";
 
const nodeTypes = {
  tooltipNode: TooltipNode,
};
 
const defaultNodes = [
  {
    id: "1",
    position: { x: 200, y: 200 },
    data: {},
    type: "tooltipNode",
  },
];
 
export default function DemoPage() {
  return (
    <DemoWrapper>
      <div className="h-full w-full">
        <ReactFlow defaultNodes={defaultNodes} nodeTypes={nodeTypes} fitView>
          <Background />
        </ReactFlow>
      </div>
    </DemoWrapper>
  );
}