signal-desktop/ts/components/AvatarPopup.tsx

125 lines
3.4 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2019 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2019-10-17 18:22:07 +00:00
import * as React from 'react';
import classNames from 'classnames';
2020-01-17 22:23:19 +00:00
import type { Props as AvatarProps } from './Avatar';
2022-12-09 20:37:45 +00:00
import { Avatar, AvatarSize } from './Avatar';
2021-09-17 22:24:21 +00:00
import { useRestoreFocus } from '../hooks/useRestoreFocus';
2019-10-17 18:22:07 +00:00
import type { LocalizerType, ThemeType } from '../types/Util';
import { Emojify } from './conversation/Emojify';
2019-10-17 18:22:07 +00:00
export type Props = {
readonly i18n: LocalizerType;
readonly theme: ThemeType;
2019-10-17 18:22:07 +00:00
hasPendingUpdate: boolean;
startUpdate: () => unknown;
2021-07-19 19:26:06 +00:00
onEditProfile: () => unknown;
2019-10-17 18:22:07 +00:00
onViewPreferences: () => unknown;
onViewArchive: () => unknown;
// Matches Popper's RefHandler type
innerRef?: React.Ref<HTMLDivElement>;
2019-10-17 18:22:07 +00:00
style: React.CSSProperties;
2022-09-28 16:27:52 +00:00
name?: string;
2022-12-09 20:37:45 +00:00
} & Omit<AvatarProps, 'onClick' | 'size'>;
2019-10-17 18:22:07 +00:00
2022-11-18 00:45:19 +00:00
export function AvatarPopup(props: Props): JSX.Element {
2019-10-17 18:22:07 +00:00
const {
hasPendingUpdate,
2019-10-17 18:22:07 +00:00
i18n,
2020-07-24 01:35:32 +00:00
name,
2021-07-19 19:26:06 +00:00
onEditProfile,
2019-10-17 18:22:07 +00:00
onViewArchive,
onViewPreferences,
phoneNumber,
profileName,
startUpdate,
2019-10-17 18:22:07 +00:00
style,
title,
2019-10-17 18:22:07 +00:00
} = props;
2020-07-24 01:35:32 +00:00
const shouldShowNumber = Boolean(name || profileName);
2019-10-17 18:22:07 +00:00
2019-11-07 21:36:16 +00:00
// Note: mechanisms to dismiss this view are all in its host, MainHeader
// Focus first button after initial render, restore focus on teardown
const [focusRef] = useRestoreFocus();
2019-11-07 21:36:16 +00:00
2019-10-17 18:22:07 +00:00
return (
<div style={style} className="module-avatar-popup">
2021-07-19 19:26:06 +00:00
<button
className="module-avatar-popup__profile"
onClick={onEditProfile}
ref={focusRef}
type="button"
>
2022-12-09 20:37:45 +00:00
<Avatar {...props} size={AvatarSize.FORTY_EIGHT} />
2019-10-17 18:22:07 +00:00
<div className="module-avatar-popup__profile__text">
<div className="module-avatar-popup__profile__name">
<Emojify text={profileName || title} />
</div>
2020-07-24 01:35:32 +00:00
{shouldShowNumber ? (
2019-10-17 18:22:07 +00:00
<div className="module-avatar-popup__profile__number">
{phoneNumber}
</div>
) : null}
</div>
2021-07-19 19:26:06 +00:00
</button>
2019-10-17 18:22:07 +00:00
<hr className="module-avatar-popup__divider" />
2019-11-07 21:36:16 +00:00
<button
2020-09-12 00:46:52 +00:00
type="button"
2019-11-07 21:36:16 +00:00
className="module-avatar-popup__item"
onClick={onViewPreferences}
>
2019-10-17 18:22:07 +00:00
<div
className={classNames(
'module-avatar-popup__item__icon',
'module-avatar-popup__item__icon-settings'
)}
/>
<div className="module-avatar-popup__item__text">
2023-03-30 00:03:25 +00:00
{i18n('icu:mainMenuSettings')}
2019-10-17 18:22:07 +00:00
</div>
</button>
2020-09-12 00:46:52 +00:00
<button
type="button"
className="module-avatar-popup__item"
onClick={onViewArchive}
>
2019-10-17 18:22:07 +00:00
<div
className={classNames(
'module-avatar-popup__item__icon',
'module-avatar-popup__item__icon-archive'
)}
/>
<div className="module-avatar-popup__item__text">
2023-03-30 00:03:25 +00:00
{i18n('icu:avatarMenuViewArchive')}
2019-10-17 18:22:07 +00:00
</div>
</button>
{hasPendingUpdate && (
<button
type="button"
className="module-avatar-popup__item"
onClick={startUpdate}
>
<div
className={classNames(
'module-avatar-popup__item__icon',
'module-avatar-popup__item__icon--update'
)}
/>
<div className="module-avatar-popup__item__text">
2023-03-30 00:03:25 +00:00
{i18n('icu:avatarMenuUpdateAvailable')}
</div>
<div className="module-avatar-popup__item--badge" />
</button>
)}
2019-10-17 18:22:07 +00:00
</div>
);
2022-11-18 00:45:19 +00:00
}