2021-12-01 23:37:37 +00:00
|
|
|
// Copyright 2018-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-05-03 02:43:23 +00:00
|
|
|
import React from 'react';
|
2018-07-07 00:48:14 +00:00
|
|
|
import classNames from 'classnames';
|
2018-06-27 20:53:49 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { EmbeddedContactType } from '../../types/EmbeddedContact';
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
2019-01-14 21:49:58 +00:00
|
|
|
import {
|
|
|
|
renderAvatar,
|
|
|
|
renderContactShorthand,
|
|
|
|
renderName,
|
2021-12-01 23:37:37 +00:00
|
|
|
} from './contactUtil';
|
2018-05-22 19:31:43 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type Props = {
|
2021-08-20 01:56:39 +00:00
|
|
|
contact: EmbeddedContactType;
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming: boolean;
|
|
|
|
withContentAbove: boolean;
|
|
|
|
withContentBelow: boolean;
|
2019-11-15 02:12:31 +00:00
|
|
|
tabIndex: number;
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick?: () => void;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export const EmbeddedContact: React.FC<Props> = (props: Props) => {
|
|
|
|
const {
|
|
|
|
contact,
|
|
|
|
i18n,
|
|
|
|
isIncoming,
|
|
|
|
onClick,
|
|
|
|
tabIndex,
|
|
|
|
withContentAbove,
|
|
|
|
withContentBelow,
|
|
|
|
} = props;
|
|
|
|
const module = 'embedded-contact';
|
|
|
|
const direction = isIncoming ? 'incoming' : 'outgoing';
|
2018-05-08 00:51:29 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={classNames(
|
|
|
|
'module-embedded-contact',
|
|
|
|
`module-embedded-contact--${direction}`,
|
|
|
|
withContentAbove ? 'module-embedded-contact--with-content-above' : null,
|
|
|
|
withContentBelow ? 'module-embedded-contact--with-content-below' : null
|
|
|
|
)}
|
|
|
|
onKeyDown={(event: React.KeyboardEvent) => {
|
|
|
|
if (event.key !== 'Enter' && event.key !== 'Space') {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-15 02:12:31 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
if (onClick) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2019-11-15 02:12:31 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
if (onClick) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
tabIndex={tabIndex}
|
|
|
|
>
|
|
|
|
{renderAvatar({ contact, i18n, size: 52, direction })}
|
|
|
|
<div className="module-embedded-contact__text-container">
|
|
|
|
{renderName({ contact, isIncoming, module })}
|
|
|
|
{renderContactShorthand({ contact, isIncoming, module })}
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
};
|