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

enhancement/issue 63 social tray component #163

Merged
merged 5 commits into from
Jan 30, 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
23 changes: 2 additions & 21 deletions src/components/footer/footer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import discordIcon from "../../assets/discord.svg?type=raw";
import githubIcon from "../../assets/github.svg?type=raw";
import twitterIcon from "../../assets/twitter-logo.svg?type=raw";
import styles from "./footer.module.css";
import greenwoodLogo from "../../assets/greenwood-logo-full.svg?type=raw";
import "../social-tray/social-tray.js";

export default class Footer extends HTMLElement {
connectedCallback() {
Expand All @@ -11,25 +9,8 @@ export default class Footer extends HTMLElement {
<div class="${styles.logo}">
${greenwoodLogo}
</div>
<ul class="${styles.socialTray}">
<li class="${styles.socialIcon}">
<a href="https://github.com/ProjectEvergreen/greenwood" title="GitHub">
${githubIcon}
</a>
</li>

<li class="${styles.socialIcon}">
<a href="/discord/" title="Discord">
${discordIcon}
</a>
</li>

<li class="${styles.socialIcon}">
<a href="https://twitter.com/PrjEvergreen" title="Twitter">
${twitterIcon}
</a>
</li>
</ul>
<app-social-tray></app-social-tray>
</footer>
`;
}
Expand Down
24 changes: 8 additions & 16 deletions src/components/footer/footer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@
fill: var(--color-white);
}

.socialTray {
display: flex;
gap: var(--size-2);
list-style-type: none;
background-color: var(--color-secondary);
.footer app-social-tray {
border: var(--border-size-1) solid var(--color-black);
border-radius: var(--radius-6);
padding: var(--size-2) var(--size-3);
align-items: center;
justify-content: center;
cursor: pointer;
}
padding: var(--size-2);

.socialIcon {
display: flex;
align-items: center;
}
& ul {
background-color: var(--color-secondary);
}

.socialIcon svg {
fill: var(--color-gray);
& svg {
fill: var(--color-white);
}
}
31 changes: 4 additions & 27 deletions src/components/footer/footer.spec.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import { expect } from "@esm-bundle/chai";
import "./footer.js";

const ICONS = [
{
link: "https://github.com/ProjectEvergreen/greenwood",
title: "GitHub",
},
{
link: "/discord/",
title: "Discord",
},
{
link: "https://twitter.com/PrjEvergreen",
title: "Twitter",
},
];

describe("Components/Footer", () => {
let footer;

Expand All @@ -39,21 +24,13 @@ describe("Components/Footer", () => {
expect(logo[0]).not.equal(undefined);
});

it("should have the expected social link icons", () => {
const links = footer.querySelectorAll("ul li a");
const icons = footer.querySelectorAll("ul li a svg");

expect(links.length).to.equal(3);
expect(icons.length).to.equal(3);
it("should have the social tray component", () => {
const tray = footer.querySelectorAll("app-social-tray");

Array.from(links).forEach((link) => {
const iconItem = ICONS.find((icon) => icon.title === link.getAttribute("title"));

expect(iconItem).to.not.equal(undefined);
expect(link.getAttribute("href")).to.equal(iconItem.link);
});
expect(tray.length).to.equal(1);
});
});

after(() => {
footer.remove();
footer = null;
Expand Down
24 changes: 2 additions & 22 deletions src/components/header/header.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { getContentByCollection } from "@greenwood/cli/src/data/client.js";
import discordIcon from "../../assets/discord.svg?type=raw";
import githubIcon from "../../assets/github.svg?type=raw";
import twitterIcon from "../../assets/twitter-logo.svg?type=raw";
import mobileMenuIcon from "../../assets/tile.svg?type=raw";
import greenwoodLogo from "../../assets/greenwood-logo-full.svg?type=raw";
import styles from "./header.module.css";
import "../social-tray/social-tray.js";

export default class Header extends HTMLElement {
async connectedCallback() {
Expand Down Expand Up @@ -38,25 +36,7 @@ export default class Header extends HTMLElement {
</nav>

<nav role="navigation" aria-label="Social">
<ul class="${styles.socialTray}">
<li class="${styles.socialIcon}">
<a href="https://github.com/ProjectEvergreen/greenwood" title="GitHub">
${githubIcon}
</a>
</li>

<li class="${styles.socialIcon}">
<a href="/discord/" title="Discord">
${discordIcon}
</a>
</li>

<li class="${styles.socialIcon}">
<a href="https://twitter.com/PrjEvergreen" title="Twitter">
${twitterIcon}
</a>
</li>
</ul>
<app-social-tray></app-social-tray>
</nav>

<button class="${styles.mobileMenuIcon}" popovertarget="mobile-menu" aria-label="Mobile Menu Icon Button">
Expand Down
28 changes: 0 additions & 28 deletions src/components/header/header.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,6 @@
text-decoration: underline;
}

.socialTray {
display: flex;
gap: var(--size-3);
list-style-type: none;
background-color: var(--color-gray);
width: fit-content;
border: var(--border-size-1) solid #4d4d4d45;
border-radius: var(--radius-6);
padding: 0 var(--size-1);
align-items: center;
justify-content: center;
cursor: pointer;
}

.socialIcon {
display: flex;
align-items: center;
line-height: 100%;
}

.socialIcon svg {
fill: var(--color-secondary);
}

.mobileMenuIcon {
display: none;
border: none;
Expand Down Expand Up @@ -155,10 +131,6 @@
align-self: center;
}

.socialTray {
padding: 0 var(--size-2);
}

.logoLink svg.greenwood-logo-full {
width: 70%;
}
Expand Down
29 changes: 3 additions & 26 deletions src/components/header/header.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ import "./header.js";
import pages from "../../stories/mocks/graph.json" with { type: "json" };

const CURRENT_ROUTE = "/guides/";
const ICONS = [
{
link: "https://github.com/ProjectEvergreen/greenwood",
title: "GitHub",
},
{
link: "/discord/",
title: "Discord",
},
{
link: "https://twitter.com/PrjEvergreen",
title: "Twitter",
},
];

window.fetch = function () {
return new Promise((resolve) => {
Expand Down Expand Up @@ -77,19 +63,10 @@ describe("Components/Header", () => {
expect(activeRoute.route).to.equal(CURRENT_ROUTE);
});

it("should have the expected social link icons", () => {
const links = header.querySelectorAll("nav[aria-label='Social'] ul li a");
const icons = header.querySelectorAll("nav[aria-label='Social'] ul li a svg");
it("should have the social tray component", () => {
const tray = header.querySelectorAll("app-social-tray");

expect(links.length).to.equal(3);
expect(icons.length).to.equal(3);

Array.from(links).forEach((link) => {
const iconItem = ICONS.find((icon) => icon.title === link.getAttribute("title"));

expect(iconItem).to.not.equal(undefined);
expect(link.getAttribute("href")).to.equal(iconItem.link);
});
expect(tray.length).to.equal(1);
});
});

Expand Down
32 changes: 32 additions & 0 deletions src/components/social-tray/social-tray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import styles from "./social-tray.module.css";
import discordIcon from "../../assets/discord.svg?type=raw";
import githubIcon from "../../assets/github.svg?type=raw";
import twitterIcon from "../../assets/twitter-logo.svg?type=raw";

export default class SocialTray extends HTMLElement {
connectedCallback() {
this.innerHTML = `
<ul class="${styles.socialTray}">
<li class="${styles.socialIcon}">
<a href="https://github.com/ProjectEvergreen/greenwood" title="GitHub">
${githubIcon}
</a>
</li>

<li class="${styles.socialIcon}">
<a href="/discord/" title="Discord">
${discordIcon}
</a>
</li>

<li class="${styles.socialIcon}">
<a href="https://twitter.com/PrjEvergreen" title="Twitter">
${twitterIcon}
</a>
</li>
</ul>
`;
}
}

customElements.define("app-social-tray", SocialTray);
29 changes: 29 additions & 0 deletions src/components/social-tray/social-tray.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.socialTray {
display: flex;
gap: var(--size-3);
list-style-type: none;
background-color: var(--color-gray);
width: fit-content;
border: var(--border-size-1) solid #4d4d4d45;
border-radius: var(--radius-6);
padding: 0 var(--size-1);
align-items: center;
justify-content: center;
cursor: pointer;
}

.socialIcon {
display: flex;
align-items: center;
line-height: 100%;
}

.socialIcon svg {
fill: var(--color-secondary);
}

@media screen and (min-width: 768px) {
.socialTray {
padding: 0 var(--size-2);
}
}
56 changes: 56 additions & 0 deletions src/components/social-tray/social-tray.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { expect } from "@esm-bundle/chai";
import "./social-tray.js";

const ICONS = [
{
link: "https://github.com/ProjectEvergreen/greenwood",
title: "GitHub",
},
{
link: "/discord/",
title: "Discord",
},
{
link: "https://twitter.com/PrjEvergreen",
title: "Twitter",
},
];

describe("Components/Social Tray", () => {
let tray;

before(async () => {
tray = document.createElement("app-social-tray");

document.body.appendChild(tray);

await tray.updateComplete;
});

describe("Default Behavior", () => {
it("should not be null", () => {
expect(tray).not.equal(undefined);
expect(tray.querySelectorAll("ul").length).equal(1);
});

it("should have the expected social link icons", () => {
const links = tray.querySelectorAll("ul li a");
const icons = tray.querySelectorAll("ul li a svg");

expect(links.length).to.equal(3);
expect(icons.length).to.equal(3);

Array.from(links).forEach((link) => {
const iconItem = ICONS.find((icon) => icon.title === link.getAttribute("title"));

expect(iconItem).to.not.equal(undefined);
expect(link.getAttribute("href")).to.equal(iconItem.link);
});
});
});

after(() => {
tray.remove();
tray = null;
});
});
9 changes: 9 additions & 0 deletions src/components/social-tray/social-tray.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "./social-tray.js";

export default {
title: "Components/Social Tray",
};

const Template = () => "<app-social-tray></app-social-tray>";

export const Primary = Template.bind({});