tooltip.tsx


Overview

tooltip.tsx is a React component module that provides reusable tooltip UI components built on top of the Radix UI Tooltip primitives (@radix-ui/react-tooltip) and customized with Tailwind CSS utility classes. It includes:

This file serves as a centralized tooltip solution in the application, offering both Radix-based tooltips and a lightweight custom tooltip alternative.


Components and Exports

1. Tooltip Primitives Wrappers

These components re-export or wrap Radix UI Tooltip primitives with additional styling:

<TooltipContent sideOffset={6} className="custom-style">
  Tooltip text or elements here
</TooltipContent>

Implementation Details:
TooltipContent uses React.forwardRef to pass refs to the underlying Radix component for proper positioning and accessibility. It applies animations and styling tailored for a popover look with a max width of 20% viewport width.


2. FormTooltip

A simple component to display an info icon with an associated tooltip. Useful for form fields or inputs where you need to show contextual help.

Props:

Usage Example:

<FormTooltip tooltip="This field is required for registration." />

Behavior:


3. AntToolTip

A fully controlled, custom tooltip component with configurable placement and trigger behavior.

Props:

Prop

Type

Default

Description

title

React.ReactNode

The tooltip content to display

children

React.ReactNode

Element(s) that the tooltip is attached to

placement

`'top'

'bottom'

'left'

trigger

`'hover'

'click'

'focus'`

className

string

Additional CSS classes for tooltip container

Usage Example:

<AntToolTip title="More info here" placement="right" trigger="click">
  <button>Hover or click me</button>
</AntToolTip>

Behavior and Implementation:


Important Implementation Details


Interaction with Other Parts of the System


Mermaid Component Diagram

componentDiagram
    component TooltipProvider
    component Tooltip
    component TooltipTrigger
    component TooltipContent
    component FormTooltip
    component AntToolTip

    TooltipProvider <|-- Tooltip
    Tooltip <|-- TooltipTrigger
    Tooltip <|-- TooltipContent

    FormTooltip ..> Tooltip : uses
    FormTooltip ..> TooltipTrigger : uses
    FormTooltip ..> TooltipContent : uses

    AntToolTip : manages visible state
    AntToolTip : supports hover, click, focus triggers
    AntToolTip : customizable placement

    AntToolTip --> children
    AntToolTip --> title

Summary

tooltip.tsx provides both Radix UI-based and custom tooltip React components with rich styling and configurable behavior. It abstracts complex tooltip interactions and accessibility concerns, enabling developers to easily integrate tooltips with multiple trigger modes and placements throughout the app. The file balances leveraging existing libraries with custom solutions for flexibility and maintainability.