4

Is there a way to change dynamically the lumo primary colors:

html {
  --lumo-primary-text-color: hsl(214, 35%, 15%);
  --lumo-primary-color-50pct: rgba(140, 236, 0, 0.5);
  --lumo-primary-color-10pct: rgba(140, 236, 0, 0.1);
  --lumo-primary-color: #8CEC00;
  --lumo-primary-contrast-color: hsl(214, 35%, 15%);
}

Thanks in advance!

Best Regards, Thomas

4
  • 1
    Hi! This is likely useful to you: demo.vaadin.com/lumo-editor Commented May 14, 2021 at 10:09
  • Hello! I used the theme editor to get my colors. But how can I change this live in the application? Commented May 14, 2021 at 10:15
  • @Thomas So you mean you want to change them programmatically at runtime? Like let the user change some color? If so, do you want to do it in Java? Commented May 14, 2021 at 10:18
  • Hello Tarek! Yes, I want to change to colors during runtime. Commented May 14, 2021 at 10:35

1 Answer 1

9

The CSS variables can be updated dynamically from Java like so

UI.getCurrent().getElement().getStyle().set("--lumo-primary-text-color", "hsl(214, 35%, 15%)")

This will update the variable's value for the whole UI. If you want to change the variable only for a specific component (and its children), then you can call getElement().getStyle().set() on that component only.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, so easy! Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.