I'm implementing a (lit-element) webcomponent that has a css-grid that's specific per instance of the element. For now I set the grid-template property by the style attribute of the element, but as the grid can become quite big this attribute is also very large and maybe reaches some limits and certainly is not nice to read/validate in the HTML. What would be the correct way to do this?
Like:
<div id="timeline" draggable="true" class="timeline year" style="grid-template: [years] "dummy-group-cell _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021--- _y_2021---" var(--default-height, 40px) [months] "dummy-group-cell _m_2021-09 _m_2021-09 _m_2021-09 _m_2021-09 _m_2021-09 _m_2021-10 _m_2021-10 _m_2021-10 _m_2021-10 _m_2021-10 _m_2021-10 _m_2021-10" var(--default-height, 32px) [data] [none] "none - - - - - - - - - - - -" var(--default-height, 60px) [none] "none - - - - - - - - - - - -" var(--default-height, 60px) [none] "none - - - - - - - - - - - -" var(--default-height, 60px) [none] "none - - - - - - - - - - - -" var(--default-height, 60px) [none] "none - - - - - - - - - - - -" var(--default-height, 60px) [footer] "none - - - - - - - - - - - -" 1fr [end] / [group] auto [_1635285600000] var(--width) [_1635372000000] var(--width) [_1635458400000] var(--width) [_1635544800000] var(--width) [_1635631200000] var(--width) [_1635721200000] var(--width) [_1635807600000] var(--width) [_1635894000000] var(--width) [_1635980400000] var(--width) [_1636066800000] var(--width) [_1636153200000] var(--width) [_1636239600000] var(--width) ;">
...
</div>
<html>
<body>
<script src="https://unpkg.com/@webcomponents/shadycss/scoping-shim.min.js"></script>
<script type="module">
import {LitElement, html} from 'https://unpkg.com/@polymer/[email protected]/lit-element.js?module';
import 'https://unpkg.com/@polymer/[email protected]/paper-button.js?module';
class MyElement extends LitElement {
static properties = {
color: {type: String}
};
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties);
// todo: fix @apply https://github.com/Polymer/lit-html/issues/518
window.ShadyCSS.styleSubtree(this);
}
render() {
return html`
<style>
:host {
--paper-button: {
background: ${this.color};
}
}
</style>
<paper-button style="color:${this.color}">Button</paper-button>
`;
}
}
customElements.define('my-element', MyElement);
</script>
<my-element color="green"></my-element>
<my-element color="red"></my-element>
</body>
</html>