choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
153 lines (129 loc) • 4.65 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _extends from "@babel/runtime/helpers/extends";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
var _excluded = ["className", "size", "locale", "prefixCls", "selectPrefixCls", "selectProps"];
import React, { Component } from 'react';
import classNames from 'classnames';
import { Size } from '../_util/enum';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import Select from '../select';
import MiniSelect from './MiniSelect';
import LargeSelect from './LargeSelect';
import RcPagination from '../rc-components/pagination';
import enUS from '../rc-components/pagination/locale/en_US';
import Button from '../button/Button';
import ConfigContext from '../config-provider/ConfigContext';
function getSelect(size) {
switch (size) {
case Size.small:
return MiniSelect;
case Size.large:
return LargeSelect;
default:
return Select;
}
}
function getIcon(type) {
switch (type) {
case 'first':
return 'first_page';
case 'last':
return 'last_page';
case 'prev':
return 'navigate_before';
case 'next':
return 'navigate_next';
default:
}
}
function itemRender(page, type, item, disabled, size) {
if (page !== undefined) {
if (type === 'page' || type === 'jump-prev' || type === 'jump-next') {
return /*#__PURE__*/React.createElement(Button, {
size: size,
shape: "circle"
}, item);
}
return /*#__PURE__*/React.createElement(Button, {
size: size,
shape: "circle",
icon: getIcon(type),
disabled: disabled
});
}
}
var Pagination = /*#__PURE__*/function (_Component) {
_inherits(Pagination, _Component);
var _super = _createSuper(Pagination);
function Pagination() {
var _this;
_classCallCheck(this, Pagination);
_this = _super.apply(this, arguments);
_this.renderPagination = function (contextLocale) {
var _this$props = _this.props,
className = _this$props.className,
size = _this$props.size,
customLocale = _this$props.locale,
customizePrefixCls = _this$props.prefixCls,
customizeSelectPrefixCls = _this$props.selectPrefixCls,
_this$props$selectPro = _this$props.selectProps,
selectProps = _this$props$selectPro === void 0 ? {} : _this$props$selectPro,
restProps = _objectWithoutProperties(_this$props, _excluded);
var _this$context = _this.context,
getPrefixCls = _this$context.getPrefixCls,
getConfig = _this$context.getConfig;
var prefixCls = getPrefixCls('pagination', customizePrefixCls);
selectProps.prefixCls = selectProps.prefixCls || getPrefixCls('select', customizeSelectPrefixCls);
var locale = _objectSpread(_objectSpread({}, contextLocale), customLocale);
var isSmall = size === Size.small;
var pageProps = getConfig('pagination');
return /*#__PURE__*/React.createElement(RcPagination, _extends({}, pageProps, restProps, {
selectProps: selectProps,
prefixCls: prefixCls,
size: size,
className: classNames(className, _defineProperty({}, "".concat(prefixCls, "-").concat(size), size), {
mini: isSmall
}),
selectComponentClass: getSelect(size),
locale: locale
}));
};
return _this;
}
_createClass(Pagination, [{
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement(LocaleReceiver, {
componentName: "Pagination",
defaultLocale: enUS
}, this.renderPagination);
}
}], [{
key: "contextType",
get: function get() {
return ConfigContext;
}
}]);
return Pagination;
}(Component);
export { Pagination as default };
Pagination.displayName = 'Pagination';
Pagination.defaultProps = {
showSizeChanger: true,
showSizeChangerLabel: true,
tiny: true,
pageSizeOptions: ['10', '30', '50', '100', '200'],
showTotal: function showTotal(total, range) {
return "".concat(range[0], " - ").concat(range[1], " / ").concat(total);
},
sizeChangerOptionText: function sizeChangerOptionText(value) {
return value;
},
itemRender: itemRender
};
//# sourceMappingURL=Pagination.js.map