fix: strip leading punctuation when computing avatar initials
This commit is contained in:
@@ -189,10 +189,17 @@ export function Avatar({ name, email, contactPhotoUri, size = "md", className, d
|
|||||||
|
|
||||||
const getInitials = () => {
|
const getInitials = () => {
|
||||||
if (name) {
|
if (name) {
|
||||||
const parts = name.trim().split(/\s+/);
|
const parts = name
|
||||||
|
.trim()
|
||||||
|
.split(/\s+/)
|
||||||
|
.map((p) => p.replace(/^[^\p{L}\p{N}]+/u, ""))
|
||||||
|
.filter((p) => p.length > 0);
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
return `${parts[0][0]}${parts[parts.length - 1][0]}`.toUpperCase();
|
return `${parts[0][0]}${parts[parts.length - 1][0]}`.toUpperCase();
|
||||||
}
|
}
|
||||||
|
if (parts.length === 1) {
|
||||||
|
return parts[0].slice(0, 2).toUpperCase();
|
||||||
|
}
|
||||||
return name.slice(0, 2).toUpperCase();
|
return name.slice(0, 2).toUpperCase();
|
||||||
}
|
}
|
||||||
if (email) {
|
if (email) {
|
||||||
|
|||||||
Reference in New Issue
Block a user