Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/components/Avatar/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ const CAMERA_ICON_SIZE = {
xxl: '24px',
};

const getInitials = (firstName?: string, lastName?: string): string => {
if (firstName && lastName) return firstName.slice(0, 1) + lastName.slice(0, 1);

if (firstName && !lastName) return firstName.slice(0, 1);

if (!firstName && lastName) return lastName.slice(0, 1);

return DEFAULT_INITIALS;
};

function Avatar({
src,
firstName,
Expand All @@ -38,7 +48,7 @@ function Avatar({
pickVariant,
...rest
}: AvatarProps) {
const initials = firstName && lastName ? firstName.slice(0, 1) + lastName.slice(0, 1) : DEFAULT_INITIALS;
const initials = getInitials(firstName, lastName);

return (
<AvatarTag pickVariant={ pickVariant } { ...rest } firstName={ firstName } tagName="div">
Expand Down