I have a shared-styles
element that keeps most of my applications colors. I can easily change the colors manually in shared-styles.html
, and all of my other components can inherit from there if I use the CSS variables.
My problem is I need to update the CSS variables in shared-styles.html
and have all the other components that inherit the CSS variables to update their colors accordingly. Below is my shared-styles.html
. For brevity, I removed all the variables except --app-primary-color
.
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<!-- shared styles for all views -->
<dom-module id="shared-styles">
<template>
<style is="custom-style">
:host {
--app-primary-color:#2196F3;
}
</style>
</template>
<script>
class SharedStyles extends Polymer.Element {
static get is() { return 'shared-styles'; }
ready(){
super.ready();
console.log('update css');
this.updateStyles({'--app-primary-color': 'red'});
}
}
window.customElements.define(SharedStyles.is, SharedStyles);
</script>
</dom-module>
This is how I am including them in the other components. For example:
<dom-module id="test-element">
<template>
<style include="shared-styles">