Switch
An on/off control that applies immediately.
import { Switch } from '@elluzion/iv-ui'; 01 Preview
Basic
A labelled switch with a bound state.
Send anonymous telemetry
telemetry on
Source· svelte Show Hide
<script lang="ts">
import { Switch } from '@elluzion/iv-ui';
let telemetry = $state(true);
</script>
<div class="stack">
<Switch label="Send anonymous telemetry" bind:checked={telemetry} />
<p class="readout">telemetry {telemetry ? 'on' : 'off'}</p>
</div>
<style>
.stack {
display: flex;
flex-direction: column;
gap: var(--iv_spacing-sm);
}
.readout {
margin: 0;
font-family: var(--iv_font-mono);
font-size: var(--iv_text-sm);
color: var(--iv_foreground-dim);
}
</style>02 Usage
- Bind
checked; changes apply without a submit step. - Use
labelfor the visible and accessible name. - Prefer
Checkboxwhen the choice is part of a form that is submitted later.
03 Examples
Sizes
sm and md keep the same hit area.
Small
Medium
Source· svelte Show Hide
<script lang="ts">
import { Switch } from '@elluzion/iv-ui';
let a = $state(true);
let b = $state(true);
</script>
<div class="stack">
<Switch label="Small" size="sm" bind:checked={a} />
<Switch label="Medium" bind:checked={b} />
</div>
<style>
.stack {
display: flex;
flex-direction: column;
gap: var(--iv_spacing-sm);
}
</style>Disabled
The switch is removed from interaction but keeps its value.
Locked by policy
Available
Source· svelte Show Hide
<script lang="ts">
import { Switch } from '@elluzion/iv-ui';
</script>
<div class="stack">
<Switch label="Locked by policy" checked disabled />
<Switch label="Available" />
</div>
<style>
.stack {
display: flex;
flex-direction: column;
gap: var(--iv_spacing-sm);
}
</style>04 API
import { Switch } from '@elluzion/iv-ui';Props
4 props · 3 events · 0 snippets| Prop | Type | Default | Description |
|---|---|---|---|
| checked bindable | boolean | false | On/off state. Bind with bind:checked. |
| disabled | boolean | false | Disables interaction and applies the disabled treatment. |
| label | string | '' | Label rendered next to the switch. |
| size | 'sm' | 'md' | 'md' | Control size. |
class, id, style, aria-*, and data-* are forwarded through rest props.
Events
| Event | Handler type | Description |
|---|---|---|
| onchange | (e: CustomEvent<{ checked: boolean }>) => void | Called with { checked } after the state changes. |
| onfocus | (e: FocusEvent) => void | Called when the control receives focus. |
| onblur | (e: FocusEvent) => void | Called when the control loses focus. |
The legacy on:name form is accepted for every event.
05 Accessibility
| Keys | Action |
|---|---|
| Tab | Moves focus to the switch. |
| Space / Enter | Toggles the switch. |
- The control exposes
role="switch"witharia-checked. - The label is linked through
aria-labelledby. - Focus is drawn on the track and is never removed.
06 Tokens & CSS hooks
Tokens used
--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
Class hooks
.iv-checked.iv-disabled.iv-label.iv-md.iv-root.iv-sm.iv-switch.iv-thumb