Closed troccoli closed 1 year ago
Is this a valid issue? Shall I submit a PR?
@troccoli This would be a neat addition if the opacity and hex value for each color can be set. Font Awesome's duotone icons (https://fontawesome.com/docs/web/style/duotone) implemented that flexibility quite well.
After an extensive 10 minutes of research, it looks like Figma isn't capable of handling smarter colors like currentColor
, none
, or the CSS Custom Properties (aka CSS Variables) approach that @ampodobas mentioned is in use by Font Awesome.
I did a quick spot check and it looks like the current SVGs are consistent with the colors, with the only instances of fill
or stroke
that I found being one of the following:
fill="white"
fill="none"
fill="black"
fill="#333333"
stroke="#333333"
It should be relatively "easy" to do run add a script that does some search/replacing, assuming the semantics hold up across all icons (that #333333
should always be currentColor
, for example).
I did a quick experiment and it looks like if we replace #333333
with currentColor
, most apps will just treat that as black (I tried Illustrator, Firefox, and Figma). This seems like a fine default. Then, if you use the file in a context with custom CSS (or even just embedded in an HTML document with a different font color, the icon will automagically take on that color.
Are there any drawbacks to this approach we may not be thinking of?
I am the maintainer of the troccoli/blade-health-icons package, which was how I found out the issue.
I run the following in a shell script before addind the SVG to my packages
for FILE in $RESOURCES/*; do
# Fix the svg to allow changing their colour
sed -i '' 's/fill="none"/fill="currentColor"/g' $FILE
sed -i '' 's/fill="white"/fill="none"/g' $FILE
sed -i '' 's/fill="#333333"//g' $FILE
done
I'm not sure why I completely remove the #333333
colour, but it seems to work for me. I haven't checked all icons though, but I haven't received any issues on my package either.
I like @troccoli's use of sed
. We could add something like that to the yarn update-icons
command.
@sgarrity: I see in @troccoli's example above that the replacements are:
fill="none"
→ fill="currentColor"
fill="white"
→ fill="none"
fill="#333333"
is just removedIs that what we should be doing here? Or is it:
#333333
→ currentColor
fill="white"
→ fill="none"
fill="black"
→ is it fill="currentColor"
???I have the code implemented to handle the search/replace. I just need to know what commands we actually need.
I have updated all of the icons and merged that to master.
There's now an extra yarn remove-svg-backgrounds
command which will be automatically run when you run yarn update-icons
which we always do when publishing new icons anyway.
That will automatically clean up all of the colors and add currentColor
where appropriate.
Thanks @troccoli for filing this!!
Thank you @nburka for fixing it.
I have found an issue that I think is worth looking at. I think it's related to #150 and possibly #151.
Let's say I have the following HTML
I get
However, I would expect the wheelcahir to be blue in a yellow box, since I change the colours of the container
<div>
.The issue is that the fill colour is fixed in the SVG.
I propose to remove the
fill="#333333"
that sets the colour to (a shade of) black on all the<path>
tag, replacefill="none"
on the<svg>
tag withfill="currentColor"
, and finally replacefill="white"
in the<rect>
tag withfill="none"
.This would result in the following
There may be other tags in the various SVGs that use different fills, but the idea is the same: we shold have
fill="currentColor"
on the<svg>
tag, we should not have any fill that sets a specific colour, and we may havefill="none"
on some tags inside the SVG when appropriate.