import * as React from "react" import * as AvatarPrimitive from "@radix-ui/react-avatar" import { LucideProps } from "lucide-react" import { cn } from "../../design-lib/utils" // Define type for different avatar sizes type sizes = "sm" | "md" | "lg" | "xl" | "super" // Define props for the main Avatar component type AvatarProps = React.ComponentPropsWithoutRef< typeof AvatarPrimitive.Root > & { size?: sizes } // Define props for the AvatarImage component type AvatarImageProps = React.ComponentPropsWithoutRef< typeof AvatarPrimitive.Image > // Define props for the AvatarWithIcon component type AvatarWithIconProps = React.HTMLAttributes & { size?: sizes src: string alt?: string icon: (props: LucideProps) => JSX.Element } // Define CSS classes for different avatar sizes const SIZE_CLASSES = { sm: "h-8 w-8", md: "h-10 w-10", lg: "h-12 w-12", xl: "h-14 w-14", super: "h-20 w-20", default: "h-10 w-10", } // Get CSS class for a given size const getSize = (size?: sizes): string => SIZE_CLASSES[size || "default"] // Main Avatar component const Avatar = React.forwardRef< React.ElementRef, AvatarProps >(({ className, size, ...props }, ref) => ( )) Avatar.displayName = AvatarPrimitive.Root.displayName // AvatarImage component const AvatarImage = React.forwardRef< React.ElementRef, AvatarImageProps >(({ className, ...props }, ref) => ( )) AvatarImage.displayName = AvatarPrimitive.Image.displayName // AvatarWithIcon component const AvatarWithIcon = React.forwardRef( ({ className, size, src, alt, icon: Icon, ...props }, ref) => (
{alt}
) ) AvatarWithIcon.displayName = "AvatarWithIcon" // AvatarGroup component const AvatarGroup = React.forwardRef< HTMLDivElement, React.HTMLAttributes & { avatars: Array<{ src: string; alt?: string }> limit?: number size?: sizes } >(({ className, avatars, limit, size, ...props }, ref) => { const avatarsToRender = avatars.slice(0, limit) const remainingAvatars = avatars.length - avatarsToRender.length return (
{avatarsToRender.map((avatar, index) => (
{avatar.alt}
))} {remainingAvatars > 0 && (

+{remainingAvatars}

)}
) }) AvatarGroup.displayName = "AvatarGroup" // AvatarFallback component const AvatarFallback = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName // AvatarPlaceHolder component const AvatarPlaceHolder = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { size?: sizes } >(({ className, size, ...props }, ref) => ( )) AvatarPlaceHolder.displayName = "AvatarPlaceHolder" export { Avatar, AvatarImage, AvatarFallback, AvatarGroup, AvatarPlaceHolder, AvatarWithIcon, }