UNPKG

wix-style-react

Version:
83 lines (67 loc) 3.6 kB
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 DropdownLayout from 'wix-style-react/DropdownLayout'; var generateOption = function generateOption(id) { return { id: id, value: 'options ' + id }; }; var ExampleInfiniteScroll = function (_React$Component) { _inherits(ExampleInfiniteScroll, _React$Component); function ExampleInfiniteScroll(props) { _classCallCheck(this, ExampleInfiniteScroll); var _this = _possibleConstructorReturn(this, (ExampleInfiniteScroll.__proto__ || Object.getPrototypeOf(ExampleInfiniteScroll)).call(this, props)); _this.style = { display: 'inline-block', padding: '0 5px', width: '240px', lineHeight: '22px' }; _this.generateData = function () { var newOptions = []; for (var i = 0; i < _this.itemsPerPage; i++) { newOptions.push(generateOption(_this.state.data.length + i)); } _this.setState({ data: _this.state.data.concat(newOptions) }); }; _this.render = function () { return React.createElement( 'div', { style: _this.style }, React.createElement(DropdownLayout, { infiniteScroll: true, dataHook: 'infinite-scroll-dropdownLayout', visible: true, onSelect: function onSelect(item) { return alert(item.value + ' was selected!'); }, hasMore: _this.state.hasMore, loadMore: _this.loadMore, options: _this.state.data }) ); }; _this.loadMore = _this.loadMore.bind(_this); _this.itemsPerPage = 15; _this.total = 300; _this.state = { hasMore: true, data: [] }; return _this; } _createClass(ExampleInfiniteScroll, [{ key: 'loadMore', value: function loadMore() { var _this2 = this; var loadMoreData = function loadMoreData() { if (_this2.state.data.length >= _this2.total) { _this2.setState({ hasMore: false }); } else { _this2.generateData(); } }; setTimeout(loadMoreData, 500); } }]); return ExampleInfiniteScroll; }(React.Component); export { ExampleInfiniteScroll as default };