Improve usage of icons
See original GitHub issueI’m in the middle of replacing my custom Material UI typings/wrappers in my pet project (https://github.com/krzema12/fsynth), and noticed several problems with using icons:
- For icons to work, one has to add this piece to the
<head>
section of their HTML:<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
. Without it, icons are replaced with their names cropped to the button’s size. This approach is problematic because:
- it’s not included in the docs, and it’s just another implicit dependency to add. It took me a while to find it, and I found it by looking at the test app (thanks for it!)
- it makes another web call which in some circumstances may not be possible (running the app offline) or slow (slow Internet connection)
- Names of icons accepted by
mIcon
andmIconButton
are just strings. It’s not clear what naming convention is used (it’s e.g.play_arrow
, notPlayArrow
as presented on Material UI website). It’s also prone to typos.
I recommend making the usage of icons more type-safe and self-contained. Adding implementation(npm("@material-ui/icons", "4.9.1"))
may still be needed, but at least we can get rid of including the font. There’s an alternative way of using icons, without fonts: as regular components. See e.g. https://github.com/krzema12/fsynth/blob/master/web/src/main/kotlin/it/krzeminski/fsynth/typings/materialui/icons/PlayArrowIcon.kt.
I’m keen to prepare some pull request in my spare time. If you have any thoughts on this, let’s discuss it 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
7 Tips to Design Better Icons - UX Planet
7 Tips to Design Better Icons · 1. Keep icons simple · 2. Make them recognizable · 3. Give Icons meaning · 4....
Read more >Icon Usability and Design Best Practices - Toptal
Skillful Icon Design Improves Product Usability · Icons are easy to see and use. · Icons add cohesion to the experience within a...
Read more >Icon Usability - Nielsen Norman Group
Due to the absence of a standard usage for individual icons, text labels are necessary to communicate meaning and reduce ambiguity in an ......
Read more >How to Design Better Icons - Bootcamp
The basics of effective icon design are clear. Icons need to be consistent, legible, and clear so that users can easily understand and...
Read more >Icon Usability - Best UX Tips and Design Guidelines - Intechnic
Icon Best Practices and Guidelines · Don't reinvent the wheel. · Use icons to save space and improve recognition in toolbars, functions, and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I went for mSvgIcon and had great results. I borrowed the path from here. The license is permissive enough.
Thanks for that.
In terms of changing mIcon, I am thinking it will be best to closely follow the Material-UI way of doing things. Currently their Icon takes a string child as the name of the icon, so I think we should leave mIcon the way it is and introduce something new. That way everything keeps working, new icons can be added easily and it follows Material UI’s Icon component.
Muirwik does not have an SVG icon whereas Material-UI does. So I have added mSvgIcon which is similar in use to the Material UI SvgIcon (will release it soon). In Material-UI all the other icons take on the same props as SvgIcon (or uses SvgIcon to create their icon).
Material-UI has over 5,000 icon files (including versions for Outlined, Rounded, Sharp, etc), each as a separate component. I think this helps with code splitting. So we need to decide if we are going to auto generate 5000 kotlin files, or do it some other way. The Kotlin dead code elimination might mean we don’t need a file for each icon, but having one in each file might still help with code splitting/DCE and it is a bit more like Material-UI. Then we would have things like mAccessAlarmIcon, etc (etc, etc, etc, etc…).
So I think this is the bigger task, having the build create the appropriate files, however many they may be.