# @cloud-ru/ds-segment-control > Сегментированный переключатель — компактная радио-группа с единственным выбором, токенами размеров s/m/l, иконками, счётчиками и режимом полной ширины. Docs: /snack-v2/components/segment-control/ ## Установка ```sh pnpm add @cloud-ru/ds-segment-control ``` ## Когда использовать - Когда вариантов от 2 до 5 и все они одновременно видимы на экране. - Для переключения режимов отображения (list/grid/kanban, day/week/month). - Для компактных фильтров с взаимоисключающим выбором. Когда **не** нужен `SegmentControl`: - Вариантов больше 5: - используйте `Tabs` или `Select`. - Допускается множественный выбор: - используйте чекбоксы или `ToggleGroup`. - Выбор приводит к загрузке тяжёлого контента и нужны отдельные урлы: - используйте `Tabs`. ## API ### Segment | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `counter` | `string \| number` | — | no | Счётчик в сегменте (отображается после лейбла). | | `disabled` | `boolean` | — | no | Состояние активности сегмента. | | `focusable` | `boolean` | — | no | | | `icon` | `ReactNode` | — | no | Иконка сегмента. | | `iconPosition` | `after \| before` | `before` | no | Позиция иконки относительно лейбла. | | `label` | `string` | — | no | Текстовый заголовок сегмента. | | `onClick` | `() => void` | — | yes | | | `onGetFocusable` | `((ref: HTMLButtonElement \| null) => void)` | — | no | | | `onSelectionUpdated` | `(element: HTMLButtonElement) => void` | — | yes | | | `renderWrapSegment` | `((segment: ReactNode) => ReactNode)` | — | no | Render-обёртка над сегментом. | | `selected` | `boolean` | — | yes | | | `size` | `l \| m \| s` | — | yes | | | `testId` | `string` | — | no | | | `value` | `IdType` | — | yes | Идентификатор сегмента. | ### SegmentControl | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `className` | `string` | — | no | CSS-класс контейнера. | | `data-test-id` | `string` | — | no | | | `defaultValue` | `IdType` | — | no | ID выбранного по умолчанию сегмента (uncontrolled). | | `items` | `Segment[]` | — | yes | Набор сегментов. | | `name` | `string` | — | no | Имя поля (hidden input для формы). | | `onChange` | `((value: Value) => void)` | — | no | Колбек смены выбранного сегмента. | | `outline` | `boolean` | — | no | Обводка. | | `size` | `l \| m \| s` | `m` | no | Размер компонента. | | `value` | `IdType` | — | no | Value выбранного сегмента. | | `width` | `auto \| full` | `auto` | no | Управление шириной компонента. | #### Related types - `IconPosition` = `after | before` - `Segment` (interface) - `Size` = `l | m | s` - `Value` = `0% | 100% | 50%` - `Width` = `auto | full` ## Примеры ### Basic ```tsx import { SegmentControl } from '@cloud-ru/ds-segment-control'; export function Basic() { return ( ); } ``` ### Controlled ```tsx import { SegmentControl } from '@cloud-ru/ds-segment-control'; import { useState } from 'react'; export function Controlled() { const [view, setView] = useState<'list' | 'grid' | 'kanban'>('list'); return (
Selected: {view}
); } ``` ### DisabledSegment ```tsx import { SegmentControl } from '@cloud-ru/ds-segment-control'; export function DisabledSegment() { return ( ); } ``` ### FullWidth ```tsx import { SegmentControl } from '@cloud-ru/ds-segment-control'; export function FullWidth() { return (
); } ``` ### Sizes ```tsx import { SegmentControl } from '@cloud-ru/ds-segment-control'; const items = [ { value: 'one', label: 'One' }, { value: 'two', label: 'Two' }, { value: 'three', label: 'Three' }, ]; export function Sizes() { return (
); } ``` ### WithCounter ```tsx import { SegmentControl } from '@cloud-ru/ds-segment-control'; export function WithCounter() { return ( ); } ``` ### WithIcons ```tsx import { HomeSVG, PlusSVG, SettingsSVG } from '@cloud-ru/ds-icons/interface/system'; import { SegmentControl } from '@cloud-ru/ds-segment-control'; export function WithIcons() { return (
}, { value: 'settings', label: 'Settings', icon: }, { value: 'add', label: 'Add', icon: }, ]} /> }, { value: 'settings', icon: }, { value: 'add', icon: }, ]} />
); } ```