'use client'; import * as AvatarPrimitive from '@radix-ui/react-avatar'; import * as React from 'react'; import { cn } from '@/lib/utils'; const Avatar = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); Avatar.displayName = AvatarPrimitive.Root.displayName; const AvatarImage = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); AvatarImage.displayName = AvatarPrimitive.Image.displayName; const AvatarFallback = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName; export { Avatar, AvatarFallback, AvatarImage }; type AvatarProps = React.ComponentProps; interface AvatarGroupProps extends React.ComponentProps<'div'> { children: React.ReactElement[]; max?: number; } export const AvatarGroup = ({ children, max, className, ...props }: AvatarGroupProps) => { const totalAvatars = React.Children.count(children); const displayedAvatars = React.Children.toArray(children) .slice(0, max) .reverse(); const remainingAvatars = max ? Math.max(totalAvatars - max, 1) : 0; return (
{remainingAvatars > 0 && ( +{remainingAvatars} )} {displayedAvatars.map((avatar, index) => { if (!React.isValidElement(avatar)) return null; return (
{React.cloneElement(avatar as React.ReactElement, { className: 'ring-2 ring-background', })}
); })}
); };