@mks2508/mks-ui
Primitives

Highlight

Animated background indicator that follows the active item in navigation and tab lists.

Highlight

An animated background indicator that follows the currently active element in a group, commonly used for navigation tabs, pill selectors, and menu items.

Import

import { Highlight, HighlightItem } from '@mks2508/mks-ui/react';

Basic Usage

Basic Usage
.tsx
<Highlight className="rounded-md bg-white/10">
<HighlightItem value="tab1">
  <button className="px-4 py-2">Tab 1</button>
</HighlightItem>
<HighlightItem value="tab2">
  <button className="px-4 py-2">Tab 2</button>
</HighlightItem>
<HighlightItem value="tab3">
  <button className="px-4 py-2">Tab 3</button>
</HighlightItem>
</Highlight>

How It Works

The Highlight component:

  1. Wraps items with HighlightItem
  2. Automatically tracks which item is active
  3. Animates a background indicator smoothly between items
  4. Uses spring-based motion for natural transitions

Controlled Mode

Use value and onValueChange for controlled state:

const [activeTab, setActiveTab] = useState('tab1');

<Highlight
  value={activeTab}
  onValueChange={setActiveTab}
  className="rounded-md bg-white/10"
>
  <HighlightItem value="tab1">
    <button className="px-4 py-2">Tab 1</button>
  </HighlightItem>
  <HighlightItem value="tab2">
    <button className="px-4 py-2">Tab 2</button>
  </HighlightItem>
</Highlight>

Integration with Tabs

Highlight is used internally by the Tabs component:

<Tabs defaultValue="general">
  <TabsList>
    <TabsHighlight className="rounded-md bg-white/10">
      <TabsHighlightItem value="general">
        <TabsTab value="general">General</TabsTab>
      </TabsHighlightItem>
      <TabsHighlightItem value="advanced">
        <TabsTab value="advanced">Advanced</TabsTab>
      </TabsHighlightItem>
    </TabsHighlight>
  </TabsList>
</Tabs>

API Reference

Highlight

PropTypeDefaultDescription
valuestringControlled active value
defaultValuestringDefault active value (uncontrolled)
onValueChange(value: string) => voidChange callback
controlledItemsbooleanfalseUse controlled item registration
clickbooleantrueEnable click-to-select
classNamestringCustom styles for the highlight indicator
transitionTransitionMotion transition config

HighlightItem

PropTypeDefaultDescription
valuestringUnique value for this item
classNamestringItem container classes
childrenReactNodeItem content