choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
229 lines (196 loc) • 6.25 kB
JavaScript
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 _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) {
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;
}
}
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);
};
}
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import KEYCODE from './KeyCode';
var BUILT_IN_PLACEMENTS = {
bottomLeft: {
points: ['tl', 'tl'],
offset: [0, 0],
overflow: {
adjustX: 0,
adjustY: 1
}
},
topLeft: {
points: ['bl', 'tl'],
offset: [0, -4],
overflow: {
adjustX: 0,
adjustY: 1
}
},
bottomRight: {
points: ['tr', 'br'],
offset: [0, 4],
overflow: {
adjustX: 0,
adjustY: 1
}
}
};
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 React.createElement(Option, {
key: i,
value: opt
}, buildOptionText(opt));
});
changeSelect = React.createElement(Select, {
prefixCls: props.selectPrefixCls,
showSearch: false,
className: "".concat(prefixCls, "-size-changer"),
optionLabelProp: "children",
dropdownMatchSelectWidth: false,
value: pageSize.toString(),
onChange: this.changeSize,
builtinPlacements: BUILT_IN_PLACEMENTS,
getPopupContainer: function getPopupContainer(triggerNode) {
return triggerNode.parentNode;
},
border: false
}, options);
}
if (quickGo) {
if (goButton) {
if (typeof goButton === 'boolean') {
gotoButton = React.createElement("button", {
type: "button",
onClick: this.go,
onKeyUp: this.go
}, locale.jump_to_confirm);
} else {
gotoButton = React.createElement("span", {
onClick: this.go,
onKeyUp: this.go
}, goButton);
}
}
goInput = React.createElement("div", {
className: "".concat(prefixCls, "-quick-jumper")
}, locale.jump_to, React.createElement("input", {
type: "text",
value: state.goInputText,
onChange: this.handleChange,
onKeyUp: this.go
}), locale.page, gotoButton);
}
if (props.changeSizeLabel) {
label = React.createElement("span", {
className: "".concat(prefixCls, "-label")
}, locale.label_items_per_page);
}
return React.createElement("li", {
className: "".concat(prefixCls)
}, label, changeSelect, goInput);
}
}]);
return Options;
}(Component);
_defineProperty(Options, "propTypes", {
changeSize: PropTypes.func,
quickGo: PropTypes.func,
selectComponentClass: PropTypes.func,
current: PropTypes.number,
pageSizeOptions: PropTypes.arrayOf(PropTypes.string),
pageSize: PropTypes.number,
buildOptionText: PropTypes.func,
locale: PropTypes.object
});
_defineProperty(Options, "defaultProps", {
pageSizeOptions: ['10', '20', '30', '40']
});
export { Options as default };
//# sourceMappingURL=Options.js.map