UNPKG

4.66 kBJavaScriptView Raw
1import _defineProperty from "@babel/runtime/helpers/defineProperty";
2import _extends from "@babel/runtime/helpers/extends";
3import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5import _createClass from "@babel/runtime/helpers/createClass";
6import _inherits from "@babel/runtime/helpers/inherits";
7import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
10function _createSuper(Derived) {
11 function isNativeReflectConstruct() {
12 if (typeof Reflect === "undefined" || !Reflect.construct) return false;
13 if (Reflect.construct.sham) return false;
14 if (typeof Proxy === "function") return true;
15
16 try {
17 Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
18 return true;
19 } catch (e) {
20 return false;
21 }
22 }
23
24 return function () {
25 var Super = _getPrototypeOf(Derived),
26 result;
27
28 if (isNativeReflectConstruct()) {
29 var NewTarget = _getPrototypeOf(this).constructor;
30
31 result = Reflect.construct(Super, arguments, NewTarget);
32 } else {
33 result = Super.apply(this, arguments);
34 }
35
36 return _possibleConstructorReturn(this, result);
37 };
38}
39
40import React, { Component } from 'react';
41import classNames from 'classnames';
42import { Size } from '../_util/enum';
43import LocaleReceiver from '../locale-provider/LocaleReceiver';
44import Select from '../select';
45import MiniSelect from './MiniSelect';
46import LargeSelect from './LargeSelect';
47import RcPagination from '../rc-components/pagination';
48import enUS from '../rc-components/pagination/locale/en_US';
49import Button from '../button/Button';
50import { getPrefixCls } from '../configure';
51
52function getSelect(size) {
53 switch (size) {
54 case Size.small:
55 return MiniSelect;
56
57 case Size.large:
58 return LargeSelect;
59
60 default:
61 return Select;
62 }
63}
64
65function getIcon(type) {
66 switch (type) {
67 case 'first':
68 return 'first_page';
69
70 case 'last':
71 return 'last_page';
72
73 case 'prev':
74 return 'navigate_before';
75
76 case 'next':
77 return 'navigate_next';
78
79 default:
80 }
81}
82
83function itemRender(page, type, item, disabled, size) {
84 if (page !== undefined) {
85 if (type === 'page' || type === 'jump-prev' || type === 'jump-next') {
86 return React.createElement(Button, {
87 size: size,
88 shape: "circle"
89 }, item);
90 }
91
92 return React.createElement(Button, {
93 size: size,
94 shape: "circle",
95 icon: getIcon(type),
96 disabled: disabled
97 });
98 }
99}
100
101var Pagination =
102/*#__PURE__*/
103function (_Component) {
104 _inherits(Pagination, _Component);
105
106 var _super = _createSuper(Pagination);
107
108 function Pagination() {
109 var _this;
110
111 _classCallCheck(this, Pagination);
112
113 _this = _super.apply(this, arguments);
114
115 _this.renderPagination = function (locale) {
116 var _this$props = _this.props,
117 className = _this$props.className,
118 size = _this$props.size,
119 customizePrefixCls = _this$props.prefixCls,
120 customizeSelectPrefixCls = _this$props.selectPrefixCls,
121 restProps = _objectWithoutProperties(_this$props, ["className", "size", "prefixCls", "selectPrefixCls"]);
122
123 var prefixCls = getPrefixCls('pagination', customizePrefixCls);
124 var selectPrefixCls = getPrefixCls('select', customizeSelectPrefixCls);
125 return React.createElement(RcPagination, _extends({}, restProps, {
126 selectPrefixCls: selectPrefixCls,
127 prefixCls: prefixCls,
128 size: size,
129 className: classNames(className, _defineProperty({}, "".concat(prefixCls, "-").concat(size), size)),
130 selectComponentClass: getSelect(size),
131 locale: locale
132 }));
133 };
134
135 return _this;
136 }
137
138 _createClass(Pagination, [{
139 key: "render",
140 value: function render() {
141 return React.createElement(LocaleReceiver, {
142 componentName: "Pagination",
143 defaultLocale: enUS
144 }, this.renderPagination);
145 }
146 }]);
147
148 return Pagination;
149}(Component);
150
151export { Pagination as default };
152Pagination.displayName = 'Pagination';
153Pagination.defaultProps = {
154 showSizeChanger: true,
155 showSizeChangerLabel: true,
156 tiny: true,
157 pageSizeOptions: ['10', '30', '50', '100', '200'],
158 showTotal: function showTotal(total, range) {
159 return "".concat(range[0], " - ").concat(range[1], " / ").concat(total);
160 },
161 sizeChangerOptionText: function sizeChangerOptionText(value) {
162 return value;
163 },
164 itemRender: itemRender
165};
166//# sourceMappingURL=Pagination.js.map