DocsComponentsTemplatesThemesGitHub

SegmentedControl

Pill-shaped switcher between 2–5 views or modes.

Code

import * as React from 'react';
import { SegmentedControl } from '@fruit-labs/design';

export default function Demo() {
  return (
    <div
      style={{
        maxWidth: 360,
      }}
    >
      <SegmentedControl
        options={['Day', 'Week', 'Month', 'Year']}
        defaultValue="Week"
        label="Range"
      />
    </div>
  );
}

With icons

import { SegmentedControl } from '@fruit-labs/design';

export default function Example() {
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, alignItems: 'center' }}>
      <SegmentedControl label="View" options={[{ value: 'grid', label: 'Grid', icon: 'grid' }, { value: 'chart', label: 'Chart', icon: 'chart' }]} />
    </div>
  );
}

Install

From npm:

npm install @fruit-labs/design

import { SegmentedControl } from '@fruit-labs/design';

Or copy the TypeScript source into your project:

npx shadcn@latest add https://design.fruitlabs.online/r/segmented-control.json

Guidelines

  • Switches views of the same content (Day/Week/Month, Grid/List). For navigation between pages use Tabs.

Props

PropTypeRequired
optionsArray<string | { value: string; label: React.ReactNode; icon?: string }>Yes
valuestringNo
defaultValuestringNo
onChange(value: string) => voidNo
labelstringNo
classNamestringNo
styleReact.CSSPropertiesNo

Edit this example on GitHub