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
|
|
|
|
2019-03-15 22:18:00 +00:00
|
|
|
import { ContactType } from '../../types/Contact';
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
import { LocalizerType } from '../../types/Util';
|
|
|
|
import {
|
|
|
|
renderAvatar,
|
|
|
|
renderContactShorthand,
|
|
|
|
renderName,
|
|
|
|
} from './_contactUtil';
|
2018-05-22 19:31:43 +00:00
|
|
|
|
2018-05-03 02:43:23 +00:00
|
|
|
interface Props {
|
2019-03-15 22:18:00 +00:00
|
|
|
contact: ContactType;
|
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;
|
2018-05-03 02:43:23 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 19:31:43 +00:00
|
|
|
export class EmbeddedContact extends React.Component<Props> {
|
2018-05-08 00:51:29 +00:00
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
contact,
|
|
|
|
i18n,
|
2018-06-27 20:53:49 +00:00
|
|
|
isIncoming,
|
2018-07-09 21:29:13 +00:00
|
|
|
onClick,
|
2019-11-15 02:12:31 +00:00
|
|
|
tabIndex,
|
2018-06-27 20:53:49 +00:00
|
|
|
withContentAbove,
|
|
|
|
withContentBelow,
|
2018-05-08 00:51:29 +00:00
|
|
|
} = this.props;
|
2018-06-27 20:53:49 +00:00
|
|
|
const module = 'embedded-contact';
|
2019-01-30 20:15:07 +00:00
|
|
|
const direction = isIncoming ? 'incoming' : 'outgoing';
|
2018-05-08 00:51:29 +00:00
|
|
|
|
|
|
|
return (
|
2019-11-07 21:36:16 +00:00
|
|
|
<button
|
2018-07-07 00:48:14 +00:00
|
|
|
className={classNames(
|
2018-06-27 20:53:49 +00:00
|
|
|
'module-embedded-contact',
|
|
|
|
withContentAbove
|
|
|
|
? 'module-embedded-contact--with-content-above'
|
|
|
|
: null,
|
|
|
|
withContentBelow
|
|
|
|
? 'module-embedded-contact--with-content-below'
|
|
|
|
: null
|
|
|
|
)}
|
2019-11-15 02:12:31 +00:00
|
|
|
onKeyDown={(event: React.KeyboardEvent) => {
|
|
|
|
if (event.key !== 'Enter' && event.key !== 'Space') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onClick) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}}
|
2019-11-07 21:36:16 +00:00
|
|
|
onClick={(event: React.MouseEvent) => {
|
|
|
|
if (onClick) {
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}}
|
2019-11-15 02:12:31 +00:00
|
|
|
tabIndex={tabIndex}
|
2018-06-27 20:53:49 +00:00
|
|
|
>
|
2019-10-04 18:06:17 +00:00
|
|
|
{renderAvatar({ contact, i18n, size: 52, direction })}
|
2018-06-27 20:53:49 +00:00
|
|
|
<div className="module-embedded-contact__text-container">
|
|
|
|
{renderName({ contact, isIncoming, module })}
|
|
|
|
{renderContactShorthand({ contact, isIncoming, module })}
|
2018-05-08 00:51:29 +00:00
|
|
|
</div>
|
2019-11-07 21:36:16 +00:00
|
|
|
</button>
|
2018-05-08 00:51:29 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|