Skip to content

Segmented ​

One of a few options side by side in a sunken track, the picked one raised. It suits two to four short options that change what a view shows. For views with a count, use Tabs.

tsx
import { Segmented } from '@adecore/ui';
tsx
import { Segmented } from '@adecore/ui';
import { Columns2, LayoutGrid, List } from 'lucide-react';
import { useState } from 'react';

type View = 'list' | 'grid' | 'split';

export default function SegmentedDemo() {
    const [view, setView] = useState<View>('list');

    return (
        <Segmented<View>
            label="View"
            value={view}
            onValueChange={setView}
            options={[
                { id: 'list', label: 'List', icon: List },
                { id: 'grid', label: 'Grid', icon: LayoutGrid },
                { id: 'split', label: 'Split', icon: Columns2 }
            ]}
        />
    );
}

The track is as wide as its options, even in a stretching container. Long labels wrap. With orientation="vertical" the options stack in a column as wide as its container.

It is a radiogroup of radio options and one tab stop: the picked option, or the first. The arrow keys pick the next or previous option and wrap, Home and End pick the first and last, and Space or a click picks the focused one.

Icons only ​

With iconOnly each option is a square with its icon, and the label becomes its accessible name and tooltip. Give every option an icon; one without keeps its label.

With iconOnly="unpicked" only the options that are not picked are squares; the picked one shows its icon and its label.

indicator: true draws a quiet dot in the corner of an option that holds something new. indicatorLabel, such as "3 unread", is added to the option's accessible name and tooltip while the dot is on.

tsx
import { Segmented } from '@adecore/ui';
import { Bell, Inbox, ShoppingCart, Tag, User } from 'lucide-react';
import { useState } from 'react';

type Category = 'primary' | 'transactions' | 'updates' | 'promotions' | 'all';

export default function SegmentedUnpicked() {
    const [category, setCategory] = useState<Category>('primary');

    return (
        <Segmented
            label="Category"
            iconOnly="unpicked"
            value={category}
            onValueChange={setCategory}
            options={[
                { id: 'primary', label: 'Primary', icon: User, indicator: true, indicatorLabel: '3 unread' },
                { id: 'transactions', label: 'Transactions', icon: ShoppingCart },
                { id: 'updates', label: 'Updates', icon: Bell, indicator: true, indicatorLabel: '12 unread' },
                { id: 'promotions', label: 'Promotions', icon: Tag },
                { id: 'all', label: 'All mail', icon: Inbox }
            ]}
        />
    );
}
tsx
import { Segmented } from '@adecore/ui';
import { Monitor, Moon, Sun } from 'lucide-react';
import { useState } from 'react';

type Theme = 'light' | 'dark' | 'system';

export default function SegmentedIconsDemo() {
    const [theme, setTheme] = useState<Theme>('system');

    return (
        <Segmented<Theme>
            label="Theme"
            iconOnly
            value={theme}
            onValueChange={setTheme}
            options={[
                { id: 'light', label: 'Light', icon: Sun },
                { id: 'dark', label: 'Dark', icon: Moon },
                { id: 'system', label: 'Match the system', icon: Monitor }
            ]}
        />
    );
}

A disabled option ​

An option with disabled: true dims, and the keyboard and the tab stop skip it.

tsx
import { Segmented } from '@adecore/ui';
import { useState } from 'react';

type Resolution = 'minute' | 'hour' | 'day';

export default function SegmentedDisabledDemo() {
    const [resolution, setResolution] = useState<Resolution>('hour');

    return (
        <Segmented<Resolution>
            label="Resolution"
            value={resolution}
            onValueChange={setResolution}
            options={[
                { id: 'minute', label: 'Per minute', disabled: true },
                { id: 'hour', label: 'Per hour' },
                { id: 'day', label: 'Per day' }
            ]}
        />
    );
}

Sizes ​

size="md" is 32 pixels high and size="sm" 28, matching Input, Select and Button. At sm the icons are 12 pixels.

tsx
import { Button, Input, Segmented, Select } from '@adecore/ui';
import { Search } from 'lucide-react';
import { useState } from 'react';

type Status = 'open' | 'resolved' | 'ignored';
type Sort = 'recent' | 'frequent';

export default function SegmentedSizeDemo() {
    const [status, setStatus] = useState<Status>('open');
    const [sort, setSort] = useState<Sort>('recent');

    return (
        <div className="flex flex-wrap items-center gap-2">
            <Segmented<Status>
                label="Status"
                size="sm"
                value={status}
                onValueChange={setStatus}
                options={[
                    { id: 'open', label: 'Open' },
                    { id: 'resolved', label: 'Resolved' },
                    { id: 'ignored', label: 'Ignored' }
                ]}
            />
            <Input size="sm" icon={Search} aria-label="Search" placeholder="Search" className="w-40" />
            <Select<Sort>
                label="Sort"
                size="sm"
                value={sort}
                onValueChange={setSort}
                items={[
                    { value: 'recent', label: 'Most recent' },
                    { value: 'frequent', label: 'Most frequent' }
                ]}
            />
            <Button size="sm" variant="secondary">
                Clear
            </Button>
        </div>
    );
}

Props ​

PropTypeDefault
valueTRequired.
onValueChange(id: T) => voidRequired.
optionsreadonly SegmentedOption<T>[]Required. { id, label, icon?, disabled?, indicator?, indicatorLabel? }, with a Lucide icon drawn at 14 pixels, 12 at sm.
labelstringRequired. The accessible name of the group.
disabledboolean
orientation'horizontal' | 'vertical''horizontal'
size'md' | 'sm''md'
iconOnlyboolean | 'unpicked'false
classNamestring
refRef<HTMLDivElement>

T is a string type. SegmentedProps and SegmentedOption are exported types.

Licenses and third-party notices are listed in each package.