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
Use svgr to generate icons for iconoir-react #35
Conversation
If you would like to test it, I've published it to the GitHub registry: |
I'll take a proper look when I have a moment later on, but from the quick skim over I've just done it looks good and looks like it fixes some of the issues and limitations I had made a mental note of but not yet got around to fixing properly (including the stroke width problem we were talking about earlier @lucaburgio). If we did want to keep the |
Thanks @PianoManDanDan! Looking forward to your feedback 😃 You're right! If you want to keep the |
Thank you @paescuj, that's super interesting! And thank you @PianoManDanDan for taking care of this! I'll follow the thread 🙏🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paescuj I've left a couple of comments. For the most part it looks good, only one thing that doesn't quite look right. I'm also having a few issues running some of the commands at the moment, but suspect it's due to me using node 12, so if you could let me know what version of node and npm you're using I'll update and try again. I agree with what you say about the automatically generated types and would like to change it in the future, but it is something we can come back to at a later date.
@lucaburgio it looks like this also doesn't fix the stroke width problem. The react library will try to add the stroke width onto the root svg element, but because you're adding it to each of the path elements at the moment, the <path>
stroke widths overwrite the root <svg>
stroke width. Is it possible to add the stroke width onto the root elements at all, or are you sometimes using different stroke widths in the same icon?
@PianoManDanDan the icons are using the same stroke-width everywhere, so yes, I would remove the stroke-width property from all the paths and move it in the root element. This would also make the icons clearer. Let me know if you want me to fix them now directly in the master. On a side note: Should we do the same for the stroke="currentColor" in order to let you change the color too? |
@PianoManDanDan Thank you very much for your feedback! Thanks for pointing out the error - it's fixed now. Besides that I did some other improvements...
Great! I think the best thing would be to track this in an issue as soon as we've merged this pull request.
This is not absolutely necessary, because currentColor inherits the value from the root/parent elements and we are already able to set the color property on the root element. |
@PianoManDanDan @paescuj Just merged 13af1ea. Now all the icons have stroke-width property applied only to the root. ✅ |
Thanks @lucaburgio! I've rebased this pull request and regenerated the icons - it seems to work perfectly with your stroke-width change 😄👍 |
FYI: Republished latest version to GitHub registry: |
What do you think @PianoManDanDan ? Can we proceed? |
Sorry to be a pain but is it possible for you to regenerate the Also for some reason the
I agree. Once this is merged in we can raise it as an issue to track. |
Sure 👍 I've regenerated the
Yes, pretty strange... I've removed the |
All looks good to me. Don't worry about updating the package README @paescuj. When this gets merged in, I'll publish v2.0.0 to npm and update the README then. All good to go @lucaburgio 👍 |
Okay, thanks @PianoManDanDan! |
That's great! thank you guys 🙏🏻 |
Thanks @lucaburgio for providing this beautiful icon library and thanks @PianoManDanDan for creating the
iconoir-react
package!I started using iconoir-react in a React project and noticed that the generated JSX syntax in the React components is invalid (e.g.
stroke-width
should bestrokeWidth
) and thesvg
element is defined twice:https://github.com/lucaburgio/iconoir/blob/18671eed7e425ab043233e596f90581eae193557/packages/iconoir-react/src/icons/1st-medal.jsx#L7-L22
While looking for a lasting solution to this I stumbled upon svgr (a tool to transform SVGs into React components) which seemed like a perfect fit for iconoir-react.
After playing around and testing
svgr
, I came up with this pull request which contains the following changes:bin/build.js
script which now copies all icons, fixes the names and runs svgr afterwards. Unfortunately, I had to use the svgr CLI here because the API doesn't provide the possibility to process a whole directory and automatically creating a export file. We could get rid of this script, e.g. by renaming/fixing the icons with incompatible names in the root directory...prop-types
.rollup
totsup
which is much simpler and automatically creates and bundles TypeScript types definition.The usage is still the same, e.g.:
However with this implementation you are now able to pass all valid SVG props to the icon component (e.g. width, height, color, id, ...), for example:
The only thing which is really different is that instead of the option
size
you now have to usewidth
/height
to change the icon size and the default is now "1.5em" (equals to 24px when font size is 16px) instead of "24px". I prefer this solution because it makes the icons kind of responsive, especially in text sections:Tested with both, a JavaScript and TypeScript React project.
Please let me know what you think! If you're happy with those changes I can update the README as well.
Todo: