Hello everyone: I’m refactoring the code in frontend (apologies for many questions), and would like to ask if there is a way to define some common string literal and reuse them to control the style of different parts/yamls of the ui?
For example I have code like:
Would be nice to define things like colour rgba(255, 255, 255, 0.1), mobile screen size 749px, size of icons etc. I also have some conditional label changes color based on value and I currently have to remember the colour code of green, blue, red, orange to make them the same.
I’m aware in yaml there is no variable concept, but is there a way to do so with css?
Yes, for reusing string constants used in card mod you can use custom css variables, for reusing (actually - for mass-styling) complete styles for cards you may use card mod themes as Pieter suggested.
An off topic, but personally me do not suggest to use card/mod themes (or suggest to use them in limited scope) due to a comparingly long delay. External JS works much faster, instantly applied. But this requires more efforts probably.
Thanks, not sure I understand all what you wrote but will try to search for more info.
One question though: if I define my own theme for the dashboard, does it lose day/night modes which HA offers? For me I just want some place with constants that I can refer to I don’t intent to interfere day/night modes. Is it archievable?
Card-mod 2.0 introduced this. I use them extensively - now. Might not be after the next version is released. The beta version is a mess of unneeded and unwanted changes.
So var(–test-width) doesn’t work not sure why, the other vars seems to work fine.
Hope you don’t mind a question: is there away that I know if I’m in light or dark mode? I might need to define 2 background colour depending on its light or dark mode but need a way to tell. Thanks
This was explained in the fantastic post - others - dark / light.
Note that this thread is about to expand to more topics))
Suggest to mark as solved with selecting an appropriate solution post. Of course we can continue discussing here.
As for a test-width - not sure if variables can be used in mediaquery, cannot test myself.
Beg your pardon, Tom, but I’m not sure what you mean here — I’m really surprised you chose those words.
Beta 4 has fixed almost all (if not all) of the standing issues and, yes, introduced a great deal of new functionality. It’s what 3.5.0 briefly was — this time without the issues. And more.
Most importantly, it’s completely up to date with the current HA Frontend changes, and there have been plenty of those. I’d say that’s quite an accomplishment.
I’m not going to quote the release notes, but it’s certainly not unwanted, unneeded, or a mess.
Just give it another look — you’ll notice that the card-mod theme adjustments are actually very minor.