Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: added option to add the channel name above discord messages #520

Merged
merged 5 commits into from
Jan 4, 2025
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
2 changes: 1 addition & 1 deletion packages/core/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2>Explanation</h2>

<main id="demo">
<h3 class="title">A normal conversation</h3>
<discord-messages>
<discord-messages channel-name="General" channel-type="text">
<discord-message author="Alyx Vargas"> Hey guys, I'm new here! Glad to be able to join you all! </discord-message>
<discord-message
author="Fenton Smart"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { createContext, provide } from '@lit/context';
import { css, html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { when } from 'lit/directives/when.js';
import { defaultBackground, defaultMode, defaultTheme } from '../../config.js';
import type { LightTheme } from '../../types.js';
import ChannelForum from '../svgs/ChannelForum.js';
import ChannelIcon from '../svgs/ChannelIcon.js';
import ChannelThread from '../svgs/ChannelThread.js';
import LockedVoiceChannel from '../svgs/LockedVoiceChannel.js';
import VoiceChannel from '../svgs/VoiceChannel.js';

export const messagesLightTheme = createContext<boolean>('light-theme');
export const messagesCompactMode = createContext<boolean>('compact-mode');
Expand Down Expand Up @@ -55,6 +61,35 @@ export class DiscordMessages extends LitElement implements LightTheme {
margin-bottom: 0.5rem;
border-bottom-width: 0;
}

:host .discord-channel-header {
display: flex;
align-items: center;
padding: 0.5rem 1rem;
box-shadow:
0 2px 0 0 rgba(0, 0, 0, 0.05),
0 1.5px 0 0 rgba(0, 0, 0, 0.05),
0 1px 0 0 rgba(0, 0, 0, 0.16);
}

:host .discord-channel-icon {
height: 24px;
width: auto;
margin: 0 8px;
position: relative;
flex: 0 0 auto;
color: #80848e;
}

:host([light-theme]) .discord-channel-icon {
color: #6d6f78;
}

:host .discord-channel-name {
margin: 0 8px 0 0;
flex: 0 0 auto;
min-width: auto;
}
`;

/**
Expand All @@ -78,6 +113,20 @@ export class DiscordMessages extends LitElement implements LightTheme {
@property({ type: Boolean, reflect: true, attribute: 'compact-mode' })
public accessor compactMode = false;

/**
* The type of channel this should be, this will be displayed above the message and only applies if {@link DiscordMessages.channelName} is set.
* Valid values are: `text`, `forum`, `locked`, `thread`, and `voice`.
*/
@property({ reflect: true, attribute: 'channel-type' })
public accessor channelType: 'forum' | 'locked' | 'text' | 'thread' | 'voice';

/**
* The name of the channel, this will be displayed above the message and only applies if {@link DiscordMessages.channelType} is set.
*/

@property({ reflect: true, attribute: 'channel-name' })
public accessor channelName: string;

public override connectedCallback(): void {
super.connectedCallback();

Expand All @@ -95,7 +144,36 @@ export class DiscordMessages extends LitElement implements LightTheme {
}

protected override render() {
return html`<slot></slot>`;
let channelIcon: ReturnType<typeof html>;
switch (this.channelType) {
case 'text':
channelIcon = html`${ChannelIcon()}`;
break;
case 'voice':
channelIcon = html`${VoiceChannel()}`;
break;
case 'locked':
channelIcon = html`${LockedVoiceChannel()}`;
break;
case 'thread':
channelIcon = html`${ChannelThread()}`;
break;
case 'forum':
channelIcon = html`${ChannelForum()}`;
break;
}

return html`
${when(
this.channelType && this.channelName,
() =>
html`<div class="discord-channel-header">
<div class="discord-channel-icon">${channelIcon}</div>
<div class="discord-channel-name">${this.channelName}</div>
</div>`
)}
<slot></slot>
`;
}
}

Expand Down
Loading