UNPKG

react-native-icomoon

Version:
75 lines (62 loc) 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.iconList = iconList; exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNativeSvg = require("react-native-svg"); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } //@ts-ignore 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 = (0, _react.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.default.createElement(_reactNativeSvg.Path, { key: String(i), d: p, strokeWidth: 5 * strokeWidth, stroke: color })); return /*#__PURE__*/_react.default.createElement(_reactNativeSvg.Svg, { width: String(size), height: String(size), fill: color, viewBox: "".concat(localOffset, " ").concat(localOffset, " ").concat(offsetedViewBox, " ").concat(offsetedViewBox) }, paths); }; function iconList(iconSet) { if (iconSet && Array.isArray(iconSet.icons)) { return iconSet.icons.map(icon => icon.properties.name); } return null; } var _default = IconMoon; exports.default = _default; //# sourceMappingURL=index.js.map