react-native-icomoon
Version:
Icomoon icon compatible
60 lines (52 loc) • 1.52 kB
JavaScript
import React, { useMemo } from 'react'; //@ts-ignore
import { Svg, Path } from 'react-native-svg';
const IconMoon = ({
iconSet,
size = 32,
color = '#222',
name,
offset = 0,
strokeWidth = 1
}) => {
if (!iconSet || !name) {
console.error('The "iconSet" and "name" props are required.');
return null;
}
const viewBoxMax = 1024;
const localOffset = offset / 2 * -viewBoxMax;
const offsetedViewBox = viewBoxMax - localOffset; // eslint-disable-next-line react-hooks/rules-of-hooks
const currentIcon = useMemo(() => {
return iconSet.icons.map(i => {
return {
name: i.properties.name,
paths: i.icon.paths
};
}).find(i => {
return i.name === name;
});
}, [iconSet, name]);
if (currentIcon === undefined) {
console.error("Icon \"".concat(name, "\" not found."));
return null;
}
const paths = currentIcon.paths.map((p, i) => /*#__PURE__*/React.createElement(Path, {
key: String(i),
d: p,
strokeWidth: 5 * strokeWidth,
stroke: color
}));
return /*#__PURE__*/React.createElement(Svg, {
width: String(size),
height: String(size),
fill: color,
viewBox: "".concat(localOffset, " ").concat(localOffset, " ").concat(offsetedViewBox, " ").concat(offsetedViewBox)
}, paths);
};
export function iconList(iconSet) {
if (iconSet && Array.isArray(iconSet.icons)) {
return iconSet.icons.map(icon => icon.properties.name);
}
return null;
}
export default IconMoon;
//# sourceMappingURL=index.js.map