Created
April 22, 2018 11:14
-
-
Save stasgavrylov/39c4f003d3f0f119750e12209017e3fa to your computer and use it in GitHub Desktop.
React SVG wrapper component
This file contains 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
svg { | |
fill: white; | |
stroke: currentColor; | |
} |
This file contains 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 from 'react'; | |
import classNames from 'classnames'; | |
import './SvgIcon.css'; | |
export class SvgIcon extends React.Component { | |
static defaultProps = { | |
icon: '', | |
width: 16, | |
height: 16, | |
strokeWidth: 24, | |
}; | |
render() { | |
const { className, icon, ...attrs } = this.props; | |
return ( | |
<svg className={classNames('svg-icon', className, icon)} | |
{...attrs} | |
> | |
<use xlinkHref={`/icons.svg#${icon}`} /> | |
</svg> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment