-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE REQUEST] Automatically convert svg styles to attributes #1277
Comments
@devicons/supporter @devicons/ecosystem-react What do you guys think of this feature? |
Sounds great but somebody would have to implement it. |
Alternatively SVGO could also be directly integrated into react-devicons. |
Upon looking a bit further into it I think that convertStyleToAttrs.js does something entirely different. It converts a single style attribute on one element to multiple independent attributes on the same element. But our problem is with style elements, not attributes. |
This is what we need: https://github.com/svg/svgo/blob/main/plugins/removeStyleElement.js |
I've gone ahead and added removeStyleElement.js to react-devicons: devicons/react-devicons#14 |
@maltejur Yeah looks like you're right! I found what we need though. Instead of just removing the style element, we want to convert it to inline style attributes. This can be done with this script: https://github.com/svg/svgo/blob/main/plugins/inlineStyles.js Description of what it does here: https://github.com/svg/svgo#built-in-plugins
|
Great, but like I mentioned above, I think what we need is actually the inlineStyles.js script |
Hi, yes @Snailedlt is right, removing the style in svg elements will break lots of SVG icons. The conversion from this inline style: style="fill-rule:evenodd;clip-rule:evenodd;" To this HTML attributes styling:
is required to preserve / not break icons. Personally, when I add new icons I always use the style HTML attributes, but some old icons still have inline |
@BenSouchet Style attribute looks like this: <path style={{"fill-rule:evenodd;clip-rule:evenodd;"}} d="some path here" Style element looks like this: <style id="someId" type="text/css">
.someStyle{"fill-rule:evenodd;clip-rule:evenodd;"}
</style> Now the first (Style attribute) is okey. Looks dirty, but it doesn't cause any errors. The 2nd (Style element) however is what's causing the error. @maltejur ended up fixing the error by first running @BenSouchet |
@Snailedlt Ah okay my bad 🙂 I opened an issue but it's not a priority, nor a vital element. |
I have searched through the issues and didn't find my problem.
Problem
Upon fixing some stuff (#1276) causing a bug in the react-devicons project, I noticed that the process of converting SVG styles to attributes can be automated.
Some projects using devicons, like react-devicons will fail if styles are used in the SVG icons. This has led to several bugfixes. See #1169
Here's a screenshot of the issue:
Possible Solution
SVGO has a neat script (convertStyleToAttrs.js) to go through and convert all SVG styles into attributes. We could leverage this script to automate the process with one of our bots (maybe make a new one?).
This would be help ensure the SVG's work in the react-devicons project and potentially future projects with similar solutions.
Additional information
No response
The text was updated successfully, but these errors were encountered: