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

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08:00
// Copyright 2018 Signal Messenger, LLC
2020-10-30 15:34:04 -05:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
2021-05-28 12:15:17 -04:00
import classNames from 'classnames';
import { Emojify } from './Emojify';
import type { ContactNameColorType } from '../../types/Colors';
2021-05-28 12:15:17 -04:00
import { getClassNamesFor } from '../../util/getClassNamesFor';
export type PropsType = {
2021-05-28 12:15:17 -04:00
contactNameColor?: ContactNameColorType;
2021-03-03 14:09:58 -06:00
firstName?: string;
2022-11-08 21:38:19 -05:00
isSignalConversation?: boolean;
2023-03-02 07:57:35 +01:00
isMe?: boolean;
module?: string;
2021-03-03 14:09:58 -06:00
preferFirstName?: boolean;
title: string;
};
2022-11-17 16:45:19 -08:00
export function ContactName({
2021-05-28 12:15:17 -04:00
contactNameColor,
2021-03-03 14:09:58 -06:00
firstName,
2022-11-08 21:38:19 -05:00
isSignalConversation,
2023-03-02 07:57:35 +01:00
isMe,
2021-03-03 14:09:58 -06:00
module,
preferFirstName,
title,
2022-11-17 16:45:19 -08:00
}: PropsType): JSX.Element {
2021-05-28 12:15:17 -04:00
const getClassName = getClassNamesFor('module-contact-name', module);
2021-03-03 14:09:58 -06:00
let text: string;
if (preferFirstName) {
text = firstName || title || '';
} else {
text = title || '';
}
2020-09-14 12:51:27 -07:00
return (
2021-05-28 12:15:17 -04:00
<span
className={classNames(
getClassName(''),
contactNameColor ? getClassName(`--${contactNameColor}`) : null
)}
dir="auto"
>
2021-03-03 14:09:58 -06:00
<Emojify text={text} />
2023-03-02 07:57:35 +01:00
{(isSignalConversation || isMe) && (
<span className="ContactModal__official-badge" />
2022-11-08 21:38:19 -05:00
)}
2020-09-14 12:51:27 -07:00
</span>
);
2022-11-17 16:45:19 -08:00
}