Skip to content

Commit b752cfd

Browse files
authored
fix: correction of initials in the avatar (#407)
* feat: moved the logic of initials into a separate function, where fixed the problem * fix: flow
1 parent 2345e9f commit b752cfd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/components/Avatar/Avatar.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ const CAMERA_ICON_SIZE = {
2929
xxl: '24px',
3030
};
3131

32+
const getInitials = (firstName?: string, lastName?: string): string => {
33+
if (firstName && lastName) return firstName.slice(0, 1) + lastName.slice(0, 1);
34+
35+
if (firstName && !lastName) return firstName.slice(0, 1);
36+
37+
if (!firstName && lastName) return lastName.slice(0, 1);
38+
39+
return DEFAULT_INITIALS;
40+
};
41+
3242
function Avatar({
3343
src,
3444
firstName,
@@ -38,7 +48,7 @@ function Avatar({
3848
pickVariant,
3949
...rest
4050
}: AvatarProps) {
41-
const initials = firstName && lastName ? firstName.slice(0, 1) + lastName.slice(0, 1) : DEFAULT_INITIALS;
51+
const initials = getInitials(firstName, lastName);
4252

4353
return (
4454
<AvatarTag pickVariant={ pickVariant } { ...rest } firstName={ firstName } tagName="div">

0 commit comments

Comments
 (0)