substance
Version:
Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing systems.
41 lines (34 loc) • 838 B
JavaScript
import { forEach } from '../util'
import FontAwesomeIcon from './FontAwesomeIcon'
class FontAwesomeIconProvider {
constructor(icons) {
this.faMap = {}
this.textMap = {}
forEach(icons, function(config, name) {
let faClass = config['fontawesome']
if (faClass) {
this.addFAIcon(name, faClass)
}
let text = config['text']
if (text) {
this.addTextIcon(name, text)
}
}.bind(this))
}
renderIcon($$, name) {
let faClass = this.faMap[name]
let text = this.textMap[name]
if (faClass) {
return $$(FontAwesomeIcon, { icon: faClass })
} else if (text) {
return text
}
}
addFAIcon(name, faClass) {
this.faMap[name] = faClass
}
addTextIcon(name, text) {
this.textMap[name] = text
}
}
export default FontAwesomeIconProvider