- 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:
lenhanphung
2026-01-13 20:44:42 +07:00
committed by GitHub
parent 00266d2701
commit 8b3afc1737
9 changed files with 206 additions and 33 deletions
+18
View File
@@ -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() ?? "";
}