WlAvatar

Avatar: initials (label) or image, with a presence indicator.
Components / Data v0.1.0

Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.

Settings

size

Size in px: 24 | 28 | 32 | 36 | 48.

presence

Presence indicator.

label

Initials.

image

Image URL.

name

Person's name, used for image alt text and fallback initials.

presenceLabel

Accessible presence text; otherwise the current locale supplies it.

Props pt, shape, models, handlers and slots can be edited in the SFC. See their descriptions in API.

Example

AM
AMThe outline color follows the name. The same name and palette keep the same color on the server and client.
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 { WlAvatar } from "legato-ui";
import { getWlColorFromString } from "legato-ui/utils";
import { computed } from "vue";
const namedAvatarPt = computed(() => ({
  root: {
    style: { outline: `2px solid ${getWlColorFromString("Anna Mikhailova")}`, outlineOffset: "2px" }
  }
}));
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlAvatar
      label="AM"
      presence="online"
      aria-label="Anna Mikhailova, online"
      
    />
    <div class="wl-inline" data-space="md">
      <WlAvatar
        name="Anna Mikhailova"
        :pt="namedAvatarPt"
        role="img"
        aria-label="Anna Mikhailova"
      />
      <span class="wl-text-small">{{ "The outline color follows the name. The same name and palette keep the same color on the server and client." }}</span>
    </div>
  </div>
</template>

Sizes, presence, image and slot

24/28/32/36/48, three presence statuses, a safe local image/initials and a custom icon.

DGDGDGDGDG
MKMaria — online
DSDenis — busy
EVElena — offline
Dmitry's avatar
AMThe outline color follows the name. The same name and palette keep the same color on the server and client.
Vue SFC · additional example
<script setup lang="ts">
import { WlAvatar, type WlAvatarSize, WlCheckbox, WlIcon } from "legato-ui";
import { getWlColorFromString } from "legato-ui/utils";
import { computed, ref } from "vue";
const namedAvatarPt = computed(() => ({
  root: {
    style: { outline: `2px solid ${getWlColorFromString("Anna Mikhailova")}`, outlineOffset: "2px" }
  }
}));
const sizes = [24, 28, 32, 36, 48] as const satisfies readonly WlAvatarSize[];
const imageEnabled = ref(true);
const image = "data:image/svg+xml," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><rect width="48" height="48" rx="12" fill="#2563eb"/><circle cx="24" cy="18" r="8" fill="#fff"/><path d="M10 44c0-18 28-18 28 0" fill="#fff"/></svg>');
</script>

<template>
  <div class="wl-stack" data-space="lg">
    <div class="wl-inline" data-space="md"><WlAvatar
      v-for="size in sizes"
      :key="size"
      label="DG"
      :size="size"
      role="img"
      :aria-label="'Dmitry — avatar ' + size + ' pixels'"
    /></div>
    <div class="wl-inline" data-space="lg">
      <div class="wl-inline" data-space="xs">
        <WlAvatar label="MK" :size="36" presence="online" />
        <span class="wl-text-small">{{ "Maria — online" }}</span>
      </div>
      <div class="wl-inline" data-space="xs">
        <WlAvatar label="DS" :size="36" presence="busy" />
        <span class="wl-text-small">{{ "Denis — busy" }}</span>
      </div>
      <div class="wl-inline" data-space="xs">
        <WlAvatar label="EV" :size="36" presence="offline" />
        <span class="wl-text-small">{{ "Elena — offline" }}</span>
      </div>
    </div>
    <WlCheckbox v-model="imageEnabled">{{ "Use local image" }}</WlCheckbox>
    <div class="wl-inline" data-space="md"><WlAvatar
                                             :image="imageEnabled ? image : undefined"
                                             :label="imageEnabled ? 'Dmitry\'s avatar' : 'DG'"
                                             :size="48"
                                             role="img"
                                             aria-label="Dmitry — image or initials"
                                           />
      <WlAvatar :size="48" role="img" aria-label="User without a photo">
        <WlIcon name="user" :size="24" />
      </WlAvatar>
    </div>
    <div class="wl-inline" data-space="md">
      <WlAvatar
        name="Anna Mikhailova"
        :pt="namedAvatarPt"
        role="img"
        aria-label="Anna Mikhailova"
      />
      <span class="wl-text-small">{{ "The outline color follows the name. The same name and palette keep the same color on the server and client." }}</span>
    </div>
  </div>
</template>