Componentsv2.189.1
Iconsv1.19.0
MCPv0.8.62
Tokensv0.34.3

A component that displays a user's avatar, supporting images, Gravatar, and initials.

Importing

The component can be imported via:

import { Avatar } from '@customerio/pluma-components/react';
Loading editor

Usage

The Avatar component can display user avatars in several ways, following a priority order:

  1. Custom image via src prop
  2. Gravatar image via email prop (only when withGravatar is enabled)
  3. Text fallback using initials from name, email, or custom initials text

Basic Usage

Loading editor

With email (Gravatar)

Passing an email derives the avatar's initials and label. To also look up a Gravatar image for that address, opt in with withGravatar. Gravatar is off by default — only enable it where surfacing a third-party image for an email is appropriate (e.g. your own team members), not for your customers' own contacts.

Loading editor

With tooltip

If you place the avatar without any context around it, it is recommended to add a tooltip so that the user can understand which user the avatar represents.

Loading editor

Auto color

Use the autoColor prop to automatically generate a deterministic background and text color based on the user's name. This is useful for distinguishing users in lists when no image is available.

Loading editor

Size

Use the size prop to pick from the same four tiers as Coin (sm, md, lg, xl), defaulting to md. The initials text scales with the size to stay balanced inside the avatar.

Loading editor

Customizing the initials text

The initials typography is derived from size, but you can fine-tune it with the text-prefixed props: text (a typography style), textSize, textWeight, textFamily, and textFontStyle. Passing textSize (or a full text style) overrides the size-balanced default.

Loading editor

Customizing

You should almost never need to customize the src, label, and initials. However, we do provide escape hatches for these cases.

Loading editor

Accessibility

The Avatar component follows accessibility best practices:

  • Uses appropriate ARIA labels based on the provided label, name, or email
  • Supports keyboard navigation when interactive elements tooltips are enabled

API

When true, automatically generates a deterministic background and text color based on the user's name or email. Useful for distinguishing users in lists when no image is available.

The email address of the user. Used to derive initials and a label, and — when withGravatar is true and no src is provided — to look up a Gravatar image.

An icon to render instead of an image or initials.

The size of the icon. Only applies when icon is provided.

Initials to use if no image is provided. Max 2 characters.

The label for the avatar. Used for the tooltip and alt text.

The name of the user. Used to generate initials if no src is provided.

The size of the avatar, matching Coin's size tiers.

The initials text scales with the size to stay balanced inside the coin — override that with textSize (or a full text style).

The source URL of the image. Takes precedence over email-based Gravatar images.

The font family of the initials.

The font size of the initials. Overrides the size balanced against size (or implied by text).

Whether to look up a Gravatar image from email when no src is provided. Defaults to false — set to true to opt in to the Gravatar lookup. Otherwise the avatar falls back to initials.

Whether to show a tooltip with the label.