A fully customizable icon component that represents your user


This component is in development; interface and features are subject to change prior to final release.

Visit the Replacements API step by step guide.

Live Demo
With profile picture
Without profile picture

When to use #

The Avatar component renders an avatar icon showing the profile picture of the user ID you have given as an input. If your user doesn't have a profile picture, it will render an icon with the first letter of the user's name capitalized, in a white font and black background. You can of course customize this by using our Replacements API and replacing AvatarFallback.

Adding avatars and profile pictures to your app helps build social context. It can make it clear who sent a message, who is present on a page, or give any other social cue, that makes your users feel connected.

You can even combine avatars to do something like creating your own facepile. Let's say some of your users have a profile picture, but others don't, and you don't want to use the avatar and facepile's default fallback. You could render a series of Avatar components for users who have a profile picture, and then your own fallback for ones that don't -- or even build your own wrapper around this component that would do that.


How to use #

React:
import { betaV2 } from "@cord-sdk/react";
      
function ExampleAvatar({userID}) {
    const user = useUserData(userID);
    
    return <betaV2.Avatar
        user={user}
        enableTooltip
    />;
}
import { betaV2 } from "@cord-sdk/react";
      
function ExampleAvatar({userID}) {
    const user = useUserData(userID);
    
    return <betaV2.Avatar
        user={user}
        enableTooltip
    />;
}
Copy

Alternatively, you can use Avatar.ByID and we will fetch the user data for you.

React:
import { betaV2 } from "@cord-sdk/react";
      
function ExampleAvatarByID({user}) {    
    return <betaV2.Avatar.ByID
        userID={user.id}
        enableTooltip
    />;
}
import { betaV2 } from "@cord-sdk/react";
      
function ExampleAvatarByID({user}) {    
    return <betaV2.Avatar.ByID
        userID={user.id}
        enableTooltip
    />;
}
Copy

View Source Code


Properties #


user #

required
Data of the user whose avatar is to be displayed.

This property can be one of the following:

  • undefined
  • null
  • ClientUserData

    This is an object with the following fields:

    Show property details



enableTooltip #

optional
boolean
Whether to enable tooltip on the avatar.


isAbsent #

optional
boolean
Whether the user is absent.


style #

optional
CSSProperties
Passes the style of the component. It will be applied to the root element.


className #

optional
string
Any classes to be added to the component. It will be applied to the root element.


replace #

optional
ReplaceConfig
Object that contains the components that will be replaced in the Avatar. Find more information about it here.

Customization with Replacements #

Live Demo
With profile picture
Without profile picture

If you want to customize your component, you can customize the CSS (see below), but you can also switch parts of the component for your own ones with out Replacements API.

These are the components you can replace in the avatar. Some are better understood in context. We suggest inspecting the component with your browser's developer tools to find elements with a data-cord-replace attribute.

ComponentDescription
AvatarFallback
Shown when there is an error loading the avatar (bad url, not existing, etc.).
AvatarTooltip
Shown when hovering over the avatar.

CSS customization #

If you want to customize this component, you can target the classes below in your app's CSS. These are guaranteed to be stable.

There are more classes that are best understood in context. We suggest inspecting the component with your browser's developer tools to view everything. You can target any classes starting with cord-.

Class nameDescription
.cord-avatar-container
Applied to the container div. This class is always present.
.cord-avatar-fallback
Applied to the container div which is shown only when a user doesn't have a profile picture.
.cord-avatar-image
Applied to the img tag.
.cord-not-present
Applied to avatars of users that are not marked as present.
.cord-present
Applied to avatars of users that are marked as present.
.cord-loading
Applied to avatars before profile pictures load.

Not finding the answer you need? Ask our Developer Community

Ask Cordy