Support for multiple color schemes

EDIT: tried it, it seems to work. it’s not invasive code so I’m gonna assume that Jmix AI was a bit overly protective and that it is actually fine

I know you are restricted to a single theme at compile time and you can switch between dark/light/system.

I was wondering if it would be possible to have multiple color schemes and used jmix ai

>> In practice you still have these options inside that one compiled Aura theme:

  • Fully customize both light and dark palettes using the --*-light / --*-dark variables (accent colors, backgrounds, etc.).

  • Implement your own “extra schemes” as CSS classes or custom variables and toggle them manually (e.g. by adding/removing a class on the html element). That’s not first-class Jmix API, but it’s standard theming.

then I checked Vaadin docs and saw this documentation

Loading Stylesheets Dynamically
I pasted the relevant parts in Jmix AI and asked his opinion**, I pasted it below for brevity.** Summarized, AI is telling me its not a good idea. Is he right? should i generally stay away from this to avoid problems?

>> What you’ve quoted is from the Vaadin Flow docs, not from Jmix docs, and in the Jmix 3.0 documentation I can query there is:

  • no mention of Page.addStyleSheet(...), and

  • no Jmix-specific guidance on using it for themes.

So from the Jmix-docs-only point of view:

  • The documented ways to change look & feel are:

    • one theme (e.g. Aura) with 2 schemes: light/dark + ThemeUtils.apply*Theme().

    • changing CSS variables from Java, e.g.:

      UI.getCurrent().getElement().getStyle()
              .set("--my-button-text-color", "white");
      UI.getCurrent().getElement().getStyle()
              .set("--my-button-bg-color", "purple");
      
      

      (from styling-ui-components.html)

  • There is no Jmix page that says “use Page.addStyleSheet to switch themes” or that shows it as a recommended mechanism.

What your Vaadin snippet means conceptually (outside Jmix docs):

  • UI.getCurrentOrThrow().getPage().addStyleSheet("dynamic-styles.css")
    tells Vaadin to inject a <link rel="stylesheet" ...> pointing to that URL for the current UI/session.

  • It returns a Registration which you can later .remove() to detach that stylesheet.

  • If you put multiple “theme” CSS files under src/main/resources/META-INF/resources/, you could in principle:

    • load one or another at runtime,

    • remove the previous one using the Registration,

    • and thus approximate “swappable stylesheets”.

But because Jmix 3.0 docs do not cover addStyleSheet at all, this is:

  • a low-level Vaadin trick, not a documented Jmix theming feature,

  • something you use at your own risk (Jmix can’t guarantee how it interacts with Aura variables, light/dark schemes, or future version changes).