Toggle
ActionsA button that stays pressed until pressed again (bind:pressed), announced as pressed or not. variant (default, outline) and size (sm, default, lg) as for buttons.
import { Toggle } from '@limerdev/zest'; Use for
One on/off formatting or view option in a toolbar: bold, show grid, pin.
Don't
A setting in a form or settings page: use
Switch or Checkbox. Several related toggles: use ToggleGroup. A toggle without a name: label icon-only ones with aria-label.Examples
Basic
Toggles stay pressed. Name icon-only ones with aria-label.
<script lang="ts">
import Pin from '@lucide/svelte/icons/pin';
import Star from '@lucide/svelte/icons/star';
import { Toggle } from '@limerdev/zest';
let pinned = $state(true);
</script>
<Toggle bind:pressed={pinned} aria-label="Pin project"><Pin /></Toggle>
<Toggle variant="outline" aria-label="Favourite"><Star /></Toggle>
<Toggle variant="outline" size="sm">Billable only</Toggle>
<Toggle size="lg" disabled>Archived</Toggle> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
Toggle
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | null | false | true | false | Whether the toggle is disabled or not. |
| onPressedChange | OnChangeFn<boolean> | – | A callback function called when the toggle is pressed. |
| pressed bindable | boolean | false | Whether the toggle is pressed or not. |
| size | "default" | "sm" | "lg" | 'default' | The height and padding, from the theme's field size. |
| variant | "outline" | "default" | 'default' | default is plain until pressed; outline has a border. |