Closed bloycey closed 3 years ago
I think this replacement is something you want to do on build time. You delivering a javascript file with 224 svg icons when using – say – 5 in your frontend.
@micha149 Thanks a heap for the code review! Will go through these suggestions soon.
I think this replacement is something you want to do on build time. You delivering a javascript file with 224 svg icons when using – say – 5 in your frontend.
@micha149 You're right about the inefficiencies here. The primary motivation behind this PR is developer experience and code readability. It's up to the developer whether these improvements are worth the inclusion of an extra JS file to download.
I think this replacement is something you want to do on build time. You delivering a javascript file with 224 svg icons when using – say – 5 in your frontend.
@micha149 You're right about the inefficiencies here. The primary motivation behind this PR is developer experience and code readability. It's up to the developer whether these improvements are worth the inclusion of an extra JS file to download.
I like it! I also am working in a project that doesn't have a build step, so a CDN-served version like this would be very handy.
Hey thanks so much for the contribution! I think this particular idea would be best handled as a separate community-maintained package, as I just can't responsibly commit to taking this on and maintaining it ourselves with the resources we have.
Hope that's understandable, and thanks again ❤️
Description
This PR includes a script that generates a JS file that will look for any HTML elements with a
data-heroicons
attribute and replace it with the relevant heroicons SVG. Ideally this file would be hosted on a CDN somewhere for easy use.E.g.
will become
Note that all classes are passed through.
By default the solid version of the icon will be used, however you can also pass the attribute
data-icon-type="outline"
to instead use the outline version of the icon.The code runs on page load. However it can also be manually invoked by calling
heroiconsLoader.replaceAllIcons();
;Motivation and Context
When browsing through HTML code SVGs are not very readable. It's unclear, just from looking at the code, what the icon represents. SVG code can also be quite lengthy and add visual noise to the page.
Other libraries offer similar functionality to this. In fact, this PR is very much inspired by feather-icons. And some of the code has been borrowed from their repo.
Types of Changes
To Do
I have not yet written formal documentation for this in the README. If this PR is supported I will happily add this information.