soapbox/app/soapbox/components/display-name.tsx

50 wiersze
1.3 KiB
TypeScript
Czysty Zwykły widok Historia

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