UNPKG

2.31 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13var __rest = (this && this.__rest) || function (s, e) {
14 var t = {};
15 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16 t[p] = s[p];
17 if (s != null && typeof Object.getOwnPropertySymbols === "function")
18 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
19 t[p[i]] = s[p[i]];
20 return t;
21};
22Object.defineProperty(exports, "__esModule", { value: true });
23var React = require("react");
24var iconContext_1 = require("./iconContext");
25function Tree2Element(tree) {
26 return tree && tree.map(function (node, i) { return React.createElement(node.tag, __assign({ key: i }, node.attr), Tree2Element(node.child)); });
27}
28function GenIcon(data) {
29 return function (props) { return (React.createElement(IconBase, __assign({ attr: __assign({}, data.attr) }, props), Tree2Element(data.child))); };
30}
31exports.GenIcon = GenIcon;
32function IconBase(props) {
33 var elem = function (conf) {
34 var computedSize = props.size || conf.size || "1em";
35 var className;
36 if (conf.className)
37 className = conf.className;
38 if (props.className)
39 className = (className + ' ' || '') + props.className;
40 var attr = props.attr, svgProps = __rest(props, ["attr"]);
41 return (React.createElement("svg", __assign({ stroke: "currentColor", fill: "currentColor", strokeWidth: "0" }, conf.attr, attr, svgProps, { className: className, style: __assign({ color: props.color || conf.color }, conf.style, props.style), height: computedSize, width: computedSize }), props.children));
42 };
43 return iconContext_1.IconContext !== undefined
44 ? React.createElement(iconContext_1.IconContext.Consumer, null, function (conf) { return elem(conf); })
45 : elem(iconContext_1.DefaultContext);
46}
47exports.IconBase = IconBase;