@mmbt/react-web-vector-icons
Version:
An adaptation of react-native-vector-icons for react web
47 lines (39 loc) • 959 B
JavaScript
import React, { Component } from 'react';
export default function createIconSet(glyphMap, fontFamily) {
class Icon extends Component {
render() {
const props = this.props;
let glyph = props.name ? glyphMap[props.name] || '?' : '';
if (typeof glyph === 'number') {
glyph = String.fromCodePoint(glyph);
}
let style = _([
style = {
},
props.color ? {color: props.color} : null,
props.size ? {fontSize: props.size} : null,
props.style,
{
fontFamily: fontFamily,
fontWeight: 'normal',
fontStyle: 'normal',
}
]);
return (
<i style={style} className={props.className}>
{glyph}
</i>
);
}
}
return Icon;
}
const _ = styles => {
if(!styles) return {};
if(styles.length){
let temp = {};
styles.map(i => Object.assign(temp, i));
return temp;
}
return styles;
};