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 14 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
48 changes: 48 additions & 0 deletions client/components/material-icon/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import svg4everybody from 'svg4everybody';

const isBrowser = typeof window !== 'undefined';
if ( isBrowser ) {
griffbrad marked this conversation as resolved.
Show resolved Hide resolved
// Polyfill SVG external content support. Noop in the evergreen build.
svg4everybody();
}

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 svgPath = `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={ `/calypso/images/material-design-icons/material-icons.svg#${ svgPath }` } />
griffbrad marked this conversation as resolved.
Show resolved Hide resolved
</svg>
);
}

MaterialIcon.propTypes = {
icon: PropTypes.string.isRequired,
style: PropTypes.string,
size: PropTypes.number,
onClick: PropTypes.func,
className: PropTypes.string,
};

export default React.memo( MaterialIcon );
Loading