- Replace avatar image from API with gradient avatar from twake-mui (#457)
- Display 2-letter initials (e.g., "JD" for "John Doe") instead of single letter - Add getInitials helper function in avatarUtils for reusability - Update Avatar in PeopleSearch, CalendarSearch, and Menubar components - Remove avatarUrl prop usage across all Avatar components
This commit is contained in:
@@ -9,3 +9,21 @@ export function stringToGradient(str: string): string | undefined {
|
||||
if (!str) return undefined;
|
||||
return nameToColor(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get initials from a name string (max 2 characters)
|
||||
* @param name - Name string like "John Doe", "Alice", or "john.doe@email.com"
|
||||
* @returns Initials like "JD", "A", or "J"
|
||||
*/
|
||||
export function getInitials(name: string): string {
|
||||
if (!name) return "";
|
||||
|
||||
const trimmed = name.trim();
|
||||
const words = trimmed.split(/\s+/).filter(Boolean);
|
||||
|
||||
if (words.length >= 2) {
|
||||
return `${words[0][0]}${words[1][0]}`.toUpperCase();
|
||||
}
|
||||
|
||||
return trimmed[0]?.toUpperCase() ?? "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user