1 import { useEffect, useState } from 'react';
3 import { useMailSettings } from '@proton/mail/mailSettings/hooks';
4 import { getInitials } from '@proton/shared/lib/helpers/string';
5 import { HIDE_SENDER_IMAGES } from '@proton/shared/lib/mail/mailSettings';
6 import clsx from '@proton/utils/clsx';
8 import useSenderImage from './hooks/useSenderImage';
14 bimiSelector?: string;
15 displaySenderImage?: boolean;
16 variant?: 'default' | 'small';
19 const ContactImage = ({ email, name, className, bimiSelector, displaySenderImage, variant = 'default' }: Props) => {
20 const [mailSettings] = useMailSettings();
21 const canLoad = !!displaySenderImage && !!email && mailSettings?.HideSenderImages === HIDE_SENDER_IMAGES.SHOW;
22 const url = useSenderImage(canLoad ? email : '', bimiSelector);
23 const [tryToLoad, setTryToLoad] = useState(false);
34 className={clsx(className, 'item-sender-image')}
36 width={variant === 'default' ? '32' : '28'}
38 onError={() => setTryToLoad(false)}
39 loading="lazy" // Lazy load the image only when it's in the viewport
40 data-testid="contact-image"
41 style={{ inlineSize: variant === 'default' ? '2rem' : '1.75rem' }} // 32px, but following main font size
46 return <span data-testid="contact-initials">{getInitials(name)}</span>;
49 export default ContactImage;