JSFiddle - React, Tailwind, and code Playground
by jrunning
HTML
<my-element data="some dark values" dark-mode></my-element>
<my-element data="some light values"></my-element>
<script src="https://bundle.run/[email protected]"></script>
JavaScript
const { LitElement, css, html } = litElement;
class MyElement extends LitElement {
static get properties() {
return {
data: { type: String },
darkMode: {
type: Boolean,
reflect: true,
}
};
}
static get styles() {
return css `
:host {
display: block;
}
.data-container {
background-color: #fff;
color: #333;
}
:host([dark-mode]) .data-container {
background-color: #000;
color: #fff;
}
`;
}
constructor() {
super();
this.data = "";
this.darkMode = false;
}
render() {
return html `
<div class="data-container">
<p>${this.data}</p>
</div>
`;
}
}
customElements.define('my-element', MyElement);