1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import Header from './fixed/header';
|
9 | import StickyHeader from './sticky/header';
|
10 | import { statics } from './util';
|
11 |
|
12 | export default function sticky(BaseComponent) {
|
13 | var _class, _temp2;
|
14 |
|
15 |
|
16 | var StickyTable = (_temp2 = _class = function (_React$Component) {
|
17 | _inherits(StickyTable, _React$Component);
|
18 |
|
19 | function StickyTable() {
|
20 | var _temp, _this, _ret;
|
21 |
|
22 | _classCallCheck(this, StickyTable);
|
23 |
|
24 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
25 | args[_key] = arguments[_key];
|
26 | }
|
27 |
|
28 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {}, _temp), _possibleConstructorReturn(_this, _ret);
|
29 | }
|
30 |
|
31 | StickyTable.prototype.getChildContext = function getChildContext() {
|
32 | return {
|
33 | Header: this.props.components.Header || Header,
|
34 | offsetTop: this.props.offsetTop,
|
35 | affixProps: this.props.affixProps
|
36 | };
|
37 | };
|
38 |
|
39 | StickyTable.prototype.render = function render() {
|
40 |
|
41 | var _props = this.props,
|
42 | stickyHeader = _props.stickyHeader,
|
43 | offsetTop = _props.offsetTop,
|
44 | affixProps = _props.affixProps,
|
45 | others = _objectWithoutProperties(_props, ['stickyHeader', 'offsetTop', 'affixProps']);
|
46 |
|
47 | var _props2 = this.props,
|
48 | components = _props2.components,
|
49 | maxBodyHeight = _props2.maxBodyHeight,
|
50 | fixedHeader = _props2.fixedHeader;
|
51 |
|
52 | if (stickyHeader) {
|
53 | components = _extends({}, components);
|
54 | components.Header = StickyHeader;
|
55 | fixedHeader = true;
|
56 | maxBodyHeight = Math.max(maxBodyHeight, 10000);
|
57 | }
|
58 | return React.createElement(BaseComponent, _extends({}, others, {
|
59 | components: components,
|
60 | fixedHeader: fixedHeader,
|
61 | maxBodyHeight: maxBodyHeight
|
62 | }));
|
63 | };
|
64 |
|
65 | return StickyTable;
|
66 | }(React.Component), _class.StickyHeader = StickyHeader, _class.propTypes = _extends({
|
67 | |
68 |
|
69 |
|
70 | stickyHeader: PropTypes.bool,
|
71 | |
72 |
|
73 |
|
74 | offsetTop: PropTypes.number,
|
75 | |
76 |
|
77 |
|
78 | affixProps: PropTypes.object,
|
79 | components: PropTypes.object
|
80 | }, BaseComponent.propTypes), _class.defaultProps = _extends({
|
81 | components: {}
|
82 | }, BaseComponent.defaultProps), _class.childContextTypes = {
|
83 | Header: PropTypes.any,
|
84 | offsetTop: PropTypes.number,
|
85 | affixProps: PropTypes.object
|
86 | }, _temp2);
|
87 | StickyTable.displayName = 'StickyTable';
|
88 |
|
89 | statics(StickyTable, BaseComponent);
|
90 | return StickyTable;
|
91 | } |
\ | No newline at end of file |