WlSwitch

Switch with a slot label.
Components / Inputs v0.1.0

Appearance

Full example
<div class="wl-stack" data-space="md">
  <WlSwitch v-model="value" aria-label="Email notifications" >
    {{ "Email notifications" }}
  </WlSwitch>
</div>

States

Full example
<div class="wl-stack" data-space="md">
  <WlSwitch v-model="value" aria-label="Email notifications" >
    {{ "Email notifications" }}
  </WlSwitch>
</div>

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.

Full 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-subheading">{{ "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-subheading">{{ "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>