{"slug":"switch","name":"Switch","category":"Form & Input","summary":"An on/off control that applies immediately.","status":"stable","since":"0.1.0","import":"import { Switch } from '@elluzion/iv-ui';","usage":["Bind `checked`; changes apply without a submit step.","Use `label` for the visible and accessible name.","Prefer `Checkbox` when the choice is part of a form that is submitted later."],"props":[{"name":"checked","type":"boolean","default":"false","description":"On/off state. Bind with `bind:checked`.","required":false,"bindable":true},{"name":"disabled","type":"boolean","default":"false","description":"Disables interaction and applies the disabled treatment.","required":false,"bindable":false},{"name":"label","type":"string","default":"''","description":"Label rendered next to the switch.","required":false,"bindable":false},{"name":"size","type":"'sm' | 'md'","default":"'md'","description":"Control size.","required":false,"bindable":false}],"events":[{"name":"change","type":"(e: CustomEvent<{ checked: boolean }>) => void","default":null,"description":"Called with `{ checked }` after the state changes.","required":false,"bindable":false},{"name":"focus","type":"(e: FocusEvent) => void","default":null,"description":"Called when the control receives focus.","required":false,"bindable":false},{"name":"blur","type":"(e: FocusEvent) => void","default":null,"description":"Called when the control loses focus.","required":false,"bindable":false}],"snippets":[],"types":[],"manual":[],"tokens":["--iv_border","--iv_cursor","--iv_disabled-opacity","--iv_ease-out","--iv_font-ui","--iv_foreground","--iv_leading-tight","--iv_outline-offset","--iv_outline-width","--iv_radius-sm","--iv_spacing-sm","--iv_surface-elevated","--iv_switch-h","--iv_switch-h-sm","--iv_switch-w","--iv_switch-w-sm","--iv_text-body","--iv_thumb-md","--iv_thumb-sm","--iv_transition-fast"],"cssHooks":["iv-checked","iv-disabled","iv-label","iv-md","iv-root","iv-sm","iv-switch","iv-thumb"],"accessibility":{"keyboard":[["Tab","Moves focus to the switch."],["Space / Enter","Toggles the switch."]],"notes":["The control exposes `role=\"switch\"` with `aria-checked`.","The label is linked through `aria-labelledby`.","Focus is drawn on the track and is never removed."]},"related":[{"title":"Checkbox","summary":"A binary choice with an optional label and a mixed state.","url":"/components/checkbox","kind":"Component"},{"title":"Toggle","summary":"A pressable button that keeps a checked state.","url":"/components/toggle","kind":"Component"},{"title":"Slider","summary":"Selects a number, or a range, along a track.","url":"/components/slider","kind":"Component"},{"title":"Field","summary":"Labels a custom control and renders its helper or error message.","url":"/components/field","kind":"Component"}],"examples":[{"id":"basic","title":"Basic","description":"A labelled switch with a bound state.","code":"<script lang=\"ts\">\n\timport { Switch } from '@elluzion/iv-ui';\n\n\tlet telemetry = $state(true);\n</script>\n\n<div class=\"stack\">\n\t<Switch label=\"Send anonymous telemetry\" bind:checked={telemetry} />\n\t<p class=\"readout\">telemetry {telemetry ? 'on' : 'off'}</p>\n</div>\n\n<style>\n\t.stack {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tgap: var(--iv_spacing-sm);\n\t}\n\n\t.readout {\n\t\tmargin: 0;\n\t\tfont-family: var(--iv_font-mono);\n\t\tfont-size: var(--iv_text-sm);\n\t\tcolor: var(--iv_foreground-dim);\n\t}\n</style>"},{"id":"sizes","title":"Sizes","description":"`sm` and `md` keep the same hit area.","code":"<script lang=\"ts\">\n\timport { Switch } from '@elluzion/iv-ui';\n\n\tlet a = $state(true);\n\tlet b = $state(true);\n</script>\n\n<div class=\"stack\">\n\t<Switch label=\"Small\" size=\"sm\" bind:checked={a} />\n\t<Switch label=\"Medium\" bind:checked={b} />\n</div>\n\n<style>\n\t.stack {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tgap: var(--iv_spacing-sm);\n\t}\n</style>"},{"id":"disabled","title":"Disabled","description":"The switch is removed from interaction but keeps its value.","code":"<script lang=\"ts\">\n\timport { Switch } from '@elluzion/iv-ui';\n</script>\n\n<div class=\"stack\">\n\t<Switch label=\"Locked by policy\" checked disabled />\n\t<Switch label=\"Available\" />\n</div>\n\n<style>\n\t.stack {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tgap: var(--iv_spacing-sm);\n\t}\n</style>"}],"markdown":"/components/switch.md","page":"/components/switch"}