2021-01-14 18:07:05 +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-18 23:57:26 +00:00
|
|
|
import React from 'react';
|
2021-05-28 16:15:17 +00:00
|
|
|
import classNames from 'classnames';
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2020-07-29 23:20:05 +00:00
|
|
|
import { Emojify } from './Emojify';
|
2021-05-28 16:15:17 +00:00
|
|
|
import { ContactNameColorType } from '../../types/Colors';
|
|
|
|
import { getClassNamesFor } from '../../util/getClassNamesFor';
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type PropsType = {
|
2021-05-28 16:15:17 +00:00
|
|
|
contactNameColor?: ContactNameColorType;
|
2021-03-03 20:09:58 +00:00
|
|
|
firstName?: string;
|
2020-07-29 23:20:05 +00:00
|
|
|
module?: string;
|
2021-03-03 20:09:58 +00:00
|
|
|
preferFirstName?: boolean;
|
|
|
|
title: string;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
export const ContactName = ({
|
2021-05-28 16:15:17 +00:00
|
|
|
contactNameColor,
|
2021-03-03 20:09:58 +00:00
|
|
|
firstName,
|
|
|
|
module,
|
|
|
|
preferFirstName,
|
|
|
|
title,
|
|
|
|
}: PropsType): JSX.Element => {
|
2021-05-28 16:15:17 +00:00
|
|
|
const getClassName = getClassNamesFor('module-contact-name', module);
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
let text: string;
|
|
|
|
if (preferFirstName) {
|
|
|
|
text = firstName || title || '';
|
|
|
|
} else {
|
|
|
|
text = title || '';
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
return (
|
2021-05-28 16:15:17 +00:00
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
getClassName(''),
|
|
|
|
contactNameColor ? getClassName(`--${contactNameColor}`) : null
|
|
|
|
)}
|
|
|
|
dir="auto"
|
|
|
|
>
|
2021-03-03 20:09:58 +00:00
|
|
|
<Emojify text={text} />
|
2020-09-14 19:51:27 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|