# Magnet Tabs

> Pill tabs whose highlight slides toward the pointer.

```tsx
import { MagnetTabs } from '@brand-studio/ui';

export default function MagnetTabsDemo() {
  return (
    <MagnetTabs
      aria-label="Shop sections"
      items={[
        { value: 'coffee', label: 'Coffee' },
        { value: 'equipment', label: 'Equipment' },
        { value: 'subscriptions', label: 'Subscriptions' },
        { value: 'gifts', label: 'Gifts' },
      ]}
    />
  );
}
```

## Installation

```sh
npm install @brand-studio/ui
```

React 18 or 19 is a peer dependency. Import the stylesheet once and wrap the app in a brand theme:

```tsx
import '@brand-studio/ui/styles.css';
import { BrandTheme, MagnetTabs } from '@brand-studio/ui';
import brand from './brand.json';

<BrandTheme palette={brand.tokens} mode="system">
  {/* your app */}
</BrandTheme>
```

## Usage

```tsx
import { MagnetTabs } from '@brand-studio/ui';
```

```tsx
<MagnetTabs
  aria-label="Shop sections"
  items={[{ value: 'coffee', label: 'Coffee' }, { value: 'gifts', label: 'Gifts' }]}
/>
```

## Examples

### With panels

Give items `content` to render tab panels below.

```tsx
import { MagnetTabs } from '@brand-studio/ui';

export default function MagnetTabsPanels() {
  return (
    <div style={{ width: '100%', maxWidth: 420 }}>
      <MagnetTabs
        aria-label="Plan"
        items={[
          { value: 'monthly', label: 'Monthly', content: <p>One bag every four weeks. Pause any time.</p> },
          { value: 'fortnightly', label: 'Fortnightly', content: <p>One bag every two weeks, with free delivery.</p> },
          { value: 'weekly', label: 'Weekly', content: <p>For offices and big households.</p> },
        ]}
      />
    </div>
  );
}
```

## Accessibility

- Uses the tabs pattern: arrow keys move between tabs, Home and End jump to the ends.
- The hover highlight is decorative; the selected tab is marked with `aria-selected`.

## API Reference

| Prop | Type | Default |
|---|---|---|
| `items` | `MagnetTab[]` | – |
| `defaultValue?` | `string` | – |
| `value?` | `string` | – |
| `onValueChange?` | `((value: string) => void)` | – |
| `className?` | `string` | `''` |
| `aria-label?` | `string` | – |

Source: https://brandstudio.js.org/docs/components/magnet-tabs/
