A fully customizable icon component that represents your user
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.
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.
import { Avatar } from "@cord-sdk/react";
export const Example = () => (
<Avatar userId={'my-awesome-user-id'} />
);
true
, a tooltip with the user's name will
appear on top of the Avatar. The default value is false
If you want to customize this component, you can target the classes below in your app's CSS. These are guaranteed to be stable.
.cord-avatar-container
.cord-avatar-fallback
.cord-avatar-image
.cord-not-present
.cord-present
.cord-loading
cord-color-palette-X
class, where X is a number between 1 and 8. This number is unique per user ID. This means that the same user ID will always be assigned the same palette number. So, if the user with ID "Jack" has a cord-color-palette-2
in the Avatar, it will also have the same palette in PagePresence, and in every other Cord component..cord-avatar-fallback {
color: black;
}
.cord-avatar-container:is(.cord-color-palette-1, .cord-color-palette-2) .cord-avatar-fallback {
background-color: #7bdff2;
}
.cord-avatar-container:is(.cord-color-palette-3, .cord-color-palette-4) .cord-avatar-fallback {
background-color: #b2f7ef;
}
.cord-avatar-container:is(.cord-color-palette-5, .cord-color-palette-6) .cord-avatar-fallback {
background-color: #f7d6e0;
}
.cord-avatar-container:is(.cord-color-palette-7, .cord-color-palette-8) .cord-avatar-fallback {
background-color: #f2b5d4;
}
Not finding the answer you need? Ask our Developer Community