Skip to content

Instantly share code, notes, and snippets.

@joshdcomp
Last active August 18, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshdcomp/d1d6da875434b825e0d092946e738251 to your computer and use it in GitHub Desktop.
Save joshdcomp/d1d6da875434b825e0d092946e738251 to your computer and use it in GitHub Desktop.
ES16 ReactJS Generic Icon component for use with SVG sprites
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