feat: change colour rendering

This commit is contained in:
Paul Makles
2022-07-15 16:17:15 +01:00
parent 720de38a1e
commit 27e85d7590
2 changed files with 28 additions and 15 deletions

2
external/lang vendored

View File

@@ -26,7 +26,10 @@ const BotBadge = styled.div`
border-radius: calc(var(--border-radius) / 2); border-radius: calc(var(--border-radius) / 2);
`; `;
type UsernameProps = JSX.HTMLAttributes<HTMLElement> & { type UsernameProps = Omit<
JSX.HTMLAttributes<HTMLElement>,
"children" | "as"
> & {
user?: User; user?: User;
prefixAt?: boolean; prefixAt?: boolean;
masquerade?: API.Masquerade; masquerade?: API.Masquerade;
@@ -35,6 +38,13 @@ type UsernameProps = JSX.HTMLAttributes<HTMLElement> & {
innerRef?: Ref<any>; innerRef?: Ref<any>;
}; };
const Name = styled.span<{ colour?: string | null }>`
background: ${(props) => props.colour ?? "var(--foreground)"};
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
`;
export const Username = observer( export const Username = observer(
({ ({
user, user,
@@ -65,6 +75,11 @@ export const Username = observer(
} }
} }
const role = member.hoistedRole;
if (role) {
color = role[1].colour;
}
if (member.roles && member.roles.length > 0) { if (member.roles && member.roles.length > 0) {
const srv = client.servers.get(member._id.server); const srv = client.servers.get(member._id.server);
if (srv?.roles) { if (srv?.roles) {
@@ -81,14 +96,19 @@ export const Username = observer(
} }
} }
const el = (
<Name {...otherProps} ref={innerRef} colour={color}>
{prefixAt ? "@" : undefined}
{masquerade?.name ?? username ?? (
<Text id="app.main.channel.unknown_user" />
)}
</Name>
);
if (user?.bot) { if (user?.bot) {
return ( return (
<> <>
<span {...otherProps} ref={innerRef} style={{ color }}> {el}
{masquerade?.name ?? username ?? (
<Text id="app.main.channel.unknown_user" />
)}
</span>
<BotBadge> <BotBadge>
{masquerade ? ( {masquerade ? (
<Text id="app.main.channel.bridge" /> <Text id="app.main.channel.bridge" />
@@ -100,14 +120,7 @@ export const Username = observer(
); );
} }
return ( return el;
<span {...otherProps} ref={innerRef} style={{ color }}>
{prefixAt ? "@" : undefined}
{masquerade?.name ?? username ?? (
<Text id="app.main.channel.unknown_user" />
)}
</span>
);
}, },
); );