# @cloud-ru/ds-toggles > Пакет компонентов выбора и переключения — Checkbox, Radio, Switch, Favourite и контейнер ToggleGroup с общими токенами размеров и состояний. Docs: /snack-v2/components/toggles/ ## Установка ```sh pnpm add @cloud-ru/ds-toggles ``` ## API ### Checkbox | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `autofocus` | `boolean` | — | no | HTML-аттрибут autofocus | | `checked` | `boolean` | — | no | HTML-аттрибут checked | | `className` | `string` | — | no | CSS-класс | | `data-test-id` | `string` | — | no | | | `defaultChecked` | `boolean` | — | no | HTML-аттрибут checked по-умолчанию | | `disabled` | `boolean` | `false` | no | HTML-аттрибут disabled | | `id` | `string` | — | no | HTML-аттрибут id | | `indeterminate` | `boolean` | — | no | Состояние частичного выбора | | `indeterminateDefault` | `boolean` | — | no | Состояние частичного выбора по-умолчанию | | `inputRef` | `RefObject` | — | no | | | `loading` | `boolean` | `false` | no | Состояние загрузки | | `name` | `string` | — | no | HTML-аттрибут name | | `onBlur` | `FocusEventHandler` | — | no | Колбек потери фокуса | | `onChange` | `((checked: boolean) => void)` | — | no | Колбек смены значения | | `onClick` | `MouseEventHandler` | — | no | Колбек клика | | `onFocus` | `FocusEventHandler` | — | no | Колбек приобретения фокуса | | `size` | `s \| xs` | `s` | no | Размер | | `tabIndex` | `number` | — | no | HTML-аттрибут tab-index | | `value` | `string` | — | no | HTML-аттрибут value | #### Related types - `Size` = `s | xs` ### Favourite | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `autofocus` | `boolean` | — | no | HTML-аттрибут autofocus | | `checked` | `boolean` | — | no | HTML-аттрибут checked | | `className` | `string` | — | no | CSS-класс | | `data-test-id` | `string` | — | no | | | `defaultChecked` | `boolean` | — | no | HTML-аттрибут checked по-умолчанию | | `disabled` | `boolean` | `false` | no | HTML-аттрибут disabled | | `icon` | `heart \| star` | `heart` | no | Вариант иконки: звезда или сердце | | `id` | `string` | — | no | HTML-аттрибут id | | `inputRef` | `RefObject` | — | no | | | `loading` | `boolean` | `false` | no | Состояние загрузки | | `name` | `string` | — | no | HTML-аттрибут name | | `onBlur` | `FocusEventHandler` | — | no | Колбек потери фокуса | | `onChange` | `((checked: boolean) => void)` | — | no | Колбек смены значения | | `onClick` | `MouseEventHandler` | — | no | Колбек клика | | `onFocus` | `FocusEventHandler` | — | no | Колбек приобретения фокуса | | `onKeyUp` | `KeyboardEventHandler` | — | no | Обработчик keyup | | `size` | `s \| xs` | `s` | no | Размер | | `tabIndex` | `number` | — | no | HTML-аттрибут tab-index | | `value` | `string` | — | no | HTML-аттрибут value | #### Related types - `FavouriteIcon` = `heart | star` - `Size` = `s | xs` ### Radio | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `autofocus` | `boolean` | — | no | HTML-аттрибут autofocus | | `checked` | `boolean` | — | no | HTML-аттрибут checked | | `className` | `string` | — | no | CSS-класс | | `data-test-id` | `string` | — | no | | | `defaultChecked` | `boolean` | — | no | HTML-аттрибут checked по-умолчанию | | `disabled` | `boolean` | `false` | no | HTML-аттрибут disabled | | `id` | `string` | — | no | HTML-аттрибут id | | `inputRef` | `RefObject` | — | no | | | `loading` | `boolean` | `false` | no | Состояние загрузки | | `name` | `string` | — | no | HTML-аттрибут name | | `onBlur` | `FocusEventHandler` | — | no | Колбек потери фокуса | | `onChange` | `((checked: boolean) => void)` | — | no | Колбек смены значения | | `onClick` | `MouseEventHandler` | — | no | Колбек клика | | `onFocus` | `FocusEventHandler` | — | no | Колбек приобретения фокуса | | `size` | `s \| xs` | `s` | no | Размер | | `tabIndex` | `number` | — | no | HTML-аттрибут tab-index | | `value` | `string` | — | no | HTML-аттрибут value | #### Related types - `Size` = `s | xs` ### Switch | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `autofocus` | `boolean` | — | no | HTML-аттрибут autofocus | | `checked` | `boolean` | — | no | HTML-аттрибут checked | | `className` | `string` | — | no | CSS-класс | | `data-test-id` | `string` | — | no | | | `defaultChecked` | `boolean` | — | no | HTML-аттрибут checked по-умолчанию | | `disabled` | `boolean` | `false` | no | HTML-аттрибут disabled | | `id` | `string` | — | no | HTML-аттрибут id | | `inputRef` | `RefObject` | — | no | | | `loading` | `boolean` | `false` | no | Состояние загрузки | | `name` | `string` | — | no | HTML-аттрибут name | | `onBlur` | `FocusEventHandler` | — | no | Колбек потери фокуса | | `onChange` | `((checked: boolean) => void)` | — | no | Колбек смены значения | | `onClick` | `MouseEventHandler` | — | no | Колбек клика | | `onFocus` | `FocusEventHandler` | — | no | Колбек приобретения фокуса | | `size` | `s \| xs` | `s` | no | Размер | | `tabIndex` | `number` | — | no | HTML-аттрибут tab-index | | `value` | `string` | — | no | HTML-аттрибут value | #### Related types - `Size` = `s | xs` ### ToggleGroup | Prop | Type | Default | Required | Description | |------|------|---------|----------|-------------| | `children` | `string \| number \| boolean \| ReactElement> \| Iterable \| ReactPortal \| null \| undefined` | — | no | | | `defaultValue` | `string \| string[]` | — | no | Начальное состояние | | `onChange` | `((value: string) => void) \| ((value: string[]) => void) \| undefined` | — | no | Controlled обработчик измения состояния | | `selectionMode` | `multiple \| single` | `single` | no | Режим выбора | | `value` | `string \| string[]` | — | no | Controlled состояние | ## Примеры ### CheckboxBasic ```tsx import { Checkbox } from '@cloud-ru/ds-toggles'; export function CheckboxBasic() { return ; } ``` ### CheckboxIndeterminate ```tsx import { Checkbox } from '@cloud-ru/ds-toggles'; export function CheckboxIndeterminate() { return ; } ``` ### CheckboxStates ```tsx import { Checkbox } from '@cloud-ru/ds-toggles'; export function CheckboxStates() { return (
); } ``` ### FavouriteHeart ```tsx import { Favourite } from '@cloud-ru/ds-toggles'; export function FavouriteHeart() { return ; } ``` ### FavouriteStar ```tsx import { Favourite } from '@cloud-ru/ds-toggles'; export function FavouriteStar() { return ; } ``` ### FavouriteStates ```tsx import { Favourite } from '@cloud-ru/ds-toggles'; export function FavouriteStates() { return (
); } ``` ### RadioBasic ```tsx import { Radio } from '@cloud-ru/ds-toggles'; export function RadioBasic() { return ; } ``` ### RadioGroup ```tsx import { Radio } from '@cloud-ru/ds-toggles'; export function RadioGroup() { return (
); } ``` ### RadioStates ```tsx import { Radio } from '@cloud-ru/ds-toggles'; export function RadioStates() { return (
); } ``` ### SwitchBasic ```tsx import { Switch } from '@cloud-ru/ds-toggles'; export function SwitchBasic() { return ; } ``` ### SwitchSizes ```tsx import { Switch } from '@cloud-ru/ds-toggles'; export function SwitchSizes() { return (
); } ``` ### SwitchStates ```tsx import { Switch } from '@cloud-ru/ds-toggles'; export function SwitchStates() { return (
); } ``` ### ToggleGroupControlled ```tsx import { ToggleGroup, useToggleGroup } from '@cloud-ru/ds-toggles'; import { useState } from 'react'; function Option({ id, label }: { id: string; label: string }) { const { isChecked, handleClick } = useToggleGroup({ value: id }); return ( ); } export function ToggleGroupControlled() { const [value, setValue] = useState(); return (

Selected: {value ?? '—'}

); } ``` ### ToggleGroupMultiple ```tsx import { ToggleGroup, useToggleGroup } from '@cloud-ru/ds-toggles'; import { useState } from 'react'; function Chip({ id, label }: { id: string; label: string }) { const { isChecked, handleClick } = useToggleGroup({ value: id }); return ( ); } export function ToggleGroupMultiple() { const [value, setValue] = useState(['a']); return ( setValue(next ?? [])}> ); } ``` ### ToggleGroupSingle ```tsx import { ToggleGroup, useToggleGroup } from '@cloud-ru/ds-toggles'; import { useState } from 'react'; function Chip({ id, label }: { id: string; label: string }) { const { isChecked, handleClick } = useToggleGroup({ value: id }); return ( ); } export function ToggleGroupSingle() { const [value, setValue] = useState('a'); return ( ); } ```