Avatar
- Usage
- Styling
Avatar is a graphical representation of an object or entity, for example, a person or an organization.
new tab
<vaadin-avatar></vaadin-avatar>
<vaadin-avatar
.name="${`${this.person?.firstName} ${this.person?.lastName}`}"
></vaadin-avatar>
<vaadin-avatar
.img="${this.person?.pictureUrl}"
.name="${`${this.person?.firstName} ${this.person?.lastName}`}"
></vaadin-avatar>
Note
|
Real-time collaboration
This component is optimized for use with Collaboration Kit — a simple way to build real-time collaboration into your app — but can also be used standalone as a regular component.
|
Content
Avatar has three properties: name, abbreviation, and image.
Name and Abbreviation
The name is shown on hover in a tooltip. When a name is set, Avatar auto-generates and display an abbreviation of the specified name. For example, “Allison Torres” becomes “AT”, “John Smith” becomes “JS”, and so on.
new tab
<vaadin-avatar .name="${`${this.person?.firstName} ${this.person?.lastName}`}">
</vaadin-avatar>
The abbreviation can also be set manually. Abbreviations should be kept to a maximum of 2–3 characters.
new tab
<vaadin-avatar name="Augusta Ada King"></vaadin-avatar>
<vaadin-avatar name="Augusta Ada King" abbr="AK"></vaadin-avatar>
Image
Avatar can be used to display images, such as user profile pictures or company logos. Abbreviations aren’t shown when images are used.
new tab
<vaadin-avatar
.img="${this.person?.pictureUrl}"
.name="${`${this.person?.firstName} ${this.person?.lastName}`}"
></vaadin-avatar>
<vaadin-avatar .img="${companyLogo}" name="Company Inc."></vaadin-avatar>
Avatar Group
Avatar Group is used to group multiple Avatars together. It can be used, for example, to show that there are multiple users viewing the same page or for listing members of a project.
new tab
<vaadin-avatar-group
.items="${this.items.map((person) => ({
name: `${person.firstName} ${person.lastName}`,
}))}"
></vaadin-avatar-group>
Maximum Number of Items
You can specify the maximum number of items an Avatar Group should display. Items that overflow are grouped into a single Avatar that displays the overflow count. The name of each hidden item is shown on hover in a tooltip. Clicking the overflow item displays the overflowing avatars and names in a list.
new tab
<vaadin-avatar-group
.maxItemsVisible="${3}"
.items="${this.items.map((person) => ({
name: `${person.firstName} ${person.lastName}`,
}))}"
></vaadin-avatar-group>
Background Color
By default, there are 7 different background colors you can use for Avatar. The background color is set using a color index.
new tab
<vaadin-avatar-group
.items="${this.items.map((person, index) => ({
name: `${person.firstName} ${person.lastName}`,
colorIndex: index,
}))}"
></vaadin-avatar-group>
Using different background colors can be useful when you need to be able to distinguish between users, for example during collaborative work.
Internationalisation (i18n)
All texts in Avatar and Avatar Group are configurable:
Avatar Texts
Property | Text | Description |
---|---|---|
| "Anonymous" | Avatar’s default name. Shown on hover in a tooltip and announced by screen readers when the Avatar is focused. |
Avatar Group Texts
Property | Text | Description |
---|---|---|
| "Anonymous" | Default name for all Avatars in the Avatar Group. |
| "Currently one active user" | Announced by screen readers when there is exactly one Avatar in an Avatar Group and the Avatar is focused. The name of the Avatar is read aloud first. |
| "Currently {count} active users" | Announced by screen readers when there are multiple Avatars in an Avatar Group and an Avatar is focused. The name of the focused Avatar is read aloud first. *{count} is the Avatar Group item count. |
| "{user} joined" | Announced by screen readers when an Avatar is added to the group. *{user} is the Avatar’s name. |
| "{user} left" | Announced by screen readers when an Avatar is removed from the group. *{user} is the Avatar’s name. |
new tab
private i18n: AvatarGroupI18n = {
anonymous: 'Anonyymi',
activeUsers: {
one: 'Yksi käyttäjä aktiivisena',
many: '{count} käyttäjää aktiivisena',
},
joined: 'liittyi',
left: 'lähti',
};
protected override render() {
return html`
<vaadin-avatar-group
.i18n="${this.i18n}"
.items="${this.items.map((person) => ({
name: `${person.firstName} ${person.lastName}`,
}))}"
></vaadin-avatar-group>
`;
}
Size Variants
Avatar has four available size variants:
new tab
<vaadin-avatar
.name="${`${this.person?.firstName} ${this.person?.lastName}`}"
theme="xlarge"
></vaadin-avatar>
<vaadin-avatar
.name="${`${this.person?.firstName} ${this.person?.lastName}`}"
theme="large"
></vaadin-avatar>
<vaadin-avatar
.name="${`${this.person?.firstName} ${this.person?.lastName}`}"
theme="small"
></vaadin-avatar>
<vaadin-avatar
.name="${`${this.person?.firstName} ${this.person?.lastName}`}"
theme="xsmall"
></vaadin-avatar>
Variant | Theme name |
---|---|
Extra large |
|
Large |
|
Small |
|
Extra small |
|
Size variants should be used only in special cases. See Size and Space for details on how to change the default Avatar size.
Use Cases
Avatar can be paired with Menu Bar to create a user account menu.
new tab
protected override async firstUpdated() {
const { people } = await getPeople({ count: 1 });
this.person = people[0];
const avatarElement = document.createElement('vaadin-avatar');
avatarElement.name = `${this.person?.firstName} ${this.person?.lastName}`;
avatarElement.img = this.person?.pictureUrl;
this.menuBarItems = [
{
component: avatarElement,
children: [
{
text: 'Profile',
},
{
text: 'Settings',
},
{
text: 'Help',
},
{
text: 'Sign out',
},
],
},
];
}
protected override render() {
return html`
<vaadin-menu-bar .items="${this.menuBarItems}" theme="tertiary-inline"></vaadin-menu-bar>
`;
}
57551FAE-0B53-46FB-B384-71C3EB9D2CE1