This question is related to our new node-red-contrib-ui-svg node. We got some good news from Joseph Liard that has released a new version of DrawSvg, which now supports FontAwesome icons (which he has especially added for our node).
But I cannot get the colors of the FontAwesome icon correct in the Node-RED dashboard.
This is what happens:
I add a FontAwesome icon in DrawSvg:
I change the default color via DrawSvg to some ugly pink color:
I save the drawing, and we receive following SVG string in our node:
Morning @dceejay,
Do you mean that I can somehow say in the html code (which I generate in my UI node for the dashboard): this DIV element and all its children (SVG element ...) should not inherit any CSS from the dashboard?
Thanks !! I have been reading some articles this evening, and then it became clear that I cannot stop inheritance of styles. And yes the "!important" directive popped up in some of these articles, but they claim you should only use it as a last resort. For example:
In most cases, using an !important flag is like cracking a nut with a sledgehammer. The !important flag it is a bad practice because it makes things unnecessarily difficult to override in the future, and should only be reserved as a last resort.
But could at least test whether it solved my problem. So I added the "!important" directive (to the generated SVG), but the damn icon still stays blue
Have pasted the (generated) SVG code in a jsfiddle and then it nicely gets a pink color. So it only gets the wrong color inside the dashboard.
Hey @dceejay,
Do you mean in a dashboard template node? Could you please explain a bit in detail what you mean? Thanks!
Not the 100% answer - but a good test.
likewise you should be able to see the precedence of css in the browser debug console styles... you either could use !important... (last resort - or make your css more targeted than the one that turns it blue... so maybe by having your own div class or something to add more specificity to it.
DrawSvg generates an SVG "symbol" for each FontAwesome icon. Such a symbol has an SVG path which contains the contour of the icon.
Then DrawSvg will re-"use" that symbol at every location where I put it. And there it also gets my custom pink color (style="fill:#ff1493; !important;").
The path in the symbol has no explicit color, but it seems to get his blue color from the dashboard:
And that is the cause: because when I deselect the checkbox, then the icon gets the pink color in the dashboard...
So I need to get rid of those dashboard styles.
But as you can see, the "!important" directive doesn't help ...
Also, I'm not certain if this isn't a quirk of <use>. I.e. correct me if I'm wrong but shouldn't inline style take precedence over a class? But as the style is set in the use and not the def>path, it's not working as expected?
maybe - indeed I thought inline did take precedence. - but as i said you could define a style for path that is more specific than just .nr-dashboard-theme .nr-dashboard-template (or just use !important
DrawSvg generates an SVG symbol for each icon. As explained above that contains an SVG path that gets its blue fill color from the dashboard.
Everywhere I "use" that symbol, the browser will create a shadow dom with a copy from the original path.
But that cloned path (in the shadow dom) has fill color pink as, so here no dashboard colors.
I have the impression that the browser creates the shadow doms (with the original colors), and afterwards applies the dashboard color to the original symbol path (which is in the same DOM as the dashboard elements). But I would have expected that that cloned path would have drawn, but that is not the case because then it should have been rendered pink in the dashboard ...
@dceejay Have tried that (see above post), but it didn't help. Or should I add it somewhere else?? Or somebody has put a very strong ingredient in your beers
Fortunately, there's a trick we can use to at least get one unique color per instance. If we go in to the SVG definition itself, we can apply fill=“currentColor” to a shape or path of our choosing. What does that do? Well, the long supported CSS value currentColor , specifies that color will be inherited. This means that we can define a font color higher up in the tree (for example on the cloned instances themselves), and the fill for that path or shape will inherit the color
Might be relevant?
I haven't processed it in my head or gave it a try.
Could you play in the DOM/devtools, give it a try?