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

47 lines
1 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
2021-05-28 16:15:17 +00:00
import classNames from 'classnames';
import { Emojify } from './Emojify';
2021-05-28 16:15:17 +00:00
import { ContactNameColorType } from '../../types/Colors';
import { getClassNamesFor } from '../../util/getClassNamesFor';
export type PropsType = {
2021-05-28 16:15:17 +00:00
contactNameColor?: ContactNameColorType;
2021-03-03 20:09:58 +00:00
firstName?: string;
module?: string;
2021-03-03 20:09:58 +00:00
preferFirstName?: boolean;
title: string;
};
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);
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>
);
};