preact-icomoon
Version:
It makes it very simple to use SVG icons in your Preact projects.
61 lines • 2.81 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.iconList = void 0;
var preact_1 = require("preact");
var IcoMoon = function (_a) {
var iconSet = _a.iconSet, icon = _a.icon, size = _a.size, title = _a.title, disableFill = _a.disableFill, removeInlineStyle = _a.removeInlineStyle, props = __rest(_a, ["iconSet", "icon", "size", "title", "disableFill", "removeInlineStyle"]);
if (!iconSet || !icon)
return null;
var currentIcon = iconSet.icons.find(function (item) { return item.properties.name === icon; });
if (!currentIcon)
return null;
var initialStyle = {
display: "inline-block",
stroke: "currentColor",
fill: "currentColor",
};
var comptuedStyle = __assign(__assign(__assign({}, (removeInlineStyle ? {} : initialStyle)), (size ? { width: size, height: size } : {})), (props.style || {}));
var _b = currentIcon.icon.width, width = _b === void 0 ? "1024" : _b;
var viewBox = "0 0 ".concat(width, " 1024");
var children = currentIcon.icon.paths.map(function (path, index) {
var _a;
var attrs = (_a = currentIcon.icon.attrs) === null || _a === void 0 ? void 0 : _a[index];
var pathProps = __assign({ d: path, key: icon + index }, (!disableFill && attrs ? attrs : {}));
return (0, preact_1.createElement)("path", pathProps);
});
if (title) {
children.push((0, preact_1.createElement)("title", { key: title }, title));
}
// @ts-ignore [TODO]: Fix this!
return (0, preact_1.createElement)("svg", __assign(__assign({}, props), { viewBox: viewBox, style: comptuedStyle }), children);
};
var iconList = function (iconSet) {
if (!iconSet || !Array.isArray(iconSet.icons))
return null;
return iconSet.icons.map(function (icon) { return icon.properties.name; });
};
exports.iconList = iconList;
exports.default = IcoMoon;
//# sourceMappingURL=index.js.map