diff --git a/src/box-icon-element.js b/src/box-icon-element.js index 6600f29..d001705 100644 --- a/src/box-icon-element.js +++ b/src/box-icon-element.js @@ -4,10 +4,56 @@ import transformationsCss from '../static/css/transformations.css'; //= ====================================================== +const GLOBAL = window; const CACHE = {}; // iconName: Promise() const CSS_CLASS_PREFIX = 'bx-'; const CSS_CLASS_PREFIX_ROTATE = `${CSS_CLASS_PREFIX}rotate-`; const CSS_CLASS_PREFIX_FLIP = `${CSS_CLASS_PREFIX}flip-`; +const TEMPLATE = document.createElement('template'); +const usingShadyCss = () => !!GLOBAL.ShadyCSS; + +TEMPLATE.innerHTML = ` + +
`; /** @@ -73,55 +119,20 @@ export class BoxIconElement extends HTMLElement { * @param {String} [tagName=this.tagName] */ static define(tagName) { - customElements.define(tagName || this.tagName, this); + tagName = tagName || this.tagName; + if (usingShadyCss()) { + GLOBAL.ShadyCSS.prepareTemplate(TEMPLATE, tagName); + } + customElements.define(tagName, this); } constructor() { super(); this.$ui = this.attachShadow({ mode: 'open' }); - this.$ui.innerHTML = ` - -
`; - + this.$ui.appendChild(this.ownerDocument.importNode(TEMPLATE.content, true)); + if (usingShadyCss()) { + GLOBAL.ShadyCSS.styleElement(this); + } this._state = { $iconHolder: this.$ui.getElementById('icon'), }; @@ -166,6 +177,12 @@ ${transformationsCss} break; } } + + connectedCallback() { + if (usingShadyCss()) { + GLOBAL.ShadyCSS.styleElement(this); + } + } } function handleNameChange(inst, oldVal, newVal) {