Components
Segmented control
Switches between a few views or values of one setting.
'use client'
import { useState } from 'react'
import { SegmentedControl, SegmentedControlItem } from '@dex/shared/components/segmented-control'
export function SegmentedControlDefault() {
const [theme, setTheme] = useState('system')
return (
<SegmentedControl value={theme} onValueChange={setTheme} aria-label="Theme">
<SegmentedControlItem value="system">System</SegmentedControlItem>
<SegmentedControlItem value="light">Light</SegmentedControlItem>
<SegmentedControlItem value="dark">Dark</SegmentedControlItem>
</SegmentedControl>
)
}
'use client'
import { useState } from 'react'
import { SegmentedControl, SegmentedControlItem } from '@dex/shared/components/segmented-control'
export function SegmentedControlFullWidth() {
const [list, setList] = useState('saved')
return (
<div className="w-full max-w-xl">
<SegmentedControl fullWidth value={list} onValueChange={setList} aria-label="Roles">
<SegmentedControlItem value="all">All roles</SegmentedControlItem>
<SegmentedControlItem value="saved">Saved</SegmentedControlItem>
<SegmentedControlItem value="applied">Applied</SegmentedControlItem>
</SegmentedControl>
</div>
)
}
'use client'
import { useState } from 'react'
import { SegmentedControl, SegmentedControlItem } from '@dex/shared/components/segmented-control'
export function SegmentedControlDisabled() {
const [view, setView] = useState('preview')
return (
<SegmentedControl value={view} onValueChange={setView} disabled aria-label="CV view">
<SegmentedControlItem value="preview">Preview</SegmentedControlItem>
<SegmentedControlItem value="edit">Edit</SegmentedControlItem>
</SegmentedControl>
)
}
- Use a segmented control to switch a view or a setting, not to answer a question. For answers, use chips or radios.
- An option that is not on takes a faint tint when pointed at, lighter than the raised pill.
- It is the one control where selected is not primary: the active item is a raised card pill on a muted track. In dark it is an accent fill with no shadow.
- One item is always on. Pressing the active item again does not clear it. The control is always controlled, with
valueandonValueChange. - When each option has its own panel of content, use tabs; their pill variant shares the look.
- Give the control an
aria-labelthat names what it switches.