Skip to content

Instantly share code, notes, and snippets.

@LukeSmetham
Created September 20, 2019 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LukeSmetham/864bafcffc7ac3cec81bf68e3926fc2b to your computer and use it in GitHub Desktop.
Save LukeSmetham/864bafcffc7ac3cec81bf68e3926fc2b to your computer and use it in GitHub Desktop.
import React, { cloneElement } from 'react';
import PropTypes from 'prop-types';
import { withTheme } from 'styled-components';
const Icon = ({ children, className, color, onClick, theme, size, viewBox, style }) => {
return (
<svg className={className} width={size} height={size} viewBox={viewBox} style={style} onClick={onClick}>
{cloneElement(children, { fill: theme.color[color] })}
</svg>
);
};
Icon.propTypes = {
className: PropTypes.string.isRequired,
color: PropTypes.string.isRequired,
size: PropTypes.number.isRequired,
style: PropTypes.object,
theme: PropTypes.object.isRequired,
viewBox: PropTypes.string.isRequired,
};
Icon.defaultProps = {
color: 'text',
size: 24,
viewBox: '0 0 24 24',
};
export default withTheme(Icon);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment