forked from MergeFi/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvatar.tsx
More file actions
54 lines (51 loc) · 1.36 KB
/
Copy pathAvatar.tsx
File metadata and controls
54 lines (51 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import Image from "next/image";
import { cn } from "@/lib/utils";
function seedToUrl(seed: string) {
return `https://api.dicebear.com/9.x/identicon/svg?seed=${encodeURIComponent(seed)}&backgroundType=gradientLinear`;
}
export function Avatar({
seed,
src,
size = 32,
className,
}: {
seed: string;
src?: string;
size?: number;
className?: string;
}) {
return (
<Image
src={src ?? seedToUrl(seed)}
alt={seed}
width={size}
height={size}
unoptimized
className={cn(
"rounded-full border border-slate-200 bg-slate-50 dark:border-slate-700 dark:bg-slate-800",
className,
)}
/>
);
}
export function AvatarStack({ seeds, max = 5 }: { seeds: string[]; max?: number }) {
const shown = seeds.slice(0, max);
const rest = seeds.length - shown.length;
return (
<div className="flex items-center">
{shown.map((seed, i) => (
<Avatar
key={seed}
seed={seed}
size={28}
className={cn("ring-2 ring-white dark:ring-slate-950", i > 0 && "-ml-2")}
/>
))}
{rest > 0 && (
<span className="-ml-2 flex h-7 w-7 items-center justify-center rounded-full bg-slate-100 text-[11px] font-medium text-slate-600 ring-2 ring-white dark:bg-slate-800 dark:text-slate-300 dark:ring-slate-950">
+{rest}
</span>
)}
</div>
);
}