Avatar
Avatars are used to represent a user or an entity in the UI. They can be used in various contexts, such as user profiles, comments, or lists.
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:
<div q-avatar>
<img alt="John Doe" q-avatar-image src="/images/avatar-man.png" />
<div q-avatar-content>JD</div>
<div q-avatar-status status="active"></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
<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
<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>Variants
When displaying initials or an icon, use the variant input on q-avatar-content to set the avatar's style. Available variants are neutral (default), contrast, and brand.
Neutral
<div q-avatar>
<div q-avatar-content variant="neutral">OK</div>
</div>
High Contrast
<div q-avatar>
<div q-avatar-content variant="contrast">OK</div>
</div>
Brand
<div q-avatar>
<div q-avatar-content variant="brand">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
<div q-avatar>
<img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
<div q-avatar-content>JD</div>
<div q-avatar-status status="active"></div>
</div>
Offline
<div q-avatar>
<img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
<div q-avatar-content>JD</div>
<div q-avatar-status status="offline"></div>
</div>
Away
<div q-avatar>
<img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
<div q-avatar-content>JD</div>
<div q-avatar-status status="away"></div>
</div>
Busy
<div q-avatar>
<img alt="Jane Doe" q-avatar-image src="/images/avatar-woman.png" />
<div q-avatar-content>JD</div>
<div q-avatar-status status="busy"></div>
</div>State Callback
You can listen for changes to the avatar's state by using the stateChanged output.
<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
| Prop | Type |
|---|---|
The document's text/writing direction. | 'ltr' | 'rtl' |
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' |
Optional status for the avatar, renders a dot indicator next to the avatar. | | 'offline' |
The style variant of the avatar. | | 'neutral' |
Function called when the avatar state is changed. | { |
'ltr' | 'rtl'
string| 'xs'
| 'sm'
| 'md'
| 'lg'
| 'xl'
| 'offline'
| 'active'
| 'away'
| 'busy'
| 'neutral'
| 'contrast'
| 'brand'
{
state: string
}
q-avatar-image
| Prop | Type |
|---|---|
id attribute. If
omitted, a unique identifier will be generated for accessibility.) | string |
stringq-avatar-content
| Prop | Type |
|---|---|
id attribute. If
omitted, a unique identifier will be generated for accessibility.) | string |
stringq-avatar-status
| Prop | Type |
|---|---|
id attribute. If
omitted, a unique identifier will be generated for accessibility.) | string |
string