generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
122046e
commit b920dee
Showing
8 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |