choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
156 lines (131 loc) • 4.73 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React, { Component } from 'react';
import KEYCODE from './KeyCode';
var Options = /*#__PURE__*/function (_Component) {
_inherits(Options, _Component);
var _super = _createSuper(Options);
function Options(props) {
var _this;
_classCallCheck(this, Options);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "buildOptionText", function (value) {
return "".concat(value, " ").concat(_this.props.locale.items_per_page);
});
_defineProperty(_assertThisInitialized(_this), "changeSize", function (value) {
_this.props.changeSize(Number(value));
});
_defineProperty(_assertThisInitialized(_this), "handleChange", function (e) {
_this.setState({
goInputText: e.target.value
});
});
_defineProperty(_assertThisInitialized(_this), "go", function (e) {
var val = _this.state.goInputText;
if (val === '') {
return;
}
val = Number(val);
if (isNaN(val)) {
val = _this.state.current;
}
if (e.keyCode === KEYCODE.ENTER || e.type === 'click') {
_this.setState({
goInputText: '',
current: _this.props.quickGo(val)
});
}
});
_this.state = {
current: props.current,
goInputText: ''
};
return _this;
}
_createClass(Options, [{
key: "render",
value: function render() {
var props = this.props;
var state = this.state;
var locale = props.locale;
var prefixCls = "".concat(props.rootPrefixCls, "-options");
var changeSize = props.changeSize;
var quickGo = props.quickGo;
var goButton = props.goButton;
var buildOptionText = props.buildOptionText || this.buildOptionText;
var Select = props.selectComponentClass;
var changeSelect = null;
var goInput = null;
var gotoButton = null;
var label = null;
if (!(changeSize || quickGo)) {
return null;
}
if (changeSize && Select) {
var Option = Select.Option;
var pageSize = props.pageSize || props.pageSizeOptions[0];
var options = props.pageSizeOptions.map(function (opt, i) {
return /*#__PURE__*/React.createElement(Option, {
key: i,
value: opt
}, buildOptionText(opt));
});
changeSelect = /*#__PURE__*/React.createElement(Select, _extends({}, props.selectProps, {
showSearch: false,
className: "".concat(prefixCls, "-size-changer"),
optionLabelProp: "children",
dropdownMatchSelectWidth: false,
value: pageSize.toString(),
onChange: this.changeSize,
getPopupContainer: function getPopupContainer(triggerNode) {
return triggerNode.parentNode;
},
border: false
}), options);
}
if (quickGo) {
if (goButton) {
if (typeof goButton === 'boolean') {
gotoButton = /*#__PURE__*/React.createElement("button", {
type: "button",
onClick: this.go,
onKeyUp: this.go
}, locale.jump_to_confirm);
} else {
gotoButton = /*#__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", {
type: "text",
value: state.goInputText,
onChange: this.handleChange,
onKeyUp: this.go
}), locale.page, gotoButton);
}
if (props.changeSizeLabel) {
label = /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-label")
}, locale.label_items_per_page);
}
return /*#__PURE__*/React.createElement("li", {
className: "".concat(prefixCls)
}, label, changeSelect, goInput);
}
}]);
return Options;
}(Component);
_defineProperty(Options, "defaultProps", {
pageSizeOptions: ['10', '20', '30', '40']
});
export { Options as default };
//# sourceMappingURL=Options.js.map