import clsx from 'clsx'; import React, { ComponentProps, ComponentPropsWithoutRef, forwardRef, } from 'react'; import {Link} from 'react-router-dom'; import {Tooltip} from '@common/ui/tooltip/tooltip'; import {AvatarPlaceholderIcon} from '@common/auth/ui/account-settings/avatar/avatar-placeholder-icon'; type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | string; export interface AvatarProps extends ComponentPropsWithoutRef { className?: string; src?: string; label?: string; circle?: boolean; size?: Size; link?: string; fallback?: 'initials' | 'generic'; lazy?: boolean; } export const Avatar = forwardRef( ( { className, circle, size = 'md', src, link, label, fallback = 'generic', lazy = true, ...domProps }, ref, ) => { let renderedAvatar = src ? ( {label} ) : (
); if (label) { renderedAvatar = {renderedAvatar}; } const wrapperProps: ComponentProps = { ...domProps, className: clsx( className, 'relative block overflow-hidden select-none flex-shrink-0', getSizeClassName(size), circle ? 'rounded-full' : 'rounded', ), }; return link ? ( {renderedAvatar} ) : (
{renderedAvatar}
); }, ); function getSizeClassName(size: Size) { switch (size) { case 'xs': return 'w-18 h-18'; case 'sm': return 'w-24 h-24'; case 'md': return 'w-32 h-32'; case 'lg': return 'w-40 h-40'; case 'xl': return 'w-60 h-60'; // allow overriding with custom classNames default: return size; } }