huge-table
Version:
Table component to handle huge sets of data, based on Facebook's FixedDataTable
100 lines (76 loc) • 4.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _ZyngaScroller = require('./ZyngaScroller');
var _ZyngaScroller2 = _interopRequireDefault(_ZyngaScroller);
var _TouchableArea = require('./TouchableArea');
var _TouchableArea2 = _interopRequireDefault(_TouchableArea);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _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; }
function _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 ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var TouchWrapper = function (_React$Component) {
_inherits(TouchWrapper, _React$Component);
function TouchWrapper(props) {
_classCallCheck(this, TouchWrapper);
var _this = _possibleConstructorReturn(this, (TouchWrapper.__proto__ || Object.getPrototypeOf(TouchWrapper)).call(this, props));
_this.state = {
left: 0,
top: 0,
initialized: false
};
_this.onScroll = function (scrollLeft, scrollTop) {
if (_this.state.initialized) {
_this.props.onScroll(scrollLeft, scrollTop);
} else {
_this.setState({
initialized: true
});
}
};
return _this;
}
_createClass(TouchWrapper, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.scroller = new _ZyngaScroller2.default(this.onScroll);
this.scroller.setDimensions(this.props.tableWidth, this.props.tableHeight, this.props.contentWidth, this.props.contentHeight);
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var diffTableWidth = nextProps.tableWidth !== this.props.tableWidth;
var diffTableHeight = nextProps.tableHeight !== this.props.tableHeight;
var diffContentWidth = nextProps.contentWidth !== this.props.contentWidth;
var diffContentHeight = nextProps.contentHeight !== this.props.contentHeight;
if (this.scroller && (diffTableWidth || diffTableHeight || diffContentWidth || diffContentHeight)) {
this.scroller.setDimensions(nextProps.tableWidth, nextProps.tableHeight, nextProps.contentWidth, nextProps.contentHeight);
}
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement(
_TouchableArea2.default,
{ scroller: this.scroller },
this.props.children
);
}
}]);
return TouchWrapper;
}(_react2.default.Component);
TouchWrapper.propTypes = {
tableWidth: _propTypes2.default.number.isRequired,
tableHeight: _propTypes2.default.number.isRequired,
contentWidth: _propTypes2.default.number,
contentHeight: _propTypes2.default.number,
onScroll: _propTypes2.default.func.isRequired,
children: _propTypes2.default.any
};
exports.default = TouchWrapper;