mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 00:08:46 +00:00
37 lines
943 B
TypeScript
37 lines
943 B
TypeScript
import { useMemo } from 'react';
|
|
import type { ComponentPropsWithoutRef, FC } from 'react';
|
|
|
|
import { Skeleton } from '../skeleton';
|
|
|
|
import type { DisplayNameProps } from './index';
|
|
import { DisplayNameWithoutDomain } from './no-domain';
|
|
|
|
export const DisplayNameDefault: FC<
|
|
Omit<DisplayNameProps, 'variant'> & ComponentPropsWithoutRef<'span'>
|
|
> = ({ account, localDomain, className, ...props }) => {
|
|
const username = useMemo(() => {
|
|
if (!account) {
|
|
return null;
|
|
}
|
|
let acct = account.get('acct');
|
|
|
|
if (!acct.includes('@') && localDomain) {
|
|
acct = `${acct}@${localDomain}`;
|
|
}
|
|
return `@${acct}`;
|
|
}, [account, localDomain]);
|
|
|
|
return (
|
|
<DisplayNameWithoutDomain
|
|
account={account}
|
|
className={className}
|
|
{...props}
|
|
>
|
|
{' '}
|
|
<span className='display-name__account'>
|
|
{username ?? <Skeleton width='7ch' />}
|
|
</span>
|
|
</DisplayNameWithoutDomain>
|
|
);
|
|
};
|