signal-desktop/ts/components/conversation/EmbeddedContact.tsx

84 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-10-30 15:34:04 -05:00
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import classNames from 'classnames';
import { ContactType } from '../../types/Contact';
2019-01-14 13:49:58 -08:00
import { LocalizerType } from '../../types/Util';
import {
renderAvatar,
renderContactShorthand,
renderName,
} from './_contactUtil';
export type Props = {
contact: ContactType;
2019-01-14 13:49:58 -08:00
i18n: LocalizerType;
isIncoming: boolean;
withContentAbove: boolean;
withContentBelow: boolean;
tabIndex: number;
onClick?: () => void;
};
export class EmbeddedContact extends React.Component<Props> {
2020-09-14 12:51:27 -07:00
public render(): JSX.Element {
const {
contact,
i18n,
isIncoming,
onClick,
tabIndex,
withContentAbove,
withContentBelow,
} = this.props;
const module = 'embedded-contact';
const direction = isIncoming ? 'incoming' : 'outgoing';
return (
2019-11-07 13:36:16 -08:00
<button
2020-09-14 12:51:27 -07:00
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;
}
if (onClick) {
event.stopPropagation();
event.preventDefault();
onClick();
}
}}
2019-11-07 13:36:16 -08:00
onClick={(event: React.MouseEvent) => {
if (onClick) {
event.stopPropagation();
event.preventDefault();
onClick();
}
}}
tabIndex={tabIndex}
>
2019-10-04 11:06:17 -07:00
{renderAvatar({ contact, i18n, size: 52, direction })}
<div className="module-embedded-contact__text-container">
{renderName({ contact, isIncoming, module })}
{renderContactShorthand({ contact, isIncoming, module })}
</div>
2019-11-07 13:36:16 -08:00
</button>
);
}
}