import { ColorShade, getColorHash } from "#/utils/colors"; import { useTheme } from "next-themes"; import { FC } from "react"; export enum AvatarSize { SMALL = "small", BASE = "base", LARGE = "large", } interface AvatarProps { name: string | null | undefined; loginName: string; imageUrl?: string; size?: AvatarSize; shadow?: boolean; } export const Avatar: FC = ({ size = AvatarSize.BASE, name, loginName, imageUrl, shadow, }) => { // const { resolvedTheme } = useTheme(); let credentials = ""; if (name) { const split = name.split(" "); const initials = split[0].charAt(0) + (split[1] ? split[1].charAt(0) : ""); credentials = initials; } else { const username = loginName.split("@")[0]; let separator = "_"; if (username.includes("-")) { separator = "-"; } if (username.includes(".")) { separator = "."; } const split = username.split(separator); const initials = split[0].charAt(0) + (split[1] ? split[1].charAt(0) : ""); credentials = initials; } const color: ColorShade = getColorHash(loginName); // const avatarStyleDark = { // backgroundColor: color[900], // color: color[200], // }; // const avatarStyleLight = { // backgroundColor: color[200], // color: color[900], // }; return (
{imageUrl ? ( ) : ( {credentials} )}
); };