ValyroUI English version

Switch

Переключатель. Бесплатно, MIT · Формы и ввод › Флажки и ползунки

Установка

npx valyro-cli@latest add switch
npx shadcn@latest add https://valyro.xyz/r/switch.json
npm install valyro-ui

import 'valyro-ui/styles.css';
import { Switch } from 'valyro-ui';

Пропсы

PropTypeDefault
checkedbooleanControlled checked; use with onCheckedChange.
defaultCheckedbooleanfalseInitial checked when uncontrolled.
onCheckedChange(checked: boolean) => voidCalled with the new checked when it changes.
size'sm' | 'md' | 'lg''md'Track, knob and text size.
labelReactNodeText next to the switch; clicking it toggles the switch, and it names the input.
descriptionReactNodeSecondary text under the label, linked to the input with aria-describedby.
invalidbooleanfalseError state, e.g. from a FormField: aria-invalid on the input (an explicit aria-invalid wins).
animation'default' | 'spring''default'spring: the knob travels with a spring (a transform, not a layout change) and the track icons swap with a pop. default: the theme's transition.
startIconReactNodeIcon on the track's start side, uncovered while the switch is on (e.g. a sun).
endIconReactNodeIcon on the track's end side, uncovered while the switch is off (e.g. a moon).
thumbIconReactNodeIcon inside the knob.
pressedWidthnumberKnob width while pressed, px: it stretches into a capsule (default: the theme's stretch).

Похожие компоненты

  • Checkbox — Флажки
  • Checkbox Group — Флажки с общей подписью, подсказкой, ошибкой и обязательностью
  • Radio Group — Выбор одного варианта
  • Slider — Ползунок
  • Histogram Range — Диапазон цен с гистограммой, двумя ползунками и полями
  • Rating Input — Оценка звёздами
  • Text Input — Текстовые поля
  • Textarea — Многострочный ввод
  • Search Input — Поисковая строка
  • Mentions Input — Текст с @упоминаниями и #тегами, асинхронные подсказки
  • Tags Input — Ввод тегов
  • Select — Выбор из списка

Назад: Radio Group · Далее: Slider · Весь раздел «Формы и ввод»