1 import type { ButtonHTMLAttributes, DetailedHTMLProps, Ref } from 'react';
2 import { forwardRef } from 'react';
4 import { c } from 'ttag';
6 import { NotificationDot } from '@proton/atoms';
7 import type { ThemeColor } from '@proton/colors';
8 import DropdownCaret from '@proton/components/components/dropdown/DropdownCaret';
9 import type { IconName } from '@proton/components/components/icon/Icon';
10 import { getInitials } from '@proton/shared/lib/helpers/string';
11 import type { UserModel } from '@proton/shared/lib/interfaces';
12 import isTruthy from '@proton/utils/isTruthy';
14 export interface Props extends DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
18 notification?: ThemeColor;
19 dropdownIcon?: IconName;
22 const UserDropdownButton = (
23 { user, isOpen, notification, dropdownIcon, ...rest }: Props,
24 ref: Ref<HTMLButtonElement>
26 const { Email, DisplayName, Name } = user;
27 const nameToDisplay = DisplayName || Name || ''; // nameToDisplay can be falsy for external account
28 // DisplayName is null for VPN users without any addresses, cast to undefined in case Name would be null too.
29 const initials = getInitials(nameToDisplay || Email || '');
30 const title = [nameToDisplay, `<${Email}>`].filter(isTruthy).join(' ');
35 aria-expanded={isOpen}
38 className="max-w-full flex items-center flex-nowrap gap-3 user-dropdown-button relative interactive-pseudo-protrude rounded interactive--no-background"
41 <DropdownCaret className="md:hidden ml-1 color-weak" iconName={dropdownIcon} isOpen={isOpen} />
44 <span className="flex-1 lh130 user-dropdown-text">
45 <span className="block text-ellipsis text-sm user-dropdown-displayName">{nameToDisplay}</span>
47 <span className="block text-ellipsis color-weak text-sm m-0 lh-rg user-dropdown-email">
53 <span className="lh130 user-dropdown-text">
54 <span className="block text-ellipsis user-dropdown-displayName">{Email}</span>
58 className="my-auto text-sm rounded border p-1 inline-block relative flex shrink-0 user-initials"
61 <span className="m-auto">{initials}</span>
66 className="absolute top-0 right-0 notification-dot--top-right"
67 alt={c('Info').t`Attention required`}
74 export default forwardRef<HTMLButtonElement, Props>(UserDropdownButton);