Avatar

Alpha component

Avatar component is subject to major changes and is for experimentation purposes only. Not recommended for use in production software.

Avatar can be used to visually represent users and apps.

Import

import { Avatar } from '@contentful/f36-avatar';

Examples

Variants

The Avatar can be rendered in different variants:

  • User - default variant
  • App

Sizes

The Avatar can be rendered in different sizes:

  • Tiny - 20px
  • Small - 24px
  • Medium - 32px, default size
  • Large - 48px

Show Color Border

The Avatar can be rendered with outline colors, the color is determined by the position of the Avatar. There are 6 different colors: green, red, yellow, orange, purple and gray

Special style variant primary

The Avatar can be rendered with a special color border reserved for the current user

Special style variant muted

This property modifies the opacity of the Avatar component to indicate activity state.

Icons

An Avatar can display an icon on top of the image

Fallback

In some cases a user or an app will have no avatar to display. Instead, a fallback can be rendered when the src property is undefined (or an empty string "") and the loading state is not true.

Loading skeleton

When the avatar image is loading, a loading skeleton will be shown automatically. You can also force the loading state with the isLoading prop.

Props (API reference)

Open in Storybook

Name

Type

Default

alt
string

className
string

CSS class to be appended to the root element

colorVariant
"primary"
"muted"
"green"
"red"
"orange"
"yellow"
"purple"
"gray"

icon
ReactElement<any, string | JSXElementConstructor<any>>

isLoading
false
true

size
"small"
"tiny"
"medium"
"large"

src
string

testId
string

A [data-test-id] attribute used for testing purposes

tooltipProps
Omit<TooltipProps, "children">

A tooltipProps attribute used to conditionally render the tooltip around root element

variant
"app"
"user"

Accessibility

Make sure to pass a fitting alt property, especially if the avatar is used by itself without the user's name next to it.