Twind Configuration not working with LitElement

198 Views Asked by At

I can't seem to get theme working with LitElement. I can set the other props of setup no problem, but the theme doesn't get recognized by Twind. It's also worth mentioning that I get no error when compiling. Anyone have a quick solution?

import {LitElement, html} from 'lit';
import {setup, warn, create, cssomSheet} from 'twind';

setup({
  mode: warn,
  theme: {
    colors: {
      purple: '#2013',
    },
  },
});

const sheet = cssomSheet({target: new CSSStyleSheet()});
const {tw} = create({sheet});

export class MyApp extends LitElement {
  static styles = [sheet.target];

  static get properties() {
    return {
      name: {type: String},
    };
  }

  constructor() {
    super();
    this.name = 'World';
  }

  render() {
    return html` <h1 class="${tw`text(3xl purple)`}">${this.name}!</h1> `;
  }
}

window.customElements.define('my-app', MyApp);

1

There are 1 best solutions below

0
On

Probably, the problem is the shadow-dom. If you can use Twind, you can try to render to light-dom, instead shadow-dom.

To use light-dom add in your web-component class this method:

createRenderRoot() {
  return this;
}

In other hand, I don't sure it works without Lit...