underline-tabs.tsx


Overview

The underline-tabs.tsx file defines a set of React components that implement a stylized tab interface with an underline indicator. It leverages the Radix UI Tabs Primitive for accessible tab behavior and composes it with custom styles and UI components from a local UI library (../ui/tabs). The main purpose of this file is to provide reusable, styled tab components that visually emphasize the active tab by underlining it.

These components are designed for integration into larger React applications where tabbed navigation or content switching is needed, and they focus on a minimalist underline design consistent with modern UI patterns.


Components

1. UnderlineTabsList

Description

A React forwardRef component that renders the container for the tab triggers (the clickable tab headers). It uses the TabsList component from the local UI library and applies custom styles to create a horizontal tab list with an underline style for the active tab.

Declaration

export const UnderlineTabsList: React.ForwardRefExoticComponent<
  React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> & React.RefAttributes<React.ElementRef<typeof TabsPrimitive.List>>
>

Parameters

Styling Highlights

Usage Example

<UnderlineTabsList>
  {/* Tab triggers go here */}
</UnderlineTabsList>

2. UnderlineTabsTrigger

Description

A React forwardRef component rendering an individual tab trigger (clickable tab title). It wraps the TabsTrigger component from the local UI library and applies underline styling to indicate the active tab.

Declaration

export const UnderlineTabsTrigger: React.ForwardRefExoticComponent<
  React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger> & React.RefAttributes<React.ElementRef<typeof TabsPrimitive.Trigger>>
>

Parameters

Styling Highlights

Usage Example

<UnderlineTabsTrigger value="tab1">Tab 1</UnderlineTabsTrigger>

3. Re-exports from ../ui/tabs

The file also exports the following components under new names to maintain a consistent naming scheme:

These are imported from the local UI library and represent the main Tabs container and the content area for each tab, respectively. They are not redefined here but are essential for composing the full tab interface.

Usage Example

<UnderlineTabs defaultValue="tab1">
  <UnderlineTabsList>
    <UnderlineTabsTrigger value="tab1">Tab 1</UnderlineTabsTrigger>
    <UnderlineTabsTrigger value="tab2">Tab 2</UnderlineTabsTrigger>
  </UnderlineTabsList>
  <UnderlineTabsContent value="tab1">
    Content for Tab 1
  </UnderlineTabsContent>
  <UnderlineTabsContent value="tab2">
    Content for Tab 2
  </UnderlineTabsContent>
</UnderlineTabs>

Implementation Details


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component UnderlineTabs {
        <<re-exported>>
        +Tabs
    }
    component UnderlineTabsContent {
        <<re-exported>>
        +TabsContent
    }
    component UnderlineTabsList {
        +forwardRef
        +className: string
        +props
    }
    component UnderlineTabsTrigger {
        +forwardRef
        +className: string
        +props
    }
    UnderlineTabsList --> TabsList
    UnderlineTabsTrigger --> TabsTrigger
    TabsList --> TabsPrimitive.List
    TabsTrigger --> TabsPrimitive.Trigger

Summary

The underline-tabs.tsx file is a focused React module that composes accessible tab components with a custom underline style for active tabs. It extends Radix UI primitives and a local UI library to provide reusable, forwardRef-enabled tab components suitable for modern, accessible React applications. The styling approach leverages CSS pseudo-elements and data attributes to elegantly indicate active tabs without extra JavaScript logic.

By exporting both the stylized tab list and triggers along with the tabs container and content, this file encapsulates the underline tab pattern, promoting consistency and reusability throughout the project.