forked from mtusi2026/mtusi2026lab4
перенос 3 лабы
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user