-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAvatar.tsx
24 lines (21 loc) · 911 Bytes
/
Avatar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import * as RadixAvatar from '@radix-ui/react-avatar';
import { FC, useMemo } from 'react';
import { FaCat } from 'react-icons/fa';
import { backgroundColorBySeed } from '@/util/user';
export const Avatar: FC<{ src?: string; seed?: string }> = ({ src, seed }) => {
// Generate a deterministic color based on the seed string
const backgroundColor = useMemo(() => {
return backgroundColorBySeed(seed);
}, [seed]);
return (
<RadixAvatar.Root className="size-8 rounded-md overflow-hidden block">
<RadixAvatar.Image src={src} alt="avatar" className="w-full h-full object-contain" />
<RadixAvatar.Fallback
className="w-full h-full flex items-center justify-center"
style={{ backgroundColor }}
>
<FaCat className="size-4" />
</RadixAvatar.Fallback>
</RadixAvatar.Root>
);
};