Skip to content
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
merged 18 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
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 Mar 28, 2019
37ce5c0
Update package.json fields that still had placeholders from the docs.
griffbrad Mar 28, 2019
c4e2019
Add some info about adding icons to the package.
griffbrad Mar 29, 2019
160c784
Add svg4everybody to polyfill external SVGs in IE11.
griffbrad Apr 17, 2019
1ba09a7
Make svg4everybody a no-op on evergreen browsers where the polyfill i…
griffbrad Apr 17, 2019
aedc6de
Mark Material icon package private for now.
griffbrad Apr 12, 2019
2e2ba0d
Set Material icon license to Apache 2.0.
griffbrad Apr 12, 2019
c1d32c1
SVG sprite generation in material icons package.
griffbrad Apr 17, 2019
8b04283
Drop unnecessary "use strict" from Gruntfile.
griffbrad Apr 17, 2019
f2dc5b0
Copy Material icon sprite to public during build-static.
griffbrad Apr 17, 2019
dac08ce
Component for using a Material icon from the sprite and polyfilling w…
griffbrad Apr 17, 2019
6573c2c
Drop pragma.
griffbrad Apr 17, 2019
fd5fbba
Use classnames rather than manually filtering array.
griffbrad Apr 17, 2019
426e7a8
Switch to svgstore-cli rather than Grunt for sprite generation.
griffbrad Apr 17, 2019
cb90ef8
Use file-loader so we can cache bust the Material icons sprite.
griffbrad Apr 17, 2019
ced90eb
Fix files declaration in Material icons package.json that was causing…
griffbrad Apr 17, 2019
b89d362
Move svg4everybody usage to client/boot/polyfills.
griffbrad Apr 17, 2019
d065f98
Add MaterialIcons to the playground scope
blowery Apr 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/boot/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* External dependencies
*/
import '@babel/polyfill';
import svg4everybody from 'svg4everybody';

/**
* Internal dependencies
Expand All @@ -11,3 +12,9 @@ import '@babel/polyfill';
import localStoragePolyfill from 'lib/local-storage-polyfill';

localStoragePolyfill();

const isBrowser = typeof window !== 'undefined';
if ( isBrowser ) {
// Polyfill SVG external content support. Noop in the evergreen build.
svg4everybody();
}
42 changes: 42 additions & 0 deletions client/components/material-icon/index.jsx
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';
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@griffbrad griffbrad Apr 18, 2019

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

Copy link
Contributor

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 :)


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 );
1 change: 1 addition & 0 deletions client/devdocs/design/playground-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export JetpackLogo from 'components/jetpack-logo';
export LanguagePicker from 'components/language-picker';
export ListEnd from 'components/list-end';
export Main from 'components/main';
export MaterialIcon from 'components/material-icon';
export MarkedLines from 'components/marked-lines';
export Notices from 'components/notice';
export Pagination from 'components/pagination';
Expand Down
Loading