Skip to content

Instantly share code, notes, and snippets.

@stramel
Last active February 15, 2019 02:34
Show Gist options
  • Save stramel/536cd51402f47519a248d7433355ae72 to your computer and use it in GitHub Desktop.
Save stramel/536cd51402f47519a248d7433355ae72 to your computer and use it in GitHub Desktop.
[WIP] ShadyStyle
import "@webcomponents/shadycss/custom-style-interface.min.js";
const { CustomStyleInterface } = window.ShadyCSS;
class ShadyStyle extends HTMLElement {
__style = null;
constructor() {
super();
if (!CustomStyleInterface) {
throw new Error(`You have to load CustomStyleInterface via "import '@webcomponents/shadycss/custom-style-interface.min.js';"`);
}
CustomStyleInterface.addCustomStyle(this);
}
connectedCallback() {
this.__style = this.querySelector('style') || document.createElement('style');
if (!this.css && !this.__style.textContent) {
throw new Error('Must use either the css property or a `style` tag in the LightDOM');
}
if (this.css) {
this.__style.textContent = this.css;
}
document.head.appendChild(this.__style);
}
get style() {
return this.__style;
}
}
customElements.define('shady-style', ShadyStyle);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment