Skip to content

Components

Tabs

A segmented control whose selection travels as a glass lens.

Markdown
glass-tabs-basic.tsx

52.1km

Distance this week

Use it for

  • Switching a view or a range in place: Day / Week / Month, List / Grid.
  • Two to five short options.

Not for

  • Navigating between pages: use links.
  • Long lists of options: use a select.

Installation

Coming soon
npm install @vitrumui/react
No dependencies

Usage

app.tsx
import { GlassTabs } from '@vitrumui/react/tabs'

const [view, setView] = useState('week')

<GlassTabs
  aria-label="Range"
  value={view}
  onValueChange={setView}
  options={[
    { value: 'day', label: 'Day' },
    { value: 'week', label: 'Week' },
  ]}
/>

Examples

Coming soon

Your own markup

Already have tabs (Radix Tabs, your own radio group)? Put the lens on them with GlassLens, which ships with GlassTabs:

  • The container is relative isolate and <GlassLens value={value} /> is its first child.
  • Options carry role="radio" or role="tab" (Radix Tabs works as is)
  • The selected option contains the resting highlight, marked data-vt-highlight. Its background colour is the lens colour and its corners are the lens corners: rounded-full travels as a pill, rounded-lg as a rounded rectangle.
  • Hide the highlight while the lens moves: [[data-vt-moving]_&]:opacity-0.
A billing switch with GlassLens
glass-tabs-custom.tsx

$96

per year, four months free

API reference

PropTypeDefault
options

The segments.

{ value, label, icon?, aria-label? }[]—
value

Selected value (controlled).

string | null—
onValueChange

Called with the new value.

(value) => void—
aria-label

Required: names the group for screen readers.

string—
size

Segment height 28, 32 or 40 px.

'sm' | 'md' | 'lg''md'
highlightClassName

Classes of the resting pill; its background is the lens colour.

string'bg-white dark:bg-neutral-700'
GlassLens value

Your own markup: the selected value; any change moves the lens.

string | number | null—
GlassLens disabled

No lens; the highlight simply jumps.

booleanfalse

Accessibility

  • Radiogroup pattern: one tab stop, arrow keys move the selection.
  • Icon-only options take an aria-label each.
  • With reduced motion the pill simply jumps.