UNPKG

2.08 kBJavaScriptView Raw
1var __assign = this && this.__assign || function () {
2 __assign = Object.assign || function (t) {
3 for (var s, i = 1, n = arguments.length; i < n; i++) {
4 s = arguments[i];
5
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
7 }
8
9 return t;
10 };
11
12 return __assign.apply(this, arguments);
13};
14
15var __rest = this && this.__rest || function (s, e) {
16 var t = {};
17
18 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
19
20 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) t[p[i]] = s[p[i]];
21 return t;
22};
23
24import React from 'react';
25import { IconContext, DefaultContext } from './iconContext';
26
27function Tree2Element(tree) {
28 return tree && tree.map(function (node, i) {
29 return React.createElement(node.tag, __assign({
30 key: i
31 }, node.attr), Tree2Element(node.child));
32 });
33}
34
35export function GenIcon(data) {
36 return function (props) {
37 return React.createElement(IconBase, __assign({
38 attr: __assign({}, data.attr)
39 }, props), Tree2Element(data.child));
40 };
41}
42export function IconBase(props) {
43 var elem = function (conf) {
44 var computedSize = props.size || conf.size || "1em";
45 var className;
46 if (conf.className) className = conf.className;
47 if (props.className) className = (className + ' ' || '') + props.className;
48
49 var attr = props.attr,
50 svgProps = __rest(props, ["attr"]);
51
52 return React.createElement("svg", __assign({
53 stroke: "currentColor",
54 fill: "currentColor",
55 strokeWidth: "0"
56 }, conf.attr, attr, svgProps, {
57 className: className,
58 style: __assign({
59 color: props.color || conf.color
60 }, conf.style, props.style),
61 height: computedSize,
62 width: computedSize
63 }), props.children);
64 };
65
66 return IconContext !== undefined ? React.createElement(IconContext.Consumer, null, function (conf) {
67 return elem(conf);
68 }) : elem(DefaultContext);
69}
\No newline at end of file