ValyroUI Русская версия

Switch

On/off toggle. Free, MIT · Forms and input › Checkboxes and sliders

On/off toggle: a native checkbox with role="switch", so it submits with forms and toggles with Space. className/style go to the <label> wrapper, other props to the <input>.

Installation

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';

Props

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).

Related components

Previous: Radio Group · Next: Slider · All Forms and input