"use client";
import * as React from "react";
import { RefreshCw } from "lucide-react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { colorFromUserName } from "@/lib/yjs-provider";
export type PresenceUser = {
clientId: number;
name: string;
color: string;
imageUrl?: string;
};
function initials(name: string): string {
const parts = name.trim().split(/\s+/).filter(Boolean);
if (parts.length === 0) return "?";
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
return `${parts[0][0] ?? ""}${parts[1][0] ?? ""}`.toUpperCase();
}
export type PresenceAvatarsProps = {
users: PresenceUser[];
/** @default 5 */
maxVisible?: number;
className?: string;
};
/**
* Horizontal stack of collaborator avatars (initials or image) with cursor-colored borders.
*/
export function PresenceAvatars({
users,
maxVisible = 5,
className,
}: PresenceAvatarsProps) {
const visible = users.slice(0, maxVisible);
const overflow = Math.max(0, users.length - maxVisible);
if (users.length === 0) {
return null;
}
return (
) : (
{initials(u.name)}
)}