wix-style-react
Version:
wix-style-react
110 lines (95 loc) • 4.42 kB
JavaScript
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; }; }();
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; }
import React from 'react';
import DataTable from 'wix-style-react/DataTable';
var style = {
width: '966px'
};
var baseData = [{ firstName: 'Meghan', lastName: 'Bishop' }, { firstName: 'Sara', lastName: 'Porter' }, { firstName: 'Deborah', lastName: 'Rhodes' }, { firstName: 'Walter', lastName: 'Jenning' }];
var generateData = function generateData(count) {
var data = [];
for (var i = 0; i < count; i++) {
data = data.concat(baseData);
}
return data;
};
var DataTableExample = function (_React$Component) {
_inherits(DataTableExample, _React$Component);
function DataTableExample(props) {
_classCallCheck(this, DataTableExample);
var _this = _possibleConstructorReturn(this, (DataTableExample.__proto__ || Object.getPrototypeOf(DataTableExample)).call(this, props));
_this.state = { hasMore: true, count: 5 };
_this.loadMore = _this.loadMore.bind(_this);
return _this;
}
_createClass(DataTableExample, [{
key: 'loadMore',
value: function loadMore() {
var _this2 = this;
var loadMoreData = function loadMoreData() {
_this2.setState({ count: _this2.state.count + 5 });
if (_this2.state.count > 20) {
_this2.setState({ hasMore: false });
}
};
setTimeout(loadMoreData, 3000);
}
}, {
key: 'render',
value: function render() {
return React.createElement(
'div',
{ style: style },
React.createElement(DataTable, {
dataHook: 'story-data-table-infinite-scroll',
data: generateData(this.state.count),
onRowClick: function onRowClick(row, rowNum) {
/*eslint-disable no-alert*/
window.alert('You clicked "' + row.firstName + ' ' + row.lastName + '", row number ' + (rowNum + 1));
/*eslint-enable no-alert*/
},
infiniteScroll: true,
newDesign: true,
itemsPerPage: 20,
columns: [{
title: 'Row Number',
render: function render(row, rowNum) {
return '#' + (rowNum + 1);
},
width: '20%',
minWidth: '75px',
important: true
}, {
title: 'First Name',
render: function render(row) {
return React.createElement(
'span',
null,
row.firstName
);
},
width: '40%',
minWidth: '100px'
}, {
title: 'Last Name',
render: function render(row) {
return React.createElement(
'span',
null,
row.lastName
);
},
width: '40%',
minWidth: '100px'
}],
hasMore: this.state.hasMore,
loadMore: this.loadMore
})
);
}
}]);
return DataTableExample;
}(React.Component);
export default DataTableExample;