UNPKG

3.46 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _assign2 = require('lodash/assign');
8
9var _assign3 = _interopRequireDefault(_assign2);
10
11var _isObject2 = require('lodash/isObject');
12
13var _isObject3 = _interopRequireDefault(_isObject2);
14
15var _linkClass = require('./linkClass');
16
17var _linkClass2 = _interopRequireDefault(_linkClass);
18
19var _react = require('react');
20
21var _react2 = _interopRequireDefault(_react);
22
23var _hoistNonReactStatics = require('hoist-non-react-statics');
24
25var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
26
27function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
29function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
30
31function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
32
33function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
34
35function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? _defaults(subClass, superClass) : _defaults(subClass, superClass); } /* eslint-disable react/prop-types */
36
37/**
38 * @param {ReactClass} Component
39 * @param {Object} defaultStyles
40 * @param {Object} options
41 * @returns {ReactClass}
42 */
43
44exports.default = function (Component, defaultStyles, options) {
45 var WrappedComponent = undefined;
46
47 WrappedComponent = function (_Component) {
48 _inherits(WrappedComponent, _Component);
49
50 function WrappedComponent() {
51 _classCallCheck(this, WrappedComponent);
52
53 return _possibleConstructorReturn(this, _Component.apply(this, arguments));
54 }
55
56 WrappedComponent.prototype.render = function render() {
57 var renderResult = undefined,
58 styles = undefined;
59
60 if (this.props.styles) {
61 styles = this.props.styles;
62 } else if ((0, _isObject3.default)(defaultStyles)) {
63 this.props = (0, _assign3.default)({}, this.props, {
64 styles: defaultStyles
65 });
66
67 styles = defaultStyles;
68 } else {
69 styles = {};
70 }
71
72 renderResult = _Component.prototype.render.call(this);
73
74 if (renderResult) {
75 return (0, _linkClass2.default)(renderResult, styles, options);
76 }
77
78 return _react2.default.createElement('noscript');
79 };
80
81 return WrappedComponent;
82 }(Component);
83
84 return (0, _hoistNonReactStatics2.default)(WrappedComponent, Component);
85};
86
87module.exports = exports['default'];
88//# sourceMappingURL=extendReactClass.js.map