Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Thread Accessories #150

Merged
merged 1 commit into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,55 @@ export namespace Components {
*/
"width": number;
}
interface DiscordThread {
/**
* The the text within the call to action text. (i.e. 'See Thread' or 'x Messages')
*/
"cta": string;
/**
* The name of the thread.
*/
"name": string;
}
interface DiscordThreadMessage {
/**
* The message author's username.
* @default 'User'
*/
"author": string;
/**
* The message author's avatar. Can be an avatar shortcut, relative path, or external link.
*/
"avatar": string;
/**
* Whether the message author is a bot or not. Only works if `server` is `false` or `undefined`.
*/
"bot": boolean;
/**
* Whether the message has been edited or not.
*/
"edited": boolean;
/**
* The id of the profile data to use.
*/
"profile": string;
/**
* The relative timestamp of the message.
*/
"relativeTimestamp": string;
/**
* The message author's primary role color. Can be any [CSS color value](https://www.w3schools.com/cssref/css_colors_legal.asp).
*/
"roleColor": string;
/**
* Whether the message author is a server crosspost webhook or not. Only works if `bot` is `false` or `undefined`.
*/
"server": boolean;
/**
* Whether the bot is verified or not. Only works if `bot` is `true`
*/
"verified": boolean;
}
}
declare global {
interface HTMLDiscordActionRowElement extends Components.DiscordActionRow, HTMLStencilElement {
Expand Down Expand Up @@ -466,6 +515,18 @@ declare global {
prototype: HTMLDiscordTenorVideoElement;
new (): HTMLDiscordTenorVideoElement;
};
interface HTMLDiscordThreadElement extends Components.DiscordThread, HTMLStencilElement {
}
var HTMLDiscordThreadElement: {
prototype: HTMLDiscordThreadElement;
new (): HTMLDiscordThreadElement;
};
interface HTMLDiscordThreadMessageElement extends Components.DiscordThreadMessage, HTMLStencilElement {
}
var HTMLDiscordThreadMessageElement: {
prototype: HTMLDiscordThreadMessageElement;
new (): HTMLDiscordThreadMessageElement;
};
interface HTMLElementTagNameMap {
"discord-action-row": HTMLDiscordActionRowElement;
"discord-attachment": HTMLDiscordAttachmentElement;
Expand All @@ -484,6 +545,8 @@ declare global {
"discord-reply": HTMLDiscordReplyElement;
"discord-system-message": HTMLDiscordSystemMessageElement;
"discord-tenor-video": HTMLDiscordTenorVideoElement;
"discord-thread": HTMLDiscordThreadElement;
"discord-thread-message": HTMLDiscordThreadMessageElement;
}
}
declare namespace LocalJSX {
Expand Down Expand Up @@ -842,6 +905,55 @@ declare namespace LocalJSX {
*/
"width"?: number;
}
interface DiscordThread {
/**
* The the text within the call to action text. (i.e. 'See Thread' or 'x Messages')
*/
"cta"?: string;
/**
* The name of the thread.
*/
"name"?: string;
}
interface DiscordThreadMessage {
/**
* The message author's username.
* @default 'User'
*/
"author"?: string;
/**
* The message author's avatar. Can be an avatar shortcut, relative path, or external link.
*/
"avatar"?: string;
/**
* Whether the message author is a bot or not. Only works if `server` is `false` or `undefined`.
*/
"bot"?: boolean;
/**
* Whether the message has been edited or not.
*/
"edited"?: boolean;
/**
* The id of the profile data to use.
*/
"profile"?: string;
/**
* The relative timestamp of the message.
*/
"relativeTimestamp"?: string;
/**
* The message author's primary role color. Can be any [CSS color value](https://www.w3schools.com/cssref/css_colors_legal.asp).
*/
"roleColor"?: string;
/**
* Whether the message author is a server crosspost webhook or not. Only works if `bot` is `false` or `undefined`.
*/
"server"?: boolean;
/**
* Whether the bot is verified or not. Only works if `bot` is `true`
*/
"verified"?: boolean;
}
interface IntrinsicElements {
"discord-action-row": DiscordActionRow;
"discord-attachment": DiscordAttachment;
Expand All @@ -860,6 +972,8 @@ declare namespace LocalJSX {
"discord-reply": DiscordReply;
"discord-system-message": DiscordSystemMessage;
"discord-tenor-video": DiscordTenorVideo;
"discord-thread": DiscordThread;
"discord-thread-message": DiscordThreadMessage;
}
}
export { LocalJSX as JSX };
Expand All @@ -883,6 +997,8 @@ declare module "@stencil/core" {
"discord-reply": LocalJSX.DiscordReply & JSXBase.HTMLAttributes<HTMLDiscordReplyElement>;
"discord-system-message": LocalJSX.DiscordSystemMessage & JSXBase.HTMLAttributes<HTMLDiscordSystemMessageElement>;
"discord-tenor-video": LocalJSX.DiscordTenorVideo & JSXBase.HTMLAttributes<HTMLDiscordTenorVideoElement>;
"discord-thread": LocalJSX.DiscordThread & JSXBase.HTMLAttributes<HTMLDiscordThreadElement>;
"discord-thread-message": LocalJSX.DiscordThreadMessage & JSXBase.HTMLAttributes<HTMLDiscordThreadMessageElement>;
}
}
}
6 changes: 1 addition & 5 deletions packages/core/src/components/author-info/author-info.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

.discord-message .discord-author-info .discord-application-tag {
background-color: hsl(235, 85.6%, 64.7%);
background-color: #5865f2;
color: #fff;
font-size: 0.65em;
margin-left: 5px;
Expand All @@ -40,10 +40,6 @@
margin-left: -0.25rem;
}

.discord-light-theme .discord-message .discord-author-info .discord-application-tag {
color: #fff;
}

.discord-compact-mode .discord-message .discord-author-info .discord-author-username {
margin-left: 8px;
margin-right: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
margin-right: 16px;
margin-top: 5px;
min-width: 40px;
z-index: 1;
}

.discord-message .discord-author-avatar img {
Expand Down Expand Up @@ -191,4 +192,20 @@
background-color: rgba(6, 6, 7, 0.02);
}

.discord-message.discord-message-has-thread:after {
width: 2rem;
left: 2.2rem;
top: 1.75rem;
border-left: 2px solid #4f545c;
border-bottom: 2px solid #4f545c;
border-bottom-left-radius: 8px;
bottom: 29px;
content: '';
position: absolute;
}

.discord-light-theme .discord-message.discord-message-has-thread:after {
border-color: #747f8d;
}

@import '../author-info/author-info.css';
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ export class DiscordMessage implements ComponentInterface {
return child.tagName.toLowerCase() === 'discord-mention' && child.highlight && ['user', 'role'].includes(child.type);
}) || this.highlight;

const hasThread: boolean =
// @ts-expect-error ts doesn't understand this
Array.from(this.el.children).some((child: HTMLDiscordThreadElement): boolean => {
return child.tagName.toLowerCase() === 'discord-thread';
});

return (
<Host class={clsx('discord-message', { 'discord-highlight-mention': highlightMention })}>
<Host class={clsx('discord-message', { 'discord-highlight-mention': highlightMention, 'discord-message-has-thread': hasThread })}>
<slot name="reply"></slot>
<div class="discord-message-inner">
{parent.compactMode && <span class="discord-message-timestamp">{this.timestamp}</span>}
Expand Down Expand Up @@ -159,6 +165,7 @@ export class DiscordMessage implements ComponentInterface {
<slot name="attachments"></slot>
<slot name="components"></slot>
<slot name="reactions"></slot>
<slot name="thread"></slot>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,20 @@
background-color: rgba(6, 6, 7, 0.02);
}

.discord-system-message.discord-system-message-has-thread:after {
width: 2rem;
left: 2.2rem;
top: 1.75rem;
border-left: 2px solid #4f545c;
border-bottom: 2px solid #4f545c;
border-bottom-left-radius: 8px;
bottom: 29px;
content: '';
position: absolute;
}

.discord-light-theme .discord-system-message.discord-system-message-has-thread:after {
border-color: #747f8d;
}

@import '../author-info/author-info.css';
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,27 @@ export class DiscordSystemMessage implements ComponentInterface {
break;
}

const hasThread: boolean =
// @ts-expect-error ts doesn't understand this
Array.from(this.el.children).some((child: HTMLDiscordThreadElement): boolean => {
return child.tagName.toLowerCase() === 'discord-thread';
});

return (
<Host class={clsx('discord-system-message', `discord-${this.type}-system-message`, { 'discord-channel-name-change': this.channelName })}>
<Host
class={clsx('discord-system-message', `discord-${this.type}-system-message`, {
'discord-system-message-has-thread': hasThread,
'discord-channel-name-change': this.channelName
})}
>
<div class="discord-message-icon">{icon}</div>
<div class="discord-message-content">
<span>
<slot></slot>
<span class="discord-message-timestamp">{this.timestamp}</span>
</span>
<slot name="reactions"></slot>
<slot name="thread"></slot>
</div>
</Host>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
.discord-thread-message {
height: 18px;
min-width: 0;
display: flex;
align-items: center;
font-size: 0.875rem;
line-height: 1.125rem;
}

.discord-thread-message .discord-thread-message-avatar {
margin-right: 8px;
flex: 0 0 auto;
width: 16px;
height: 16px;
border-radius: 50%;
user-select: none;
}

.discord-thread-message .discord-thread-message-username {
flex-shrink: 0;
font-size: inherit;
line-height: inherit;
margin-right: 0.25rem;
opacity: 0.64;
color: white;
display: inline;
vertical-align: baseline;
position: relative;
overflow: hidden;
}

.discord-light-theme .discord-thread-message .discord-thread-message-username {
color: #060607;
}

.discord-thread-message .discord-application-tag {
background-color: #5865f2;
color: #fff;
font-size: 0.65em;
margin-right: 5px;
border-radius: 3px;
line-height: 100%;
text-transform: uppercase;
display: flex;
align-items: center;
height: 0.9375rem;
padding: 0 0.275rem;
margin-top: 0.075em;
border-radius: 0.1875rem;
}

.discord-thread-message .discord-application-tag-verified {
display: inline-block;
width: 0.9375rem;
height: 0.9375rem;
margin-left: -0.25rem;
}

.discord-thread-message .discord-thread-message-content {
display: flex;
align-items: baseline;
}

.discord-thread-message .discord-message-edited {
color: #72767d;
font-size: 10px;
margin-left: 5px;
}

.discord-thread-message .discord-thread-message-timestamp {
color: #72767d;
flex-shrink: 0;
margin-left: 8px;
font-size: 0.875rem;
line-height: 1.125rem;
}

.discord-light-theme .discord-thread-message .discord-thread-message-timestamp,
.discord-light-theme .discord-thread-message .discord-message-edited {
color: #747f8d;
}
Loading