Created
November 15, 2019 22:56
-
-
Save anoblet/30a31ae87015476634f3a51f3014c176 to your computer and use it in GitHub Desktop.
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 { CSSResult, LitElement } from "lit-element"; | |
/** | |
* Takes a node, CSSResult and appends it | |
*/ | |
export const applyStyle = (node: HTMLElement, style: CSSResult) => { | |
if ("adoptedStyleSheets" in document && node.shadowRoot) { | |
const shadowRoot: any = node.shadowRoot; | |
const sheets = shadowRoot.adoptedStyleSheets; | |
shadowRoot.adoptedStyleSheets = [...sheets, style.styleSheet]; | |
} else { | |
const styleNode = document.createElement("style"); | |
styleNode.textContent = style.cssText; | |
if (node.shadowRoot) node.shadowRoot.appendChild(styleNode); | |
else node.appendChild(styleNode); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment