1 import type { ChangeEvent, FocusEventHandler, MouseEventHandler } from 'react';
3 import { useUserSettings } from '@proton/account/userSettings/hooks';
4 import Icon, { type IconName } from '@proton/components/components/icon/Icon';
5 import Checkbox from '@proton/components/components/input/Checkbox';
6 import ContactImage from '@proton/components/containers/contacts/ContactImage';
7 import { DENSITY } from '@proton/shared/lib/constants';
8 import clsx from '@proton/utils/clsx';
10 import './ItemCheckbox.scss';
18 compactClassName?: string;
19 normalClassName?: string;
20 bimiSelector?: string;
21 displaySenderImage?: boolean;
23 variant?: 'default' | 'small';
24 onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
27 const ItemCheckbox = ({
41 const [userSettings] = useUserSettings();
42 const isCompactView = userSettings.Density === DENSITY.COMPACT;
45 * Due to the way we handle focus of parent elements
46 * we need to stop propagation of click and focus
49 const handleClick: MouseEventHandler<HTMLLabelElement> = (event) => event.stopPropagation();
50 const handleFocus: FocusEventHandler<HTMLLabelElement> = (event) => event.stopPropagation();
52 return isCompactView ? (
54 className={clsx(['item-icon-compact', compactClassName])}
57 labelOnClick={handleClick}
60 data-testid="item-checkbox"
64 className={clsx(['item-checkbox-label relative', normalClassName])}
70 className="item-checkbox absolute inset-0 cursor-pointer m-0"
74 data-testid="item-checkbox"
78 'item-icon shrink-0 relative rounded inline-flex',
79 variant === 'small' && 'item-icon--small'
82 backgroundColor: color ?? '',
84 data-testid="element-list:message-checkbox"
87 <span className="m-auto item-abbr rounded overflow-hidden" aria-hidden="true">
89 <Icon name={iconName} color="white" />
94 bimiSelector={bimiSelector}
95 displaySenderImage={displaySenderImage}
96 className="rounded relative"
100 <span className="item-icon-fakecheck m-auto">
101 <Icon color={color ? 'white' : undefined} name="checkmark" className="item-icon-fakecheck-icon" />
108 export default ItemCheckbox;