192 lines
7.8 KiB
JavaScript
192 lines
7.8 KiB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
|
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
|
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
|
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
|
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
|
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
|
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
|
|
/* eslint react/prop-types: 0 */
|
|
import React from 'react';
|
|
import KEYCODE from './KeyCode';
|
|
|
|
var Options = /*#__PURE__*/function (_React$Component) {
|
|
_inherits(Options, _React$Component);
|
|
|
|
var _super = _createSuper(Options);
|
|
|
|
function Options() {
|
|
var _this;
|
|
|
|
_classCallCheck(this, Options);
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
_this.state = {
|
|
goInputText: ''
|
|
};
|
|
|
|
_this.buildOptionText = function (value) {
|
|
return "".concat(value, " ").concat(_this.props.locale.items_per_page);
|
|
};
|
|
|
|
_this.changeSize = function (value) {
|
|
_this.props.changeSize(Number(value));
|
|
};
|
|
|
|
_this.handleChange = function (e) {
|
|
_this.setState({
|
|
goInputText: e.target.value
|
|
});
|
|
};
|
|
|
|
_this.handleBlur = function (e) {
|
|
var _this$props = _this.props,
|
|
goButton = _this$props.goButton,
|
|
quickGo = _this$props.quickGo,
|
|
rootPrefixCls = _this$props.rootPrefixCls;
|
|
|
|
if (goButton) {
|
|
return;
|
|
}
|
|
|
|
if (e.relatedTarget && (e.relatedTarget.className.indexOf("".concat(rootPrefixCls, "-prev")) >= 0 || e.relatedTarget.className.indexOf("".concat(rootPrefixCls, "-next")) >= 0)) {
|
|
return;
|
|
}
|
|
|
|
quickGo(_this.getValidValue());
|
|
};
|
|
|
|
_this.go = function (e) {
|
|
var goInputText = _this.state.goInputText;
|
|
|
|
if (goInputText === '') {
|
|
return;
|
|
}
|
|
|
|
if (e.keyCode === KEYCODE.ENTER || e.type === 'click') {
|
|
_this.setState({
|
|
goInputText: ''
|
|
});
|
|
|
|
_this.props.quickGo(_this.getValidValue());
|
|
}
|
|
};
|
|
|
|
return _this;
|
|
}
|
|
|
|
_createClass(Options, [{
|
|
key: "getValidValue",
|
|
value: function getValidValue() {
|
|
var _this$state = this.state,
|
|
goInputText = _this$state.goInputText,
|
|
current = _this$state.current; // eslint-disable-next-line no-restricted-globals
|
|
|
|
return !goInputText || isNaN(goInputText) ? current : Number(goInputText);
|
|
}
|
|
}, {
|
|
key: "render",
|
|
value: function render() {
|
|
var _this2 = this;
|
|
|
|
var _this$props2 = this.props,
|
|
pageSize = _this$props2.pageSize,
|
|
pageSizeOptions = _this$props2.pageSizeOptions,
|
|
locale = _this$props2.locale,
|
|
rootPrefixCls = _this$props2.rootPrefixCls,
|
|
changeSize = _this$props2.changeSize,
|
|
quickGo = _this$props2.quickGo,
|
|
goButton = _this$props2.goButton,
|
|
selectComponentClass = _this$props2.selectComponentClass,
|
|
buildOptionText = _this$props2.buildOptionText,
|
|
selectPrefixCls = _this$props2.selectPrefixCls,
|
|
disabled = _this$props2.disabled;
|
|
var goInputText = this.state.goInputText;
|
|
var prefixCls = "".concat(rootPrefixCls, "-options");
|
|
var Select = selectComponentClass;
|
|
var changeSelect = null;
|
|
var goInput = null;
|
|
var gotoButton = null;
|
|
|
|
if (!changeSize && !quickGo) {
|
|
return null;
|
|
}
|
|
|
|
if (changeSize && Select) {
|
|
var options = pageSizeOptions.map(function (opt, i) {
|
|
return /*#__PURE__*/React.createElement(Select.Option, {
|
|
key: i,
|
|
value: opt
|
|
}, (buildOptionText || _this2.buildOptionText)(opt));
|
|
});
|
|
changeSelect = /*#__PURE__*/React.createElement(Select, {
|
|
disabled: disabled,
|
|
prefixCls: selectPrefixCls,
|
|
showSearch: false,
|
|
className: "".concat(prefixCls, "-size-changer"),
|
|
optionLabelProp: "children",
|
|
dropdownMatchSelectWidth: false,
|
|
value: (pageSize || pageSizeOptions[0]).toString(),
|
|
onChange: this.changeSize,
|
|
getPopupContainer: function getPopupContainer(triggerNode) {
|
|
return triggerNode.parentNode;
|
|
}
|
|
}, options);
|
|
}
|
|
|
|
if (quickGo) {
|
|
if (goButton) {
|
|
gotoButton = typeof goButton === 'boolean' ? /*#__PURE__*/React.createElement("button", {
|
|
type: "button",
|
|
onClick: this.go,
|
|
onKeyUp: this.go,
|
|
disabled: disabled
|
|
}, locale.jump_to_confirm) : /*#__PURE__*/React.createElement("span", {
|
|
onClick: this.go,
|
|
onKeyUp: this.go
|
|
}, goButton);
|
|
}
|
|
|
|
goInput = /*#__PURE__*/React.createElement("div", {
|
|
className: "".concat(prefixCls, "-quick-jumper")
|
|
}, locale.jump_to, /*#__PURE__*/React.createElement("input", {
|
|
disabled: disabled,
|
|
type: "text",
|
|
value: goInputText,
|
|
onChange: this.handleChange,
|
|
onKeyUp: this.go,
|
|
onBlur: this.handleBlur
|
|
}), locale.page, gotoButton);
|
|
}
|
|
|
|
return /*#__PURE__*/React.createElement("li", {
|
|
className: "".concat(prefixCls)
|
|
}, changeSelect, goInput);
|
|
}
|
|
}]);
|
|
|
|
return Options;
|
|
}(React.Component);
|
|
|
|
Options.defaultProps = {
|
|
pageSizeOptions: ['10', '20', '50', '100']
|
|
};
|
|
export default Options; |