diff --git a/src/components/cookie/cookie.tsx b/src/components/cookie/cookie.tsx index 630617d5..a3eef099 100644 --- a/src/components/cookie/cookie.tsx +++ b/src/components/cookie/cookie.tsx @@ -1,6 +1,7 @@ import { Component, h, Prop, State, Element, Watch } from '@stencil/core'; +import { themeStyle } from '../../helpers/themeStyle'; import JsCookie from 'js-cookie'; import Tab from 'bootstrap/js/src/tab'; @@ -137,37 +138,6 @@ export class Cookie { this.items = items; } - themeStyle() { - const css = this.currentTheme ? this.currentTheme.components[this.tagName] : ''; - let style; - - if(!this.style) return; - - // This is used by browsers with support for shadowdom - if(this.el.shadowRoot.adoptedStyleSheets) { - style = new CSSStyleSheet(); - style.replaceSync(css); - // TODO: We should not take first index we should all except the previous style - this.el.shadowRoot.adoptedStyleSheets = [ this.el.shadowRoot.adoptedStyleSheets[0], style ]; - } else { - const node = this.el.shadowRoot || this.el; - style = this.el.querySelector('#themeStyle') || document.createElement('style'); - // style.appendChild(document.createTextNode(css)); - // style.innerHTML = css; - style.id = 'themeStyle'; - - if (style.styleSheet) { - style.styleSheet.cssText = css; - } else { - style.appendChild(document.createTextNode(css)); - } - - if(!node.querySelector('#themeStyle')) { - node.insertBefore(style, node.firstChild.nextSibling); - } - } - } - componentWillLoad() { this.loadLibs(); @@ -179,7 +149,7 @@ export class Cookie { this.store.subscribe(() => { this.setTheme(); - this.themeStyle(); + themeStyle(this.currentTheme, this.tagName, this.style, this.el); }); if (!(this.el && this.el.nodeName)) return; @@ -193,7 +163,7 @@ export class Cookie { this.style = this.el.shadowRoot.adoptedStyleSheets || []; - this.themeStyle(); + themeStyle(this.currentTheme, this.tagName, this.style, this.el); // TODO: It would make sense to create a tab and tab-item component. // That can be used instead of this hacky way diff --git a/src/components/dealer-header/dealer-header.tsx b/src/components/dealer-header/dealer-header.tsx index 28c53783..0174edfa 100644 --- a/src/components/dealer-header/dealer-header.tsx +++ b/src/components/dealer-header/dealer-header.tsx @@ -1,6 +1,7 @@ import { Component, h, Element, Prop, State, Watch, } from '@stencil/core'; +import { themeStyle } from '../../helpers/themeStyle'; @Component({ tag: 'c-dealer-header', @@ -30,6 +31,8 @@ export class DealerHeader { @State() tagName: string; + @State() style: Array; + @Element() el: HTMLElement; @Watch('theme') @@ -45,6 +48,7 @@ export class DealerHeader { this.store.subscribe(() => { this.setTheme(); + themeStyle(this.currentTheme, this.tagName, this.style, this.el); }); if (!(this.el && this.el.nodeName)) return; @@ -52,10 +56,14 @@ export class DealerHeader { this.tagName = this.el.nodeName.toLowerCase(); } + componentDidLoad() { + this.style = this.el.shadowRoot['adoptedStyleSheets'] || []; + + themeStyle(this.currentTheme, this.tagName, this.style, this.el) + } + render() { return [ - this.currentTheme ? : '', - {this.logo ? {this.siteName} diff --git a/src/components/footer/footer.tsx b/src/components/footer/footer.tsx index 9abf5f91..30e24a84 100644 --- a/src/components/footer/footer.tsx +++ b/src/components/footer/footer.tsx @@ -1,6 +1,7 @@ import { Component, h, Prop, State, Element, Watch, } from '@stencil/core'; +import { themeStyle } from '../../helpers/themeStyle'; @Component({ tag: 'c-footer', @@ -32,6 +33,8 @@ export class Footer { @State() currentTheme = { components: [] }; + @State() style: Array; + @Element() el: HTMLElement; @Watch('items') @@ -57,7 +60,10 @@ export class Footer { this.setItems(this.items); this.setSocialItems(this.socialItems); - this.store.subscribe(() => this.setTheme()); + this.store.subscribe(() => { + this.setTheme(); + themeStyle(this.currentTheme, this.tagName, this.style, this.el); + }); if (!(this.el && this.el.nodeName)) return; @@ -66,6 +72,12 @@ export class Footer { this.initialSlot = this.el.innerHTML; } + componentDidLoad() { + this.style = this.el.shadowRoot['adoptedStyleSheets'] || []; + + themeStyle(this.currentTheme, this.tagName, this.style, this.el) + } + parse(items) { return Array.isArray(items) ? items : JSON.parse(items || '[]'); } @@ -79,8 +91,6 @@ export class Footer { render() { return [ - this.currentTheme ? : '', -