Files
mtusi2026lab4/frontend/src/components/Avatar.tsx
T
2026-10-28 12:40:39 +03:00

27 lines
558 B
TypeScript

import { initials } from "../lib/format";
type AvatarProps = {
label: string;
seed?: string;
size?: "small" | "medium" | "large";
};
function tone(seed: string): number {
let hash = 0;
for (const character of seed) {
hash = (hash * 31 + character.codePointAt(0)!) >>> 0;
}
return hash % 5;
}
export function Avatar({ label, seed = label, size = "medium" }: AvatarProps) {
return (
<span
aria-hidden="true"
className={`avatar avatar--${size} avatar--tone-${tone(seed)}`}
>
{initials(label)}
</span>
);
}