-
Notifications
You must be signed in to change notification settings - Fork 10
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
Avatar background color handling based on initials #753
Conversation
}); | ||
|
||
describe('getInitials', () => { | ||
it('should return initials for a full name', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to be possible to set emoji as customer name, consider checking if such unusual input is handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not handled in here. I believe there is such an implementation in LiveChat Web
export function getInitials(name = ''): string {
const isEmojiInName = EMOJI_REGEX.test(name);
const finalName = name ? name : '';
let initials = '';
initials = finalName
.split(' ')
.map((el) => el.charAt(0))
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
.filter((el) => isAlphaNumeric(removeDiacritics(el)))
.join('')
.substring(0, 2)
.toUpperCase();
// fallback for emoji-only and non-alpha-numeric characters
if (!initials) {
initials = isEmojiInName
? finalName.match(EMOJI_REGEX)?.[0] || ''
: finalName.toLocaleUpperCase().trim().substring(0, 2);
}
return initials;
}
@vladko-uxds Do we want to support emojis
somehow in Design System
?
Resolves: Slack thread
Description
It was decided that background color of the
Avatar
should have a default value if it usestext
type
. It uses a basic algorithm that makes sure that a set of 10 colors are used, and for the exact same initials the color will be always the same.❗️
Attention:
This change brings some sort of breaking change as it will apply new color in for avatars usingtext
type
withoutcolor
provided. By default it wasgrey
.I've also enabled the possibility of using
CSS variable
forcolor
prop as earlier it was impossible due to contrast calculation requiring direct values. It was solved by usingwindow.getComputedStyle
Storybook
https://feature-avatar-default-backgrounds--613a8e945a5665003a05113b.chromatic.com/?path=/story/components-avatar--colors
Checklist
Obligatory:
livechat/design-system
)