Skip to content

Commit

Permalink
fix: correction of initials in the avatar (#407)
Browse files Browse the repository at this point in the history
* feat: moved the logic of initials into a separate function, where fixed the problem

* fix: flow
  • Loading branch information
a1eksandrk authored Mar 28, 2022
1 parent 2345e9f commit b752cfd
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit b752cfd

Please sign in to comment.