Customized.js 2.0 KB

12345678910111213141516171819202122232425262728293031
  1. var _excluded = ["component"];
  2. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  3. 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; }
  4. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
  5. /**
  6. * @fileOverview Customized
  7. */
  8. import React, { isValidElement, cloneElement, createElement } from 'react';
  9. import isFunction from 'lodash/isFunction';
  10. import { Layer } from '../container/Layer';
  11. import { warn } from '../util/LogUtils';
  12. /**
  13. * custom svg elements by rechart instance props and state.
  14. * @returns {Object} svg elements
  15. */
  16. export function Customized(_ref) {
  17. var component = _ref.component,
  18. props = _objectWithoutProperties(_ref, _excluded);
  19. var child;
  20. if ( /*#__PURE__*/isValidElement(component)) {
  21. child = /*#__PURE__*/cloneElement(component, props);
  22. } else if (isFunction(component)) {
  23. child = /*#__PURE__*/createElement(component, props);
  24. } else {
  25. warn(false, "Customized's props `component` must be React.element or Function, but got %s.", _typeof(component));
  26. }
  27. return /*#__PURE__*/React.createElement(Layer, {
  28. className: "recharts-customized-wrapper"
  29. }, child);
  30. }
  31. Customized.displayName = 'Customized';