Skip to content

Instantly share code, notes, and snippets.

@nparsons08 nparsons08/Icon.js Secret forked from LukeSmetham/Icon.js
Created Sep 24, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.