Skip to content

Instantly share code, notes, and snippets.

@enjikaka
Created February 5, 2020 15:04
Show Gist options
  • Save enjikaka/c91aaa027fc8105a6c70d4be3ffb71cc to your computer and use it in GitHub Desktop.
Save enjikaka/c91aaa027fc8105a6c70d4be3ffb71cc to your computer and use it in GitHub Desktop.
export default class TidalWebComponent extends HTMLElement {
static css (strings) {
const text = strings.raw.join();
const sheet = new CSSStyleSheet();
sheet.replace(text);
return sheet;
}
static html (strings) {
const text = strings.raw.join();
const frag = document.createRange().createContextualFragment(text);
return frag;
}
connectedCallback () {
this._sDOM = this.attachShadow({ mode: 'closed' });
const css = this.css;
if (css) {
this._sDOM.adoptedStyleSheets = [this.css];
}
const html = this.html;
if (html) {
this._sDOM.appendChild(html);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment