Skip to content

Add LitElement support to ThemableMixin #401

Closed

Description

@web-padawan

We had a couple of internal requests to support LitElement in ThemableMixin.

https://vaadin.slack.com/archives/CPJ5V35K5/p1597668822036000
https://vaadin.slack.com/archives/C3TGRP4HY/p1617098815150800

This is needed to make it possible for custom components to use the @CssImport annotation in Flow.

There is a prototype based on older version of LitElement and especially the static getStyles API.
Please note that the old API was removed in the latest major version of Lit.

Activity

  1. web-padawan commented on Oct 28, 2021

    @web-padawan
    MemberAuthor

    Addressed by #2594 but the API is considered experimental for now.

  2. web-padawan commented on Dec 28, 2021

    @web-padawan
    MemberAuthor

    Lit support is implemented by #3093 and #3123 and will be available in Vaadin 23. Closing as done.

  3. jorginius commented on Apr 22, 2022

    @jorginius

    Is it working in Vaadin 23? In Vaadin 23.0.3 the Lit component is being finalized well before that the registerStyles call in generated-flow-imports.js (especially if we use decorators)

    Besides, LitElement has a static method finalize(): boolean and ThemableMixin seems to assume that said method is just in polymer (call is(), etc.)

  4. web-padawan commented on Apr 22, 2022

    @web-padawan
    MemberAuthor

    @jorginius Could you please create a new issue with more detailed explanation and a code example to reproduce?

  5. TatuLund commented on Apr 22, 2022

    @TatuLund
    Contributor

    Is it working in Vaadin 23?

    @jorginius To some extent yes, here is an example

    https://github.com/TatuLund/TabSheet/blob/master/src/main/resources/META-INF/resources/frontend/tab-sheet.ts

    Style module needs to be included in theme folder

    https://github.com/TatuLund/TabSheet/blob/master/frontend/themes/mytheme/components/tab-sheet.css

    It is not currently working with @CssImport(value = "./tab-sheet.css", themeFor="tabSheet")

  6. tomivirkki commented on Apr 22, 2022

    @tomivirkki
    Member

    Lit component is being finalized well before that the registerStyles

    @jorginius Yeah I also noticed this change in timing. With PolymerElement, a component doesn't finalize before a first instance of it gets added to the DOM. With LitElement, the getter for styles gets called even without having a single component instance attached.

    So in case of using LitElement + ThemableMixin, a developed needs to make sure to register all styles before the component definitions get imported

    Note that even with PolymerElement, the following will only work as long as there's no instance of a <vaadin-button> in the DOM beforehand. Otherwise, vaadin-button would finalize before reaching the style imports on the second line.

    import '@vaadin/button';
    import 'myButtonStyles.js';
  7. jorginius commented on Apr 22, 2022

    @jorginius

    It is not currently working with @CssImport(value = "./tab-sheet.css", themeFor="tabSheet")

    Many thanks @TatuLund . I was using @CssImport() and i hadn't added the is() method.

  8. tomivirkki commented on Apr 22, 2022

    @tomivirkki
    Member

    Besides, LitElement has a static method finalize(): boolean and ThemableMixin seems to assume that said method is just in polymer (call is(), etc.)

    Good catch, added an explicit check here #3723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions