34 lines
969 B
TypeScript
Raw Normal View History

2024-05-04 23:31:35 -07:00
"use client"
import { colorClasses, colors } from "@/lib/colors"
import { useOthers } from "@/liveblocks.config"
import { useState } from "react"
2024-05-03 14:27:45 -07:00
export function Avatars() {
const users = useOthers()
2024-05-04 23:31:35 -07:00
const colorNames = Object.keys(colors)
const [activeColors, setActiveColors] = useState([])
2024-05-03 14:27:45 -07:00
return (
2024-05-04 23:31:35 -07:00
<div className="flex space-x-2">
2024-05-03 14:27:45 -07:00
{users.map(({ connectionId, info }) => {
2024-05-04 23:31:35 -07:00
const c = colorNames[
connectionId % colorNames.length
] as keyof typeof colors
2024-05-03 14:27:45 -07:00
2024-05-04 23:31:35 -07:00
return (
<div
className={`w-8 h-8 font-mono rounded-full ring-1 ${colorClasses[c].ring} ring-offset-2 ring-offset-background overflow-hidden bg-gradient-to-tr ${colorClasses[c].bg} flex items-center justify-center text-xs font-medium`}
>
{info.name
.split(" ")
.slice(0, 2)
.map((letter) => letter[0].toUpperCase())}
</div>
)
})}
2024-05-03 14:27:45 -07:00
</div>
)
}