Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin: change CSS variables dynamically

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

like image 255
Thomas Avatar asked Oct 26 '25 05:10

Thomas


1 Answers

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.

like image 92
Tarek Oraby Avatar answered Oct 29 '25 09:10

Tarek Oraby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!