mirror of
https://github.com/mastodon/mastodon.git
synced 2025-10-05 16:42:47 +00:00
add LinkedDisplayName component
This commit is contained in:
parent
7f87bd9195
commit
2633692a3d
|
@ -4,7 +4,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
|
||||||
import { accountFactoryState } from '@/testing/factories';
|
import { accountFactoryState } from '@/testing/factories';
|
||||||
|
|
||||||
import { DisplayName } from '.';
|
import { DisplayName, LinkedDisplayName } from '.';
|
||||||
|
|
||||||
type PageProps = Omit<ComponentProps<typeof DisplayName>, 'account'> & {
|
type PageProps = Omit<ComponentProps<typeof DisplayName>, 'account'> & {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -67,3 +67,15 @@ export const LocalUser: Story = {
|
||||||
localDomain: '',
|
localDomain: '',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const Linked: Story = {
|
||||||
|
render({ name, username, loading, ...args }) {
|
||||||
|
const account = !loading
|
||||||
|
? accountFactoryState({
|
||||||
|
display_name: name,
|
||||||
|
acct: username,
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
return <LinkedDisplayName {...args} account={account} />;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import type { ComponentPropsWithoutRef, FC } from 'react';
|
import type { ComponentPropsWithoutRef, FC } from 'react';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
|
import type { LinkProps } from 'react-router-dom';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { EmojiHTML } from '@/mastodon/features/emoji/emoji_html';
|
import { EmojiHTML } from '@/mastodon/features/emoji/emoji_html';
|
||||||
import type { Account } from '@/mastodon/models/account';
|
import type { Account } from '@/mastodon/models/account';
|
||||||
import { isModernEmojiEnabled } from '@/mastodon/utils/environment';
|
import { isModernEmojiEnabled } from '@/mastodon/utils/environment';
|
||||||
|
@ -52,31 +55,24 @@ export const DisplayName: FC<Props & ComponentPropsWithoutRef<'span'>> = ({
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const accountName = isModernEmojiEnabled()
|
||||||
|
? account.get('display_name')
|
||||||
|
: account.get('display_name_html');
|
||||||
if (simple) {
|
if (simple) {
|
||||||
return (
|
return (
|
||||||
<EmojiHTML
|
<bdi>
|
||||||
{...props}
|
<EmojiHTML {...props} htmlString={accountName} shallow as='span' />
|
||||||
htmlString={
|
</bdi>
|
||||||
isModernEmojiEnabled()
|
|
||||||
? account.get('display_name')
|
|
||||||
: account.get('display_name_html')
|
|
||||||
}
|
|
||||||
shallow
|
|
||||||
as='span'
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span {...props} className={`display-name ${className}`}>
|
<span {...props} className={`display-name ${className}`}>
|
||||||
<bdi>
|
<bdi>
|
||||||
<EmojiHTML
|
<EmojiHTML
|
||||||
{...props}
|
{...props}
|
||||||
className={`display-name__html ${className}`}
|
className={`display-name__html ${className}`}
|
||||||
htmlString={
|
htmlString={accountName}
|
||||||
isModernEmojiEnabled()
|
|
||||||
? account.get('display_name')
|
|
||||||
: account.get('display_name_html')
|
|
||||||
}
|
|
||||||
shallow
|
shallow
|
||||||
as='strong'
|
as='strong'
|
||||||
/>
|
/>
|
||||||
|
@ -85,3 +81,38 @@ export const DisplayName: FC<Props & ComponentPropsWithoutRef<'span'>> = ({
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const LinkedDisplayName: FC<
|
||||||
|
Props & { asProps?: ComponentPropsWithoutRef<'span'> } & Partial<LinkProps>
|
||||||
|
> = ({
|
||||||
|
account,
|
||||||
|
asProps = {},
|
||||||
|
className,
|
||||||
|
localDomain,
|
||||||
|
simple,
|
||||||
|
noDomain,
|
||||||
|
...linkProps
|
||||||
|
}) => {
|
||||||
|
const displayProps = {
|
||||||
|
account,
|
||||||
|
className,
|
||||||
|
localDomain,
|
||||||
|
simple,
|
||||||
|
noDomain,
|
||||||
|
...asProps,
|
||||||
|
};
|
||||||
|
if (!account) {
|
||||||
|
return <DisplayName {...displayProps} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
to={`/@${account.acct}`}
|
||||||
|
title={`@${account.acct}`}
|
||||||
|
data-hover-card-account={account.id}
|
||||||
|
{...linkProps}
|
||||||
|
>
|
||||||
|
<DisplayName {...displayProps} />
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user