Last active
February 15, 2019 02:34
-
-
Save stramel/536cd51402f47519a248d7433355ae72 to your computer and use it in GitHub Desktop.
[WIP] ShadyStyle
This file contains hidden or 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
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