The example below loads live from Storybook; open it in Storybook to use the controls. Change the option to see the pill slide on a spring.
Default
Section titled “Default”SegmentedControl comes at 36 px high. The selected option sits on a raised pill that slides over a layer track. label is required.
import { Provider, SegmentedControl } from '@bigbang/ui';
const items = [ { value: 'day', label: 'Daily' }, { value: 'week', label: 'Weekly' }, { value: 'month', label: 'Monthly' },];
export default function Default() { return ( <Provider locale="en-GB"> <SegmentedControl label="Period" items={items} defaultValue="week" /> </Provider> );}With icons
Section titled “With icons”Each option can take a decorative icon before its label.
import { Provider, SegmentedControl } from '@bigbang/ui';
export default function WithIcons() { return ( <Provider locale="en-GB"> <SegmentedControl label="View" defaultValue="list" items={[ { value: 'list', label: 'List', icon: 'list' }, { value: 'grid', label: 'Grid', icon: 'layout-grid' }, ]} /> </Provider> );}size gives a 32 or 36 px height.
import { Provider, SegmentedControl } from '@bigbang/ui';
const items = [ { value: 'day', label: 'Daily' }, { value: 'week', label: 'Weekly' }, { value: 'month', label: 'Monthly' },];
export default function Sizes() { return ( <Provider locale="en-GB"> <div className="flex flex-col items-start gap-lg"> <SegmentedControl label="Period sm" items={items} defaultValue="day" size="sm" /> <SegmentedControl label="Period md" items={items} defaultValue="day" /> </div> </Provider> );}Full width
Section titled “Full width”fullWidth stretches the control to its container and shares the width equally.
import { Provider, SegmentedControl } from '@bigbang/ui';
const items = [ { value: 'day', label: 'Daily' }, { value: 'week', label: 'Weekly' }, { value: 'month', label: 'Monthly' },];
export default function FullWidth() { return ( <Provider locale="en-GB"> <div className="w-full max-w-md"> <SegmentedControl label="Period" items={items} defaultValue="month" fullWidth /> </div> </Provider> );}Disabled
Section titled “Disabled”A single option can be disabled; arrow keys skip it. Pass disabled to the control to turn off every option.
import { Provider, SegmentedControl } from '@bigbang/ui';
const items = [ { value: 'day', label: 'Daily' }, { value: 'week', label: 'Weekly' }, { value: 'month', label: 'Monthly' },];
export default function Disabled() { return ( <Provider locale="en-GB"> <SegmentedControl label="Period" items={[...items, { value: 'year', label: 'Yearly', disabled: true }]} defaultValue="day" /> </Provider> );}Light and dark mode
Section titled “Light and dark mode”Colours come from semantic tokens; neither mode needs extra settings.
import { Provider, SegmentedControl } from '@bigbang/ui';
const items = [ { value: 'day', label: 'Daily' }, { value: 'week', label: 'Weekly' }, { value: 'month', label: 'Monthly' },];
export default function Default() { return ( <Provider locale="en-GB"> <SegmentedControl label="Period" items={items} defaultValue="week" /> </Provider> );}