iconBase.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.GenIcon = GenIcon;
  6. exports.IconBase = IconBase;
  7. var _react = _interopRequireDefault(require("react"));
  8. var _iconContext = require("./iconContext");
  9. var _excluded = ["attr", "size", "title"];
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  12. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  13. function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  14. function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
  15. function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
  16. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  17. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
  18. function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  19. function Tree2Element(tree) {
  20. return tree && tree.map((node, i) => /*#__PURE__*/_react.default.createElement(node.tag, _objectSpread({
  21. key: i
  22. }, node.attr), Tree2Element(node.child)));
  23. }
  24. function GenIcon(data) {
  25. // eslint-disable-next-line react/display-name
  26. return props => /*#__PURE__*/_react.default.createElement(IconBase, _extends({
  27. attr: _objectSpread({}, data.attr)
  28. }, props), Tree2Element(data.child));
  29. }
  30. function IconBase(props) {
  31. var elem = conf => {
  32. var {
  33. attr,
  34. size,
  35. title
  36. } = props,
  37. svgProps = _objectWithoutProperties(props, _excluded);
  38. var computedSize = size || conf.size || "1em";
  39. var className;
  40. if (conf.className) className = conf.className;
  41. if (props.className) className = (className ? className + " " : "") + props.className;
  42. return /*#__PURE__*/_react.default.createElement("svg", _extends({
  43. stroke: "currentColor",
  44. fill: "currentColor",
  45. strokeWidth: "0"
  46. }, conf.attr, attr, svgProps, {
  47. className: className,
  48. style: _objectSpread(_objectSpread({
  49. color: props.color || conf.color
  50. }, conf.style), props.style),
  51. height: computedSize,
  52. width: computedSize,
  53. xmlns: "http://www.w3.org/2000/svg"
  54. }), title && /*#__PURE__*/_react.default.createElement("title", null, title), props.children);
  55. };
  56. return _iconContext.IconContext !== undefined ? /*#__PURE__*/_react.default.createElement(_iconContext.IconContext.Consumer, null, conf => elem(conf)) : elem(_iconContext.DefaultContext);
  57. }