-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add/material design icons and svg4everybody #32364
Add/material design icons and svg4everybody #32364
Conversation
…ith svg4everybody.
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Webpack Runtime
App Entrypoints
Async-loaded Components
Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
… us to need an alias for the sprite import.
@griffbrad I added the MaterialIcon to the playground scope just to be able to test it out there. Looks good! We might want to add an example to devdocs too, but that can probably wait for another PR. |
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.
LGTM
populate this package with all the available icons. Alternatively, we could seek | ||
out an alternative distribution of the icons. | ||
|
||
## Using a Material icon in Calypso |
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.
@griffbrad Looks like the readme needs to be updated in a future PR.
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.
Thanks for the heads up. Will post that later today.
import classnames from 'classnames'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import spritePath from '@automattic/material-design-icons/svg-sprite/material-icons.svg'; |
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.
@griffbrad This line is interesting. How does this import get converted into a path string, and how would I be able to replicate it in gridicons?
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.
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.
This is done with webpack's file-loader. In the context of Calypso, it's added to webpack.config.js here:
https://github.com/Automattic/wp-calypso/blob/master/webpack.config.js#L234
That comes out of the Calypso build package:
https://github.com/Automattic/wp-calypso/blob/master/packages/calypso-build/webpack/file-loader.js
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.
Very interesting, thank you both! Should be easy to replicate for gridicons, then :)
Excellent work, @griffbrad, some great improvements on my experimental PR! I'll be sure to copy what you did here when I start work on gridicons 🙂 |
I am thinking that you might have some good input on the Add icons block being proposed for Gutenberg Core. WordPress/gutenberg#16484 |
Thanks, @paaljoachim, I'll take a look! |
Changes proposed in this Pull Request
Add a package for storing the Material icons we're using in the new nav drawer work (see PR #31742). The official material-design-icon package (https://github.com/google/material-design-icons) has not been updated since Jan 2018. It is missing several icons we intend to use.
To load SVGs, I use the technique @sgomes introduced in PR #32172. This uses svg4everybody to polyfill the use of external references in SVG
<use>
elements, enabling the browser to load and optimize SVG rather than converting SVGs to React components.Testing instructions
With this PR, you can use the new MaterialIcon component to render an icon. Example: