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

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2018 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';
import type { ContactNameColorType } from '../../types/Colors';
2021-05-28 16:15:17 +00:00
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;
2022-11-09 02:38:19 +00:00
isSignalConversation?: boolean;
2023-03-02 06:57:35 +00:00
isMe?: boolean;
module?: string;
2021-03-03 20:09:58 +00:00
preferFirstName?: boolean;
title: string;
};
2022-11-18 00:45:19 +00:00
export function ContactName({
2021-05-28 16:15:17 +00:00
contactNameColor,
2021-03-03 20:09:58 +00:00
firstName,
2022-11-09 02:38:19 +00:00
isSignalConversation,
2023-03-02 06:57:35 +00:00
isMe,
2021-03-03 20:09:58 +00:00
module,
preferFirstName,
title,
2022-11-18 00:45:19 +00:00
}: 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} />
2023-03-02 06:57:35 +00:00
{(isSignalConversation || isMe) && (
<span className="ContactModal__official-badge" />
2022-11-09 02:38:19 +00:00
)}
2020-09-14 19:51:27 +00:00
</span>
);
2022-11-18 00:45:19 +00:00
}