import _defineProperty from 'babel-runtime/helpers/defineProperty'; import _extends from 'babel-runtime/helpers/extends'; import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _createClass from 'babel-runtime/helpers/createClass'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import React from 'react'; import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import classNames from 'classnames'; import ListView from './ListView'; import { getOffsetTop, _event } from './util'; function setDocumentScrollTop(val) { window.document.body.scrollTop = val; // chrome61 is invalid window.document.documentElement.scrollTop = val; } /* eslint react/prop-types: 0 */ var IndexedList = function (_React$Component) { _inherits(IndexedList, _React$Component); function IndexedList(props) { _classCallCheck(this, IndexedList); var _this = _possibleConstructorReturn(this, (IndexedList.__proto__ || Object.getPrototypeOf(IndexedList)).call(this, props)); _initialiseProps.call(_this); _this.state = { pageSize: props.pageSize, _delay: false }; return _this; } _createClass(IndexedList, [{ key: 'componentDidMount', value: function componentDidMount() { this.dataChange(this.props); // handle quickSearchBar this.getQsInfo(); } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if (this.props.dataSource !== nextProps.dataSource) { this.dataChange(nextProps); } } }, { key: 'componentDidUpdate', value: function componentDidUpdate() { this.getQsInfo(); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { if (this._timer) { clearTimeout(this._timer); } this._hCache = null; } }, { key: 'renderQuickSearchBar', value: function renderQuickSearchBar(quickSearchBarTop, quickSearchBarStyle) { var _this2 = this; var _props = this.props, dataSource = _props.dataSource, prefixCls = _props.prefixCls; var sectionKvs = dataSource.sectionIdentities.map(function (i) { return { value: i, label: dataSource._getSectionHeaderData(dataSource._dataBlob, i) }; }); return React.createElement( 'ul', { ref: function ref(el) { return _this2.quickSearchBarRef = el; }, className: prefixCls + '-quick-search-bar', style: quickSearchBarStyle, onTouchStart: this.onTouchStart, onTouchMove: this.onTouchMove, onTouchEnd: this.onTouchEnd, onTouchCancel: this.onTouchEnd }, React.createElement( 'li', { 'data-qf-target': quickSearchBarTop.value, onClick: function onClick() { return _this2.onQuickSearchTop(undefined, quickSearchBarTop.value); } }, quickSearchBarTop.label ), sectionKvs.map(function (i) { return React.createElement( 'li', { key: i.value, 'data-qf-target': i.value, onClick: function onClick() { return _this2.onQuickSearch(i.value); } }, i.label ); }) ); } }, { key: 'render', value: function render() { var _this3 = this, _classNames; var _state = this.state, _delay = _state._delay, pageSize = _state.pageSize; var _props2 = this.props, className = _props2.className, prefixCls = _props2.prefixCls, children = _props2.children, quickSearchBarTop = _props2.quickSearchBarTop, quickSearchBarStyle = _props2.quickSearchBarStyle, _props2$initialListSi = _props2.initialListSize, initialListSize = _props2$initialListSi === undefined ? Math.min(20, this.props.dataSource.getRowCount()) : _props2$initialListSi, showQuickSearchIndicator = _props2.showQuickSearchIndicator, _renderSectionHeader = _props2.renderSectionHeader, sectionHeaderClassName = _props2.sectionHeaderClassName, other = _objectWithoutProperties(_props2, ['className', 'prefixCls', 'children', 'quickSearchBarTop', 'quickSearchBarStyle', 'initialListSize', 'showQuickSearchIndicator', 'renderSectionHeader', 'sectionHeaderClassName']); // initialListSize={this.props.dataSource.getRowCount()} return React.createElement( 'div', { className: prefixCls + '-container' }, _delay && this.props.delayActivityIndicator, React.createElement( ListView, _extends({}, other, { ref: function ref(el) { return _this3.indexedListViewRef = el; }, className: classNames(prefixCls, className), initialListSize: initialListSize, pageSize: pageSize, renderSectionHeader: function renderSectionHeader(sectionData, sectionID) { return React.cloneElement(_renderSectionHeader(sectionData, sectionID), { ref: function ref(c) { return _this3.sectionComponents[sectionID] = c; }, className: sectionHeaderClassName || prefixCls + '-section-header' }); } }), children ), this.renderQuickSearchBar(quickSearchBarTop, quickSearchBarStyle), showQuickSearchIndicator ? React.createElement('div', { className: classNames((_classNames = {}, _defineProperty(_classNames, prefixCls + '-qsindicator', true), _defineProperty(_classNames, prefixCls + '-qsindicator-hide', !showQuickSearchIndicator || !this.state.showQuickSearchIndicator), _classNames)), ref: function ref(el) { return _this3.qsIndicatorRef = el; } }) : null ); } }]); return IndexedList; }(React.Component); IndexedList.propTypes = _extends({}, ListView.propTypes, { children: PropTypes.any, prefixCls: PropTypes.string, className: PropTypes.string, sectionHeaderClassName: PropTypes.string, quickSearchBarTop: PropTypes.object, quickSearchBarStyle: PropTypes.object, onQuickSearch: PropTypes.func, showQuickSearchIndicator: PropTypes.bool }); IndexedList.defaultProps = { prefixCls: 'rmc-indexed-list', quickSearchBarTop: { value: '#', label: '#' }, onQuickSearch: function onQuickSearch() {}, showQuickSearchIndicator: false, delayTime: 100, // delayActivityIndicator: