WlAvatar
Appearance
Full example
<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>Content
Full example
<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.
Full 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>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
label | string | Not set | Initials. |
image | string | Not set | Image URL. |
size | WlAvatarSize | 32 | Size in px: 24 | 28 | 32 | 36 | 48. |
presence | WlAvatarPresence | Not set | Presence indicator. |
pt | WlPt< | Not set | Attributes of internal Legato UI elements. |
name | string | Not set | Person's name, used for image alt text and fallback initials. |
presenceLabel | string | Not set | Accessible presence text; otherwise the current locale supplies it. |
shape | "circle" | | "circle" | Avatar outline shape. |
Events
No public events.
Slots
| Slot | Type / values | Content |
|---|---|---|
default | — | Custom content instead of label/image. |
Pass-through: pt
Sections WlAvatar are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | span | The root section in WlConfig.pt.avatar configuration. |
image | img.wl-avatar__img | The image section in WlConfig.pt.avatar configuration. |
label | span | The label section in WlConfig.pt.avatar configuration. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Image alt comes from label. For meaningful initials/slot content, add a role and accessible name, or the person's name nearby.
- Presence is a decorative aria-hidden dot; explain online/busy/offline in text.
- Size does not replace semantics. Keep the user's name when replacing an image with initials; the application handles image loading errors.
Keyboard and application responsibilities
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesIn your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.