Last active
August 18, 2016 15:37
-
-
Save joshdcomp/d1d6da875434b825e0d092946e738251 to your computer and use it in GitHub Desktop.
ES16 ReactJS Generic Icon component for use with SVG sprites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
export default class Icon extends Component { | |
fullName(href='') { | |
return `#${href}_icon-${this.props.glyph}`; | |
} | |
render() { | |
const { glyph } = this.props; | |
let wrapperClasses = [ | |
'_icon', | |
'_icon-' + glyph, | |
this.props.className | |
]; | |
return ( | |
<svg className={wrapperClasses.join(' ')}> | |
<use xlinkHref={this.fullName()} /> | |
</svg> | |
) | |
} | |
} | |
Icon.defaultProps = { | |
glyph: '', | |
className: '', | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment