UNPKG

3.46 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6
7var _class, _temp2;
8
9import React from 'react';
10import { findDOMNode } from 'react-dom';
11import PropTypes from 'prop-types';
12import BodyComponent from '../base/body';
13
14/* eslint-disable react/prefer-stateless-function */
15var FixedBody = (_temp2 = _class = function (_React$Component) {
16 _inherits(FixedBody, _React$Component);
17
18 function FixedBody() {
19 var _temp, _this, _ret;
20
21 _classCallCheck(this, FixedBody);
22
23 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
24 args[_key] = arguments[_key];
25 }
26
27 return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.onBodyScroll = function (event) {
28 var onFixedScrollSync = _this.context.onFixedScrollSync;
29 // sync scroll left to header
30
31 onFixedScrollSync && onFixedScrollSync(event);
32
33 // sync scroll top/left to lock columns
34 if ('onLockScroll' in _this.props && typeof _this.props.onLockScroll === 'function') {
35 _this.props.onLockScroll(event);
36 }
37 }, _temp), _possibleConstructorReturn(_this, _ret);
38 }
39
40 FixedBody.prototype.componentDidMount = function componentDidMount() {
41 var getNode = this.context.getNode;
42
43 getNode && getNode('body', findDOMNode(this));
44 };
45
46 FixedBody.prototype.render = function render() {
47 /*eslint-disable no-unused-vars */
48 var _props = this.props,
49 className = _props.className,
50 colGroup = _props.colGroup,
51 onLockScroll = _props.onLockScroll,
52 tableWidth = _props.tableWidth,
53 others = _objectWithoutProperties(_props, ['className', 'colGroup', 'onLockScroll', 'tableWidth']);
54
55 var _context = this.context,
56 maxBodyHeight = _context.maxBodyHeight,
57 fixedHeader = _context.fixedHeader;
58
59 var style = {};
60 if (fixedHeader) {
61 style.maxHeight = maxBodyHeight;
62 style.position = 'relative';
63 }
64 return React.createElement(
65 'div',
66 {
67 style: style,
68 className: className,
69 onScroll: this.onBodyScroll
70 },
71 React.createElement(
72 'table',
73 { style: { width: tableWidth } },
74 colGroup,
75 React.createElement(BodyComponent, _extends({}, others, { colGroup: colGroup }))
76 )
77 );
78 };
79
80 return FixedBody;
81}(React.Component), _class.propTypes = {
82 children: PropTypes.any,
83 prefix: PropTypes.string,
84 className: PropTypes.string,
85 colGroup: PropTypes.any,
86 onLockScroll: PropTypes.func,
87 tableWidth: PropTypes.number
88}, _class.contextTypes = {
89 fixedHeader: PropTypes.bool,
90 maxBodyHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
91 onFixedScrollSync: PropTypes.func,
92 getNode: PropTypes.func
93}, _temp2);
94FixedBody.displayName = 'FixedBody';
95export { FixedBody as default };
\No newline at end of file