Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correction of initials in the avatar #407

Merged
merged 2 commits into from
Mar 28, 2022
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