Last active
October 17, 2018 07:10
-
-
Save kalyantm/297b88d6ee5d9837044ca2c5e3f8a357 to your computer and use it in GitHub Desktop.
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
<Icon fileType="svg" icon="check" alt="check icon" /> |
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
class Icon extends React.PureComponent<Props, {}> { | |
render() { | |
const { fileType, size, gtmClass, alt, icon } = this.props; | |
const isSvg = fileType === 'svg'; | |
const file = require(`../../resources/icons/${icon}.${ | |
isSvg ? 'svg' : 'png' | |
}`); | |
console.log('file is', file); | |
const svgElement = isSvg ? ( | |
<div className={cStyles('icon', size, gtmClass)}> | |
{ | |
<svg viewBox="0 0 60 60"> | |
<use xlinkHref={`#${file.url}`} /> | |
</svg> | |
} | |
</div> | |
) : ( | |
<img | |
className={cStyles('icon', size, gtmClass)} | |
alt={alt || ''} | |
src={file} | |
/> | |
); | |
return svgElement || null; | |
} | |
} | |
export default Icon; |
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
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin'); | |
const plugins = [, | |
....., | |
new SpriteLoaderPlugin(), | |
]; |
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
.... | |
{ | |
test: /\.svg$/, | |
loader: 'svg-sprite-loader', | |
options: { | |
extract: true, | |
}, | |
}, | |
.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment