UNPKG

@data-ui/xy-chart

Version:

A package of charts with standard x- and y- axes. https://williaster.github.io/data-ui

54 lines (42 loc) 2.33 kB
function _extends() { _extends = Object.assign || 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); } 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; } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } /* * example usage: * const XYChartWithTheme = withTheme(theme)(XYChart); */ import React from 'react'; import { chartTheme as defaultTheme } from '@data-ui/theme'; import updateDisplayName from '../utils/updateDisplayName'; function withTheme(theme) { if (theme === void 0) { theme = defaultTheme; } return function withThemeHOC(WrappedComponent) { // use a class for ref-ability and for PureComponent optimization // eslint-disable-next-line react/prefer-stateless-function var EnhancedComponent = /*#__PURE__*/ function (_React$PureComponent) { _inheritsLoose(EnhancedComponent, _React$PureComponent); function EnhancedComponent() { return _React$PureComponent.apply(this, arguments) || this; } var _proto = EnhancedComponent.prototype; _proto.render = function render() { var _this$props = this.props, componentTheme = _this$props.theme, restProps = _objectWithoutPropertiesLoose(_this$props, ["theme"]); return React.createElement(WrappedComponent, _extends({}, restProps, { theme: _extends({}, theme, componentTheme) })); }; return EnhancedComponent; }(React.PureComponent); EnhancedComponent.propTypes = WrappedComponent.propTypes || {}; EnhancedComponent.defaultProps = WrappedComponent.defaultProps || {}; updateDisplayName(WrappedComponent, EnhancedComponent, 'withTheme'); return EnhancedComponent; }; } export default withTheme;