Skip to content

Commit

Permalink
added sidebar contact
Browse files Browse the repository at this point in the history
  • Loading branch information
eKrausedivae committed Feb 6, 2024
1 parent 122046e commit b920dee
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 6 deletions.
8 changes: 4 additions & 4 deletions dist/main/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/styles/styles.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/components/sidebar/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { customElement, query } from 'lit/decorators.js';
import { debounce } from '@kluntje/js-utils/lib/function-helpers/decorators';

import './sidebarNav.ts';
import './sidebarContact.ts';
import './sidebarFooter.ts';

@customElement('sidebar-component')
Expand Down Expand Up @@ -38,6 +39,7 @@ export class SidebarComponent extends LitElement {
return html`
<div class="inner">
<sidebar-nav></sidebar-nav>
<sidebar-contact></sidebar-contact>
<sidebar-footer id="footer"></sidebar-footer>
</div>
<a href="#sidebar" class="toggle hamburger-icon"><icon-component name="hamburger"></icon-component></a>
Expand Down
65 changes: 65 additions & 0 deletions src/components/sidebar/sidebarContact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { LitElement, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { fetchData } from '../../utils/fetchData';
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';

interface SidebarContactTemplateArgs {
headline: HTMLHeadingElement;
text: HTMLParagraphElement;
contacts: Contact[];
}

interface Contact {
contactIcon: string;
contactMarkup: string;
}

@customElement('sidebar-contact')
export class SidebarContact extends LitElement {
@state()
contactTemplateArgs: SidebarContactTemplateArgs;

protected createRenderRoot(): HTMLElement | DocumentFragment {
return this;
}

connectedCallback(): void {
super.connectedCallback();
this.fetchContactData();
}

async fetchContactData() {
const response = await fetchData<string>({ endpoint: 'contact.plain.html' });
const responseMarkup = document.createElement('div');
responseMarkup.innerHTML = response;
// TODO: refactor contactTemplateArgs
this.contactTemplateArgs = {
headline: responseMarkup.querySelector('h2') as HTMLHeadingElement,
text: responseMarkup.querySelector('p') as HTMLParagraphElement,
contacts: Array.from(responseMarkup.querySelectorAll('.contact > div:not(:first-child)')).map((item) => {
return {
contactIcon: item.querySelector('div')?.innerText as string,
contactMarkup: item.querySelector('div:last-child')?.innerHTML as string,
};
}),
};
}

render() {
const { headline, text, contacts } = this.contactTemplateArgs;
return html`
<section>
<header class="major">${headline}</header>
${text}
<ul class="contact">
${contacts.map((item) => {
return html` <li class="icon solid">
<icon-component name="${item.contactIcon}"></icon-component>
${unsafeHTML(item.contactMarkup)}
</li>`;
})}
</ul>
</section>
`;
}
}
20 changes: 20 additions & 0 deletions src/styles/sass/layout/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
}
}

.contact icon-component {
color: #f56a6a;
display: inline-block;
font-size: 1.5em;
height: 1.125em;
left: 0;
line-height: 1.125em;
position: absolute;
text-align: center;
width: 29px;
}

.toggle {
@include icon(false, solid);
@include vendor('transition', 'left 0.5s ease');
Expand Down Expand Up @@ -172,6 +184,10 @@
}
}

.contact icon-component {
width: 27px;
}

.toggle {
text-indent: 6em;
width: 6em;
Expand All @@ -187,6 +203,10 @@
}

@include breakpoint('<=small') {
.contact icon-component {
width: 24px;
}

.toggle {
text-indent: 7.25em;
width: 7.25em;
Expand Down
1 change: 1 addition & 0 deletions types/components/sidebar/sidebar.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LitElement } from 'lit';
import './sidebarNav.ts';
import './sidebarContact.ts';
import './sidebarFooter.ts';
export declare class SidebarComponent extends LitElement {
toggle: HTMLAnchorElement;
Expand Down
18 changes: 18 additions & 0 deletions types/components/sidebar/sidebarContact.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LitElement } from 'lit';
interface SidebarContactTemplateArgs {
headline: HTMLHeadingElement;
text: HTMLParagraphElement;
contacts: Contact[];
}
interface Contact {
contactIcon: string;
contactMarkup: string;
}
export declare class SidebarContact extends LitElement {
contactTemplateArgs: SidebarContactTemplateArgs;
protected createRenderRoot(): HTMLElement | DocumentFragment;
connectedCallback(): void;
fetchContactData(): Promise<void>;
render(): import("lit-html").TemplateResult<1>;
}
export {};

0 comments on commit b920dee

Please sign in to comment.