Toggle
Toggle is a checkbox that is styled to look like a switch button.
Usage
import { Toggle } from 'stwui';
import Toggle from 'stwui/toggle';
<script lang="ts">
import { Toggle } from 'stwui';
</script>
<Toggle name="toggle-1" />
With Left Label
<script lang="ts">
import { Toggle } from 'stwui';
</script>
<Toggle name="toggle-2">
<Toggle.ContentLeft slot="content-left">
<Toggle.ContentLeft.Label slot="label">Left Label</Toggle.ContentLeft.Label>
</Toggle.ContentLeft>
</Toggle>
With Both Labels
<script lang="ts">
import { Toggle } from 'stwui';
</script>
<Toggle name="toggle-4">
<Toggle.ContentLeft slot="content-left">
<Toggle.ContentLeft.Label slot="label">Left Label</Toggle.ContentLeft.Label>
</Toggle.ContentLeft>
<Toggle.ContentRight slot="content-right">
<Toggle.ContentRight.Label slot="label">Right Label</Toggle.ContentRight.Label>
</Toggle.ContentRight>
</Toggle>
With Description
<script lang="ts">
import { Toggle } from 'stwui';
</script>
<Toggle name="toggle-5">
<Toggle.ContentRight slot="content-right">
<Toggle.ContentRight.Label slot="label">Right Label</Toggle.ContentRight.Label>
<Toggle.ContentRight.Description slot="description"
>(10% off)</Toggle.ContentRight.Description
>
</Toggle.ContentRight>
</Toggle>
<script lang="ts">
import { Toggle } from 'stwui';
let on = false;
let error: string | undefined = 'Here is an error!';
$: if (on) {
error = undefined;
} else {
error = 'Here is an error!';
}
</script>
<Toggle name="toggle" {error} bind:on />
<script lang="ts">
import { Toggle } from 'stwui';
</script>
<Toggle name="toggle">
<Toggle.LeftIcon slot="left-icon" data={brightness_5} class="text-white" />
<Toggle.RightIcon slot="right-icon" data={brightness_4} />
</Toggle>
Toggle Props
name | string | nanoid() |
on | boolean | false |
error | string | undefined | |
Toggle Slots
content-left | <Toggle.ContentLeft slot="content-left" /> |
left-icon | <Toggle.LeftIcon slot="left-icon" /> |
right-icon | <Toggle.RightIcon slot="right-icon" /> |
content-right | <Toggle.ContentRight slot="content-right" /> |
Toggle.LeftIcon Props
data | string (IconData) | |
viewBox | string | 0 0 24 24 |
size | string | 24px |
width | string | 24px |
height | string | 24px |
color | string | currentColor |
stroke | string | undefined | |
fill | string | currentColor |
Toggle.RightIcon Props
data | string (IconData) | |
viewBox | string | 0 0 24 24 |
size | string | 24px |
width | string | 24px |
height | string | 24px |
color | string | currentColor |
stroke | string | undefined | |
fill | string | currentColor |
Toggle.ContentLeft Slots
label | <Toggle.ContentLeft.Label slot="label" /> |
left-icon | <Toggle.ContentLeft.Description slot="description" /> |
Toggle.ContentLeft.Title Slots
Toggle.ContentLeft.Description Slots
Toggle.ContentRight Slots
label | <Toggle.ContentRight.Label slot="label" /> |
left-icon | <Toggle.ContentRight.Description slot="description" /> |
Toggle.ContentRight.Title Slots
Toggle.ContentRight.Description Slots
Toggle Class Identifiers
stwui-toggle-wrapper |
stwui-toggle |
stwui-toggle-dongle |
stwui-toggle-left-icon-wrapper |
stwui-toggle-right-icon-wrapper |
stwui-toggle-error |
stwui-toggle-label |
stwui-toggle-content-left |
stwui-toggle-content-right |
stwui-toggle-description |