2022-11-25 09:04:11 -08:00
|
|
|
import React from 'react';
|
2022-05-13 09:12:19 -07:00
|
|
|
|
2022-11-15 12:46:23 -08:00
|
|
|
import HoverRefWrapper from 'soapbox/components/hover-ref-wrapper';
|
2022-05-13 09:12:19 -07:00
|
|
|
import { useSoapboxConfig } from 'soapbox/hooks';
|
|
|
|
|
|
|
|
import { getAcct } from '../utils/accounts';
|
|
|
|
|
2022-11-25 09:04:11 -08:00
|
|
|
import { HStack, Text } from './ui';
|
2022-11-15 08:00:49 -08:00
|
|
|
import VerificationBadge from './verification-badge';
|
2022-05-13 09:12:19 -07:00
|
|
|
|
2023-06-20 12:24:39 -07:00
|
|
|
import type { Account } from 'soapbox/schemas';
|
2022-05-13 09:12:19 -07:00
|
|
|
|
|
|
|
interface IDisplayName {
|
2023-06-20 12:24:39 -07:00
|
|
|
account: Pick<Account, 'id' | 'acct' | 'fqn' | 'verified' | 'display_name_html'>
|
2022-11-25 09:04:11 -08:00
|
|
|
withSuffix?: boolean
|
2023-01-10 15:03:15 -08:00
|
|
|
children?: React.ReactNode
|
2022-05-13 09:12:19 -07:00
|
|
|
}
|
|
|
|
|
2023-01-09 12:46:59 -08:00
|
|
|
const DisplayName: React.FC<IDisplayName> = ({ account, children, withSuffix = true }) => {
|
2022-05-13 09:12:19 -07:00
|
|
|
const { displayFqn = false } = useSoapboxConfig();
|
2023-01-09 12:46:59 -08:00
|
|
|
const { verified } = account;
|
2022-05-13 09:12:19 -07:00
|
|
|
|
|
|
|
const displayName = (
|
2022-11-25 09:04:11 -08:00
|
|
|
<HStack space={1} alignItems='center' grow>
|
|
|
|
<Text
|
|
|
|
size='sm'
|
|
|
|
weight='semibold'
|
|
|
|
truncate
|
|
|
|
dangerouslySetInnerHTML={{ __html: account.display_name_html }}
|
|
|
|
/>
|
|
|
|
|
2022-05-13 09:12:19 -07:00
|
|
|
{verified && <VerificationBadge />}
|
2022-11-25 09:04:11 -08:00
|
|
|
</HStack>
|
2022-05-13 09:12:19 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
const suffix = (<span className='display-name__account'>@{getAcct(account, displayFqn)}</span>);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className='display-name' data-testid='display-name'>
|
2023-06-20 12:24:39 -07:00
|
|
|
<HoverRefWrapper accountId={account.id} inline>
|
2022-05-13 09:12:19 -07:00
|
|
|
{displayName}
|
|
|
|
</HoverRefWrapper>
|
2022-11-25 09:04:11 -08:00
|
|
|
{withSuffix && suffix}
|
2022-05-13 09:12:19 -07:00
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DisplayName;
|