fix: allow unicodes in initials

This commit is contained in:
HannesOberreiter
2026-04-16 14:21:13 +02:00
parent dbad8e976b
commit 3bf6e6fa19
3 changed files with 14 additions and 10 deletions
@@ -5,7 +5,6 @@
import upperFirst from 'lodash/upperFirst';
import camelCase from 'lodash/camelCase';
import initials from 'initials';
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
@@ -35,6 +34,19 @@ const COLORS = [
'midnight-blue',
];
const getInitials = (name) => {
const words = name
.trim()
.split(/[\s-]+/)
.filter(Boolean);
if (words.length === 0) return '';
if (words.length === 1) return [...words[0]].slice(0, 2).join('');
return words
.slice(0, 2)
.map((word) => [...word][0])
.join('');
};
const getColor = (name) => {
let sum = 0;
for (let i = 0; i < name.length; i += 1) {
@@ -78,7 +90,7 @@ const UserAvatar = React.memo(
background: avatarUrl && `url("${avatarUrl}") center / cover`,
}}
>
{!avatarUrl && <span className={styles.initials}>{initials(user.name).slice(0, 2)}</span>}
{!avatarUrl && <span className={styles.initials}>{getInitials(user.name)}</span>}
{withCreatorIndicator && <span className={styles.creatorIndicator}>+</span>}
</span>
);