WlSwitch
Switch with a slot label.
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
size
md
Size.
Disables the switch.
Error state.
Indicate pending work supplied by the application.
Props pt, labelPosition, density, models, handlers and slots can be edited in the SFC. See their descriptions in API.
Example
Focus: outside the example · pointer: outside the example
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { WlSwitch } from "legato-ui";
import { ref } from "vue";
const value = ref(true);
</script>
<template>
<div class="wl-stack" data-space="md">
<WlSwitch v-model="value" aria-label="Email notifications" >
{{ "Email notifications" }}
</WlSwitch>
</div>
</template>Settings and states
Compare sm/md, labels, a validated setting with an error, disabled and resetting models.
Two sizes and a slot label
Space toggles the focused switch. The label names the setting; aria-checked conveys its state.
Error and unavailable setting
Enable protection before continuing.
Notifications: enabled. Brief: disabled. Protection: disabled.
Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlField, WlSwitch } from "legato-ui";
import { ref } from "vue";
const notifications = ref(true);
const compactNotifications = ref(false);
const protectedMode = ref(false);
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlSwitch">
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "Two sizes and a slot label" }}</h3>
<WlSwitch v-model="notifications" size="md">{{ "Notifications, md" }}</WlSwitch>
<WlSwitch v-model="compactNotifications" size="sm">{{ "Brief notifications, sm" }}</WlSwitch>
<p class="wl-text-small wl-text-muted">{{ "Space toggles the focused switch. The label names the setting; aria-checked conveys its state." }}</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "Error and unavailable setting" }}</h3>
<WlField
id="docs-switch-protected"
v-slot="{ id, ariaDescribedby, invalid }"
:error="protectedMode ? undefined : 'Enable protection before continuing.'"
><WlSwitch
:id="id"
v-model="protectedMode"
:invalid="invalid"
:aria-describedby="ariaDescribedby"
>{{ "Protected mode" }}</WlSwitch></WlField>
<WlSwitch :model-value="true" disabled>{{ "Archiving is enabled by an administrator" }}</WlSwitch>
<div class="wl-inline" data-space="sm">
<WlButton size="sm" @click="notifications = true; compactNotifications = false; protectedMode = false">
{{ "Reset settings" }}
</WlButton>
</div>
<p class="wl-text-small" role="status">{{
"Notifications:"
}} {{
notifications ? "enabled" : "disabled"
}}{{
". Brief:"
}} {{
compactNotifications ? "enabled" : "disabled"
}}{{
". Protection:"
}} {{
protectedMode ? "enabled" : "disabled"
}}.</p>
</section>
</div>
</template>