WlTag

Tag. Can include a remove button.
Components / Data v0.1.0

Appearance

Design
Full example
<script setup lang="ts">
import { WlButton, WlTag } from "legato-ui";
import { ref } from "vue";
const visible = ref(true);
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlTag
      v-if="visible"
      removable
      color="blue"
      tone="info"
      icon="check"
      size="sm"
      remove-label="Remove Design tag"
      
      @remove="visible = false"
    >{{ "Design" }}</WlTag>
    <WlButton v-else size="sm" @click="visible = true">{{ "Restore tag" }}</WlButton>
  </div>
</template>

Size and density

Design
Full example
<script setup lang="ts">
import { WlButton, WlTag } from "legato-ui";
import { ref } from "vue";
const visible = ref(true);
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlTag
      v-if="visible"
      removable
      color="blue"
      tone="info"
      icon="check"
      size="sm"
      remove-label="Remove Design tag"
      
      @remove="visible = false"
    >{{ "Design" }}</WlTag>
    <WlButton v-else size="sm" @click="visible = true">{{ "Restore tag" }}</WlButton>
  </div>
</template>

Variants and removable tags

All five colours, removable with a unique removeLabel, controlled array and restoring focus/tags.

tone
neutralaccentinfosuccesswarningdanger
color
DefaultReleaseDoneIn progressOverdue
DesignDevelopmentReview

Selected tags: Design, Development, Review.

The remove event identifies the tag to remove. The application updates the array and restores focus.

Full example
<script setup lang="ts">
import { WlButton, WlTag, type WlTagColor, type WlTone } from "legato-ui";
import { nextTick, ref } from "vue";
const labels = { gray: "Default", blue: "Release", green: "Done", amber: "In progress", red: "Overdue" } satisfies Record<WlTagColor, string>;
const tones = ["neutral", "accent", "info", "success", "warning", "danger"] as const satisfies readonly WlTone[];
const tags = ref(["Design", "Development", "Review"]);
const controls = ref<HTMLElement | null>(null);
async function remove(tag: string): Promise<void> {
  tags.value = tags.value.filter((value) => value !== tag);
  await nextTick();
  controls.value?.querySelector<HTMLButtonElement>("button")?.focus();
}
</script>

<template>
  <div class="wl-stack" data-space="lg">
    <div class="wl-stack" data-space="xs">
      <code>tone</code>
      <div class="wl-inline" data-space="sm">
        <WlTag v-for="tone in tones" :key="tone" :tone="tone">{{ tone }}</WlTag>
      </div>
    </div>
    <div class="wl-stack" data-space="xs">
      <code>color</code>
      <div class="wl-inline" data-space="sm">
        <WlTag v-for="(label, color) in labels" :key="color" :color="color">{{ label }}</WlTag>
      </div>
    </div>
    <div ref="controls" class="wl-inline" data-space="sm"><WlTag
                                                            v-for="tag in tags"
                                                            :key="tag"
                                                            color="blue"
                                                            removable
                                                            :remove-label="'Remove tag ' + tag"
                                                            @remove="remove(tag)"
                                                          >{{ tag }}</WlTag>
      <WlButton
        size="sm"
        variant="ghost"
        @click="tags = ['Design', 'Development', 'Review']"
      >{{ "Restore tags" }}</WlButton>
    </div>
    <p class="wl-text-small" role="status">{{ "Selected tags:" }} {{ tags.join(', ') || "none" }}.</p>
    <p class="wl-text-small wl-text-muted">{{ "The remove event identifies the tag to remove. The application updates the array and restores focus." }}</p>
  </div>
</template>