WlCheckbox

Checkbox with a boolean value and slot label.
Components / Inputs v0.1.0

States

Permissions
[1]
Full example
<script setup lang="ts">
import { WlCheckbox } from "legato-ui";
import { ref } from "vue";
const value = ref(true);
const permissions = ref<number[]>([1]);
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlCheckbox v-model="value" >{{ "Receive updates" }}</WlCheckbox>
    <fieldset class="wl-choice-group">
      <legend class="wl-choice-group__legend wl-text-label">{{ "Permissions" }}</legend>
      <div class="wl-surface wl-stack" data-space="sm">
        <WlCheckbox v-model="permissions" :value="1" size="sm">{{ "Read" }}</WlCheckbox>
        <WlCheckbox v-model="permissions" :value="2" size="sm">{{ "Share" }}</WlCheckbox>
        <output class="wl-text-small wl-text-muted" aria-label="Permissions">
          <code>{{ JSON.stringify(permissions) }}</code>
        </output>
      </div>
    </fieldset>
  </div>
</template>

Size and density

Permissions
[1]
Full example
<script setup lang="ts">
import { WlCheckbox } from "legato-ui";
import { ref } from "vue";
const value = ref(true);
const permissions = ref<number[]>([1]);
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlCheckbox v-model="value" >{{ "Receive updates" }}</WlCheckbox>
    <fieldset class="wl-choice-group">
      <legend class="wl-choice-group__legend wl-text-label">{{ "Permissions" }}</legend>
      <div class="wl-surface wl-stack" data-space="sm">
        <WlCheckbox v-model="permissions" :value="1" size="sm">{{ "Read" }}</WlCheckbox>
        <WlCheckbox v-model="permissions" :value="2" size="sm">{{ "Share" }}</WlCheckbox>
        <output class="wl-text-small wl-text-muted" aria-label="Permissions">
          <code>{{ JSON.stringify(permissions) }}</code>
        </output>
      </div>
    </fieldset>
  </div>
</template>

Related checkboxes

Select all available items with calculated indeterminate, consent with an error and disabled.

Permissions
[1]

Linked selection and indeterminate

The application computes the intermediate state when some child items are selected. Space toggles the focused checkbox.

Label, error and disabled

Confirm your agreement.

Notifications selected: 1 of 2. Agreement: not confirmed.

Full example
<script setup lang="ts">
import { WlButton, WlCheckbox, WlField } from "legato-ui";
import { computed, ref } from "vue";
const notifications = ref([{ id: "mail", label: "Email", enabled: true }, { id: "push", label: "Push notifications", enabled: false }]);
const selectedCount = computed(() => notifications.value.filter((item) => item.enabled).length);
const allSelected = computed({
  get: () => selectedCount.value === notifications.value.length,
  set: (checked: boolean) => {
    notifications.value.forEach((item) => {
      item.enabled = checked;
    });
  }
});
const mixed = computed(() => selectedCount.value > 0 && !allSelected.value);
const consent = ref(false);
const permissions = ref<number[]>([1]);
const summary = computed(() =>
  "Notifications selected:" + " " + selectedCount.value + " " + "of" + " "
  + notifications.value.length + ". Agreement:" + " "
  + (consent.value ? "confirmed" : "not confirmed") + "."
);
</script>

<template>
  <div class="wl-stack" data-space="xl" data-input-example="WlCheckbox">
    <fieldset class="wl-choice-group">
      <legend class="wl-choice-group__legend wl-text-label">{{ "Permissions" }}</legend>
      <div class="wl-surface wl-stack" data-space="sm">
        <WlCheckbox v-model="permissions" :value="1" size="sm">{{ "Read" }}</WlCheckbox>
        <WlCheckbox v-model="permissions" :value="2" size="sm">{{ "Share" }}</WlCheckbox>
        <output class="wl-text-small wl-text-muted" aria-label="Permissions">
          <code>{{ JSON.stringify(permissions) }}</code>
        </output>
      </div>
    </fieldset>
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-subheading">{{ "Linked selection and indeterminate" }}</h3>
      <WlCheckbox v-model="allSelected" :indeterminate="mixed">{{ "All available notifications" }}</WlCheckbox>
      <div class="wl-stack" data-space="sm">
        <WlCheckbox v-for="item in notifications" :key="item.id" v-model="item.enabled">{{ item.label }}</WlCheckbox>
      </div>
      <p class="wl-text-small wl-text-muted">{{ "The application computes the intermediate state when some child items are selected. Space toggles the focused checkbox." }}</p>
    </section>
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-subheading">{{ "Label, error and disabled" }}</h3>
      <WlField
        id="docs-checkbox-consent"
        v-slot="{ id, ariaDescribedby, invalid }"
        :error="consent ? undefined : 'Confirm your agreement.'"
      ><WlCheckbox
        :id="id"
        v-model="consent"
        :invalid="invalid"
        :aria-describedby="ariaDescribedby"
        required
      >{{ "I agree to the terms" }}</WlCheckbox></WlField>
      <WlCheckbox :model-value="true" disabled>{{ "System notifications are required" }}</WlCheckbox>
      <WlButton size="sm" @click="allSelected = false; consent = false">{{ "Clear available checkboxes" }}</WlButton>
      <p class="wl-text-small" role="status">{{ summary }}</p>
    </section>
  </div>
</template>