Avatar

Avatars provide visual representation of users, accounts, or entities. They support multiple content types including icons, initials, and images, with optional status indicators to communicate presence or state information.

import {AvatarModule} from "@qualcomm-ui/angular/avatar"

Usage

Avatars can display a user or entity image, initials, or custom content when an image is unavailable. They can also indicate the status of the user or entity.

Overview

The anatomy of the avatar component is as follows:

  • q-avatar-root: The main component.
  • q-avatar-image: (optional) Displays an image as the avatar.
  • q-avatar-content: (optional) Displays alternative content, such as initials or an icon, and acts as a fallback if the image fails to load.
  • q-avatar-status: (optional) Shows a status indicator dot.

Examples

Showcase

Here's a typical usage example:

John Doe
<div q-avatar status="active">
  <img alt="John Doe" q-avatar-image src="/images/avatar-man.png" />
  <div q-avatar-content>JD</div>
  <div q-avatar-status></div>
</div>

Content

The q-avatar-content directive displays alternative content within the avatar. Use it by itself to show initials or an icon, or together with q-avatar-image to provide fallback content if the image cannot be loaded.

Initials
OK
Icon
Fallback
JD
Initials
<div q-avatar>
  <div q-avatar-content>OK</div>
</div>
Icon
<div q-avatar>
  <div q-avatar-content>
    <svg aria-label="User" qIcon="User"></svg>
  </div>
</div>
Fallback
<div q-avatar>
  <img alt="John Doe" q-avatar-image src="https://example.invalid" />
  <div q-avatar-content>JD</div>
</div>

Sizes

Use the size input to set the size of the avatar. The available sizes are xs, sm, md (default), lg, and xl.

XSmall
Jane Doe
Small
Jane Doe
Medium
Jane Doe
Large
Jane Doe
XLarge
Jane Doe
XSmall
<div q-avatar size="xs">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
</div>
Small
<div q-avatar size="sm">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
</div>
Medium
<div q-avatar size="md">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
</div>
Large
<div q-avatar size="lg">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
</div>
XLarge
<div q-avatar size="xl">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
</div>

Emphasis

When displaying initials or an icon, use the emphasis input to set the avatar's color. Available values are neutral (default), contrast, and brand.

Neutral
OK
High Contrast
OK
Brand
OK
Neutral
<div emphasis="neutral" q-avatar>
  <div q-avatar-content>OK</div>
</div>
High Contrast
<div emphasis="contrast" q-avatar>
  <div q-avatar-content>OK</div>
</div>
Brand
<div emphasis="brand" q-avatar>
  <div q-avatar-content>OK</div>
</div>

Status

To indicate the status of the user or entity, use the q-avatar-status directive and set its status input to one of: active, offline (default), away, or busy.

Active
Jane Doe
Offline
Jane Doe
Away
Jane Doe
Busy
Jane Doe
Active
<div q-avatar status="active">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
  <div q-avatar-status></div>
</div>
Offline
<div q-avatar status="offline">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
  <div q-avatar-status></div>
</div>
Away
<div q-avatar status="away">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
  <div q-avatar-status></div>
</div>
Busy
<div q-avatar status="busy">
  <img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
  <div q-avatar-content>JD</div>
  <div q-avatar-status></div>
</div>

State Callback

You can listen for changes to the avatar's state by using the stateChanged output.

John Doe
current state: loaded
JD
current state: error
<div q-avatar (stateChanged)="currentStateValid.set($event.state)">
  <img alt="John Doe" q-avatar-image src="/images/avatar-man.png" />
  <div q-avatar-content>JD</div>
</div>
<output>current state: {{ currentStateValid() }}</output>
<div q-avatar (stateChanged)="currentStateInvalid.set($event.state)">
  <img alt="John Doe" q-avatar-image src="https://example.invalid" />
  <div q-avatar-content>JD</div>
</div>
<output>current state: {{ currentStateInvalid() }}</output>

API

q-avatar

PropType
The document's text/writing direction.
'ltr' | 'rtl'
Governs the color of the avatar.
| 'neutral'
| 'contrast'
| 'brand'
HTML id attribute. If omitted, a unique identifier will be generated for accessibility.)
string
Governs the width and height of the avatar as well as the font size of its content.
| 'xs'
| 'sm'
| 'md'
| 'lg'
| 'xl'
Optional status for the avatar, renders a dot indicator next to the avatar.
| 'offline'
| 'active'
| 'away'
| 'busy'
Deprecated use emphasis instead
| 'neutral'
| 'contrast'
| 'brand'
Function called when the avatar state is changed.
{
state: string
}
Type
'ltr' | 'rtl'
Description
The document's text/writing direction.
Type
| 'neutral'
| 'contrast'
| 'brand'
Description
Governs the color of the avatar.
Type
string
Description
HTML id attribute. If omitted, a unique identifier will be generated for accessibility.)
Type
| 'xs'
| 'sm'
| 'md'
| 'lg'
| 'xl'
Description
Governs the width and height of the avatar as well as the font size of its content.
Type
| 'offline'
| 'active'
| 'away'
| 'busy'
Description
Optional status for the avatar, renders a dot indicator next to the avatar.
Type
| 'neutral'
| 'contrast'
| 'brand'
Description
Deprecated use emphasis instead
Type
{
state: string
}
Description
Function called when the avatar state is changed.

q-avatar-image

PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.)
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.)

q-avatar-content

PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.)
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.)

q-avatar-status

PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.)
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.)