Skip to content

Instantly share code, notes, and snippets.

@nhusher
Created February 23, 2018 17:17
Show Gist options
  • Save nhusher/867c3e6424173cb3abaf410f0580e49a to your computer and use it in GitHub Desktop.
Save nhusher/867c3e6424173cb3abaf410f0580e49a to your computer and use it in GitHub Desktop.
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