The built-in badge shows a status or a counter right on the avatar; for a marker on arbitrary content take CdsBadge, and for a text label inside a line — CdsTag.
Anatomy
An avatar is a container with one of three kinds of content and an optional badge in the top corner.
Variations
Content
The content comes from one of three props: image — a photo, icon — an icon, text — initials. If you pass several of them, image wins, then icon.
Sizes
The size prop takes a token from xs to xl or a number of pixels. The default size is md.
Colors
The color prop paints the background of an avatar with initials or an icon: a theme token or any CSS color will do.
Badge
The badge prop set to true shows a dot in the corner of the avatar. An object is passed through as props of CdsBadge: this is how you change the color of the dot, show a counter (dot: false plus content) or move the badge away from the edge (floating). The badge slot replaces the content of the badge with anything you like — an icon, for example.
Spacing
The start and end props add a margin on the side of the neighboring content: start — for an avatar at the beginning of a line, end — at the end. This way the avatar fits into text without wrappers that carry outer margins.
Slots
| Slot | Description |
|---|---|
default | Avatar content. Replaces image, icon and text |
badge | Badge content. Shown instead of the dot when badge is on |
Guidelines
Scenarios
Member list
In a list of people the avatar is a fast visual anchor. The start prop gives the margin before the text, photos and initials alternate depending on what the user has, and the badge dot shows who is online right now.
Group of members
When there are many members and little space, avatars are stacked with a slight overlap — a border in the background color separates the neighbors from each other. The last avatar with text="+3" tells how many people did not fit.
Uploading a profile photo
While there is no photo yet, the avatar shows the initials from text — the page is not left with an empty circle. As soon as image gets a link, the photo replaces the initials; after the photo is removed, the initials come back on their own.
API
Props
| Name | Type | Default | Description |
|---|---|---|---|
activeColor | string | undefined | — | Color of the component in its active state |
badge | boolean | CdsBadgeProps | undefined | false | Avatar badge. true shows a dot, an object is passed through as CdsBadge props. |
baseColor | string | undefined | — | Color of the component in its inactive state |
bgColor | string | undefined | — | Background color of the component |
color | string | undefined | — | Component color |
content | string | number | undefined | — | Content displayed in the component. |
end | boolean | undefined | — | Adds a margin on the left — for an avatar at the end of a line of content. |
icon | IconValue | undefined | — | Icon shown in the avatar when no image is set. |
image | string | undefined | — | Source of the avatar image. Takes priority over icon and text. |
size | number | "xs" | "sm" | "md" | "lg" | "xl" | undefined | 'md' | Size of the component |
start | boolean | undefined | — | Adds a margin on the right — for an avatar at the beginning of a line of content. |
tag | string | JSXComponent<any> | undefined | 'div' | Custom HTML tag or component to render |
text | string | number | undefined | — | Text displayed in the component. |
textColor | string | undefined | — | Text color of the component |
theme | string | undefined | — | Component theme |
Slots
| Name | Type | Description |
|---|---|---|
badge | any | Content of the avatar badge. |
default | any | Avatar content. Overrides image, icon and text. |