-
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
Merged
griffbrad
merged 18 commits into
master
from
add/material-design-icons-and-svg4everybody
Apr 17, 2019
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3e8d6e7
Initial material-design-icons package stub.
griffbrad 37ce5c0
Update package.json fields that still had placeholders from the docs.
griffbrad c4e2019
Add some info about adding icons to the package.
griffbrad 160c784
Add svg4everybody to polyfill external SVGs in IE11.
griffbrad 1ba09a7
Make svg4everybody a no-op on evergreen browsers where the polyfill i…
griffbrad aedc6de
Mark Material icon package private for now.
griffbrad 2e2ba0d
Set Material icon license to Apache 2.0.
griffbrad c1d32c1
SVG sprite generation in material icons package.
griffbrad 8b04283
Drop unnecessary "use strict" from Gruntfile.
griffbrad f2dc5b0
Copy Material icon sprite to public during build-static.
griffbrad dac08ce
Component for using a Material icon from the sprite and polyfilling w…
griffbrad 6573c2c
Drop pragma.
griffbrad fd5fbba
Use classnames rather than manually filtering array.
griffbrad 426e7a8
Switch to svgstore-cli rather than Grunt for sprite generation.
griffbrad cb90ef8
Use file-loader so we can cache bust the Material icons sprite.
griffbrad ced90eb
Fix files declaration in Material icons package.json that was causing…
griffbrad b89d362
Move svg4everybody usage to client/boot/polyfills.
griffbrad d065f98
Add MaterialIcons to the playground scope
blowery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
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'; | ||
|
||
function MaterialIcon( props ) { | ||
const { size = 24, style = 'outline', icon, onClick, className, ...otherProps } = props; | ||
|
||
// Using a missing icon doesn't produce any errors, just a blank icon, which is the exact intended behaviour. | ||
// This means we don't need to perform any checks on the icon name. | ||
const iconName = `material-icon-${ icon }`; | ||
const iconClass = classnames( 'material-icon', iconName, className ); | ||
|
||
const svgId = `icon-${ style }-${ icon }-${ size }px`; | ||
|
||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
className={ iconClass } | ||
height={ size } | ||
width={ size } | ||
onClick={ onClick } | ||
{ ...otherProps } | ||
> | ||
<use xlinkHref={ `${ spritePath }#${ svgId }` } /> | ||
</svg> | ||
); | ||
} | ||
|
||
MaterialIcon.propTypes = { | ||
icon: PropTypes.string.isRequired, | ||
style: PropTypes.string, | ||
size: PropTypes.number, | ||
onClick: PropTypes.func, | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default React.memo( MaterialIcon ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
https://github.com/Automattic/wp-calypso/blob/master/packages/calypso-build/webpack/file-loader.js
file-loader magic
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 :)