Similar question in nature to recent Dark vs Light detection, I wonder how once could detect Lumo vs Aura in the upcoming V25
This is now topical as Iâd like to at least prepare update of some add-ons and probably there are other add-on authors wondering this as well. There has bean some Lumo leakege into some of them and I wouldnât like that we get lumo and aura variants of all the add-ons
A trivial example of the problem:
(Note: this particular case seems to work just fine as the LUMO_PRIMARY value is âprimaryâ and Aura uses the same, but there are actual issuesâŚ)
Another thing that maybe somebody has solved, how to easily test add-ons with both themes
There is a section about upgrading add-ons in the V24->V25 upgrading guide (published just a few days ago) that covers that subject, amongst others: How to upgrade Vaadin applications. (TL;DR is that there is a ThemeDetectionMixin that can be used to load theme-specific styles.)
(Feedback and contributions to that guide are very welcome, obviously.)
You get that only if you use ThemeDetectionMixin, which is not applied to standard Vaadin components.
In general there is no solution to this problem yet. Weâd need either or both:
A marker attribute on the document or host element of the Flow client to allow global CSS to target that
Some way to make that information available in Java code. Doing that automatically might be tricky since it requires waiting for the theme to load and then do a server call, only after which you could apply respective styles. Which is probably too late because at that point the add-on might have already rendered in the browser.
The only solution I can think of that works right now is for the add-on to provide theme-specific components / variants.
Iâm curious to know what the cases are when an add-on needs to know what theme the application is using.
Applying a theme variant is one, and the primary button example is kind of obvious. For that specific case, weâve been pondering if that should actually be a core feature of the Button component, and not theme-dependent. That wonât resolve the whole topic, but just wanted to mention.
It might be suitable to apply both Lumo and Aura variants when you want to support both and use the built-in theme variants of a Vaadin component. Seems unlikely that there would be unwanted conflicts. For example, you could apply both the ButtonVariant.LUMO_ERROR and ButtonVariant.AURA_DANGER variants on the same button. But perhaps you want to apply âprimaryâ when the app uses Lumo, but not when it uses Aura and instead use the âaccentâ variant?
For non-Vaadin-component parts of the add-on (i.e., custom CSS), add-ons should offer separate stylesheets for the app to import, one for Lumo and one for Aura.
That approach was not met with a warm welcome, because then an add-on is not just a drop in solution. Technically this is a new problem: there wasnât any way to have automatic support for different themes from the Java side. For custom web components there was via the theme folder, which let Flow import the respective entry-point from the theme folder based on the @Theme annotation. So at least for that we created a replacement with the ThemeDetectionMixin that can automatically detect Aura and Lumo.
Please also remember that the actual case might also be neither Lumo nor Aura if the application has a custom theme built on top of the base styles. Or then itâs something that is technically based on either Lumo or Aura but customized beyond recognition.
Using style properties is the most common I guess. Would need to conditionally drop in a different CSS for component with Aura or provide a fallback value (that probably doesnât fit well into new them). Leaky, yes, what can one do
From Viritin, Badge is probably quite broken if Aura is used (havenât tested at all yet):
Yeah and as a regular complaint, Vaadin provided Badge component would be great (like the Default/PrimaryButton)
Yeah, clearly. But this was the case which I believed would be solved by offering two separate stylesheets that the app chooses which to import. But as Sascha pointed out, this makes using an add-on more involved with an additional step as you need to remember to import the correct stylesheet. To me that feels natural, as itâs the application theme that decides how components should be styled. Explicitly importing the main stylesheet for Aura or Lumo is no different in that regard.
If I remember correctly, we used to have some âmagicâ for add-ons in Vaadin 7 and 8, that we auto-generated the âaddons.cssâ file where all add-on stylesheets got imported. But you still needed to have the import for that âaddons.cssâ in your main stylesheet explicitly.