Skip to content

Instantly share code, notes, and snippets.

@bjerkek
Created May 6, 2021 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjerkek/82cbdea4a7e967caa494cfd83ffc99e5 to your computer and use it in GitHub Desktop.
Save bjerkek/82cbdea4a7e967caa494cfd83ffc99e5 to your computer and use it in GitHub Desktop.
Learning Podium - Header Web Component
const template = document.createElement('template');
template.innerHTML = `
<style>
:host {
all: initial;
display: inline-block;
}
</style>
<header>
<nav>
<a href="">Link 1</a>
<a href="">Link 2</a>
<a href="">Link 3</a>
</nav>
</header>
`;
class Header extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
const { shadowRoot } = this;
const node = document.importNode(template.content, true);
shadowRoot.appendChild(node);
}
}
if (!customElements.get('app-header')) {
customElements.define('app-header', Header);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment