Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from sveenxx/develop
Browse files Browse the repository at this point in the history
Build 1.2.0
  • Loading branch information
sveenxx committed Aug 30, 2021
2 parents 5116da7 + b9c5cd7 commit c0b99ba
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 25 deletions.
3 changes: 2 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
(async function () {
const discord = await DiscordWidget.init(
document.querySelector("#discord"),
"600381707073486871"
"600381707073486871",
{ connectButton: false }
);
})()
</script>
Expand Down
2 changes: 1 addition & 1 deletion dist/discord-widget.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/interfaces/widget.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export declare type WidgetOptions = {
connectButton: boolean;
styles: Record<string, unknown>;
connectButton?: boolean;
styles?: Record<string, unknown>;
};
export declare type Guild = {
id: string;
Expand Down
8 changes: 8 additions & 0 deletions dist/options.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { WidgetOptions } from "./interfaces/";
export declare class Options {
/**
*
*/
connectButton: boolean;
constructor(options?: Partial<WidgetOptions>);
}
3 changes: 2 additions & 1 deletion dist/templates/widget.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export declare const getWidget: (guild: any) => any;
import { WidgetOptions, Guild } from "../interfaces/";
export declare const getWidget: (guild: Guild, options: WidgetOptions) => string;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-widget",
"version": "1.2.0",
"version": "1.2.1",
"description": "♻️ Customize discord widget for your website",
"main": "dist/discord-widget.js",
"jsnext:main": "dist/discord-widget.js",
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/widget.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type WidgetOptions = {
connectButton: boolean;
styles: Record<string, unknown>;
connectButton?: boolean;
styles?: Record<string, unknown>;
};

export type Guild = {
Expand Down
14 changes: 14 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { WidgetOptions } from "./interfaces/";

export class Options {
/**
*
*/
connectButton = true;

constructor(options: Partial<WidgetOptions> = {}) {
Object.keys(options).forEach((prop) => {
this[prop] = options[prop];
});
}
}
5 changes: 3 additions & 2 deletions src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ const WIDGET_STYLE = `
}
.widget-footer {
min-height: 30px;
height: 42px;
box-sizing: border-box;
background-color: #202225;
padding: 6px 6px 6px 20px;
-webkit-box-shadow: 0 -1px 18px rgb(0 0 0 / 20%), 0 -1px 0 rgb(0 0 0 / 20%);
Expand All @@ -106,7 +107,7 @@ const WIDGET_STYLE = `
}
.widget-join-button {
color: #fff;
color: #fff!important;
text-decoration: none;
border: 1px solid #212325;
border-radius: 4px;
Expand Down
19 changes: 12 additions & 7 deletions src/templates/widget.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { template } from "../template";
import { getMemeberList } from "./widgetMemberList";
import { WidgetOptions, Guild } from "../interfaces/";

export const getWidget = (guild) =>
template(guild, (data) =>
`
export const getWidget = (guild: Guild, options: WidgetOptions): string =>
template(
guild,
(data) =>
`
<div class="widget-header">
<a class="widget-logo" href="http://discord.com" target="_blank"></a>
<span class="widget-status"><strong>${
Expand All @@ -26,9 +29,11 @@ export const getWidget = (guild) =>
</div>
<div class="widget-footer">
<span class="widget-footer-text">Free voice chat from Discord</span>
<a class="widget-join-button" href="${
data.instant_invite
}" target="_blank">Connect</a>
${
!options.connectButton
? ``
: `<a class="widget-join-button" href="${data.instant_invite}" target="_blank">Connect</a>`
}
</div>
`.replaceAll(",", "")
`
);
10 changes: 6 additions & 4 deletions src/templates/widgetMemberList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { template } from "../template";

export const getMemeberList = (guild) =>
template(guild, (data) =>
data.members.map(
(member) =>
`
data.members
.map(
(member) =>
`
<div class="widget-member">
<div>
<div class="widget-member-avatar">
Expand All @@ -23,5 +24,6 @@ export const getMemeberList = (guild) =>
}
</div>
`
)
)
.join("")
);
7 changes: 3 additions & 4 deletions src/widget.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as I from "./interfaces/";
import { WidgetOptions, Guild } from "./interfaces/";
import { getWidget } from "./templates";
import { Options } from "./options";

export class Widget implements I.Widget {
/**
Expand All @@ -24,7 +25,7 @@ export class Widget implements I.Widget {
options?: WidgetOptions | undefined
) {
this.element = element;
this.options = options;
this.options = new Options(options);
this.guild = guild;

/**
Expand All @@ -36,14 +37,12 @@ export class Widget implements I.Widget {
* Mark as discord widget
*/
contentElement.setAttribute("data-discord-widget", "true");

contentElement.className = "discord-widget";

/**
* Create template
*/

contentElement.innerHTML = getWidget(this.guild);
contentElement.innerHTML = getWidget(this.guild, this.options);

this.element.appendChild(contentElement);
}
Expand Down

0 comments on commit c0b99ba

Please sign in to comment.