@alifd/next
Version:
A configurable component library for web built on React.
121 lines (109 loc) • 4.57 kB
JavaScript
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _class, _temp2;
import React from 'react';
import { findDOMNode } from 'react-dom';
import PropTypes from 'prop-types';
import BodyComponent from '../base/body';
/* eslint-disable react/prefer-stateless-function */
var VirtualBody = (_temp2 = _class = function (_React$Component) {
_inherits(VirtualBody, _React$Component);
function VirtualBody() {
var _temp, _this, _ret;
_classCallCheck(this, VirtualBody);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.tableRef = function (table) {
_this.tableNode = table;
}, _this.virtualScrollRef = function (virtualScroll) {
_this.virtualScrollNode = virtualScroll;
}, _this.onScroll = function (current) {
// for fixed
_this.context.onFixedScrollSync(current);
// for lock
_this.context.onLockBodyScroll(current);
// for virtual
_this.context.onVirtualScroll();
}, _temp), _possibleConstructorReturn(_this, _ret);
}
VirtualBody.prototype.componentDidMount = function componentDidMount() {
var bodyNode = findDOMNode(this);
// // for fixed
this.context.getNode('body', bodyNode);
// for virtual
this.context.getBodyNode(bodyNode, this.context.lockType);
// for lock
this.context.getLockNode('body', bodyNode, this.context.lockType);
};
VirtualBody.prototype.render = function render() {
var _props = this.props,
prefix = _props.prefix,
className = _props.className,
colGroup = _props.colGroup,
tableWidth = _props.tableWidth,
others = _objectWithoutProperties(_props, ['prefix', 'className', 'colGroup', 'tableWidth']);
var _context = this.context,
maxBodyHeight = _context.maxBodyHeight,
bodyHeight = _context.bodyHeight,
innerTop = _context.innerTop;
var style = {
width: tableWidth
};
var wrapperStyle = {
position: 'relative'
};
// todo 2.0 ,这里最好自己画滚动条
if (bodyHeight > maxBodyHeight) {
wrapperStyle.height = bodyHeight;
}
return React.createElement(
'div',
{ style: { maxHeight: maxBodyHeight }, className: className, onScroll: this.onScroll },
React.createElement(
'div',
{ style: wrapperStyle, ref: this.virtualScrollRef },
React.createElement(
'div',
{
style: {
position: 'relative',
transform: 'translateY(' + innerTop + 'px)',
willChange: 'transform'
}
},
React.createElement(
'table',
{ ref: this.tableRef, style: style },
colGroup,
React.createElement(BodyComponent, _extends({}, others, { prefix: prefix }))
)
)
)
);
};
return VirtualBody;
}(React.Component), _class.propTypes = {
children: PropTypes.any,
prefix: PropTypes.string,
className: PropTypes.string,
colGroup: PropTypes.any,
tableWidth: PropTypes.number
}, _class.contextTypes = {
maxBodyHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
onBodyScroll: PropTypes.func,
onFixedScrollSync: PropTypes.func,
onVirtualScroll: PropTypes.func,
onLockBodyScroll: PropTypes.func,
bodyHeight: PropTypes.number,
innerTop: PropTypes.number,
getNode: PropTypes.func,
getBodyNode: PropTypes.func,
getLockNode: PropTypes.func,
lockType: PropTypes.oneOf(['left', 'right'])
}, _temp2);
VirtualBody.displayName = 'VirtualBody';
export { VirtualBody as default };