{"slug":"toggle","name":"Toggle","category":"Form & Input","summary":"A pressable button that keeps a checked state.","status":"stable","since":"0.2.0","import":"import { Toggle } from '@elluzion/iv-ui';","usage":["Use `Toggle` for formatting and view modes; use `Switch` for settings that save immediately.","Pass visible children or a `label` for the accessible name.","`icon` renders before the children; the check mark appears when checked."],"props":[{"name":"checked","type":"boolean","default":"false","description":"Pressed 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":"Accessible name. Visible text can be passed as children instead.","required":false,"bindable":false},{"name":"size","type":"'sm' | 'md' | 'lg'","default":"'md'","description":"Control size.","required":false,"bindable":false}],"events":[{"name":"click","type":"(e: MouseEvent) => void","default":null,"description":"Called when the element is activated.","required":false,"bindable":false},{"name":"change","type":"(e: CustomEvent<{ checked: boolean }>) => void","default":null,"description":"Called with `{ checked }` after the state changes.","required":false,"bindable":false}],"snippets":[{"name":"icon","type":"Snippet","default":null,"description":"Icon rendered inside the toggle.","required":false,"bindable":false},{"name":"children","type":"Snippet","default":null,"description":"Content rendered inside the component.","required":false,"bindable":false}],"types":[],"manual":[],"tokens":["--iv_border","--iv_border-hover","--iv_btn-pad-x","--iv_btn-pad-x-lg","--iv_btn-pad-x-sm","--iv_control-pad-y","--iv_control-pad-y-lg","--iv_control-pad-y-sm","--iv_cursor","--iv_disabled-opacity","--iv_ease-in-out","--iv_ease-out","--iv_font-ui","--iv_foreground","--iv_radius-sm","--iv_reverse-bg","--iv_reverse-fg","--iv_reverse-hover","--iv_ring","--iv_ring-width","--iv_spacing-sm","--iv_spacing-xs","--iv_surface","--iv_surface-elevated","--iv_surface-hover","--iv_text-btn","--iv_text-btn-sm","--iv_text-lg","--iv_transition-base","--iv_transition-fast","--iv_weight-semibold"],"cssHooks":["iv-check","iv-checked","iv-disabled","iv-icon","iv-lg","iv-sm","iv-toggle"],"accessibility":{"keyboard":[["Tab","Moves focus to the toggle."],["Space / Enter","Toggles the pressed state."]],"notes":["The toggle is a native button with `aria-pressed`.","With no visible text, pass `label` so the control has an accessible name.","Focus uses the standard button ring."]},"related":[{"title":"ToggleGroup","summary":"A row of toggles with single or multiple selection.","url":"/components/toggle-group","kind":"Component"},{"title":"Button","summary":"Triggers an action or submits a form.","url":"/components/button","kind":"Component"},{"title":"Switch","summary":"An on/off control that applies immediately.","url":"/components/switch","kind":"Component"},{"title":"Checkbox","summary":"A binary choice with an optional label and a mixed state.","url":"/components/checkbox","kind":"Component"}],"examples":[{"id":"basic","title":"Basic","description":"A labelled toggle with a bound state.","code":"<script lang=\"ts\">\n\timport { Toggle } from '@elluzion/iv-ui';\n\n\tlet pinned = $state(true);\n</script>\n\n<div class=\"stack\">\n\t<Toggle bind:checked={pinned}>Pin to dashboard</Toggle>\n\t<p class=\"readout\">pinned {pinned ? 'yes' : 'no'}</p>\n</div>\n\n<style>\n\t.stack {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\talign-items: start;\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":"icons","title":"Icons","description":"Icons inherit the current text color and size step.","code":"<script lang=\"ts\">\n\timport { IconBold, IconItalic, IconUnderline } from '@tabler/icons-svelte';\n\timport { Toggle } from '@elluzion/iv-ui';\n\n\tlet bold = $state(true);\n\tlet italic = $state(false);\n\tlet underline = $state(false);\n</script>\n\n<div class=\"row\">\n\t<Toggle bind:checked={bold} label=\"Bold\"><IconBold size={14} /></Toggle>\n\t<Toggle bind:checked={italic} label=\"Italic\"><IconItalic size={14} /></Toggle>\n\t<Toggle bind:checked={underline} label=\"Underline\"><IconUnderline size={14} /></Toggle>\n</div>\n\n<style>\n\t.row {\n\t\tdisplay: flex;\n\t\tgap: var(--iv_spacing-sm);\n\t}\n</style>"},{"id":"sizes","title":"Sizes","description":"`sm`, `md`, and `lg` share the same shape.","code":"<script lang=\"ts\">\n\timport { Toggle } from '@elluzion/iv-ui';\n\n\tlet a = $state(true);\n\tlet b = $state(true);\n\tlet c = $state(true);\n</script>\n\n<div class=\"row\">\n\t<Toggle size=\"sm\" bind:checked={a}>Small</Toggle>\n\t<Toggle bind:checked={b}>Medium</Toggle>\n\t<Toggle size=\"lg\" bind:checked={c}>Large</Toggle>\n</div>\n\n<style>\n\t.row {\n\t\tdisplay: flex;\n\t\tflex-wrap: wrap;\n\t\talign-items: center;\n\t\tgap: var(--iv_spacing-sm);\n\t}\n</style>"}],"markdown":"/components/toggle.md","page":"/components/toggle"}