Created
February 23, 2018 17:17
-
-
Save nhusher/867c3e6424173cb3abaf410f0580e49a 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
export class Icon extends PureComponent { | |
constructor (...args) { | |
super(...args) | |
this.ref = node => { this.node = node } | |
} | |
applyFill () { | |
if (!this.node) return | |
const fill = this.props.fill | |
Array.from(this.node.querySelectorAll('path')).forEach(path => { | |
if (fill) { | |
path.setAttribute('fill', this.props.fill) | |
} else { | |
path.removeAttribute('fill') | |
} | |
}) | |
} | |
componentDidMount () { | |
this.applyFill() | |
} | |
componentDidUpdate () { | |
this.applyFill() | |
} | |
render () { | |
const { name } = this.props | |
if (!ICONS[name]) return null | |
return <span | |
dangerouslySetInnerHTML={{ __html: ICONS[name] }} | |
/> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment