UNPKG

react-biz

Version:

React components for Business

80 lines (68 loc) 1.82 kB
import React, {Component, PropTypes} from 'react'; import transitions from '../styles/transitions'; class SvgIcon extends Component { static muiName = 'SvgIcon'; static propTypes = { /** * Elements passed into the SVG Icon. */ children: PropTypes.node, color: PropTypes.string, hoverColor: PropTypes.string, onMouseEnter: PropTypes.func, onMouseLeave: PropTypes.func, style: PropTypes.object, viewBox: PropTypes.string }; static defaultProps = { onMouseEnter: () => {}, onMouseLeave: () => {}, viewBox: '0 0 24 24' }; state = { hovered: false }; handleMouseLeave = (event) => { this.setState({hovered: false}); this.props.onMouseLeave(event); }; handleMouseEnter = (event) => { this.setState({hovered: true}); this.props.onMouseEnter(event); }; render () { const { children, color, hoverColor, onMouseEnter, // eslint-disable-line no-unused-vars onMouseLeave, // eslint-disable-line no-unused-vars style, viewBox, ...other } = this.props; const offColor = color ? color : 'currentColor'; const onColor = hoverColor ? hoverColor : offColor; const mergedStyles = Object.assign({ display: 'inline-block', color: '#00000', fill: this.state.hovered ? onColor : offColor, height: 24, width: 24, userSelect: 'none', transition: transitions.easeOut() }, style); return ( <svg {...other} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave} style={mergedStyles} viewBox={viewBox} > {children} </svg> ); } } export default SvgIcon;