zent
Version:
一套前端设计语言和基于React的实现
82 lines (81 loc) • 3.94 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { Component } from 'react';
import memoize from '../../utils/memorize-one';
import Select from '../../select';
import { I18nReceiver as Receiver } from '../../i18n';
var memoizedNormalizeSelectOptions = memoize(function normalizeSelectOptions(pageSizeOptions, i18n) {
return (pageSizeOptions || []).map(function (opt) {
if (typeof opt === 'number') {
return { key: opt, text: opt + " " + i18n.items };
}
return {
key: opt.value,
text: opt.text,
};
});
});
var Text = function (props) {
return (_jsx("span", __assign({ className: "zent-pagination-count--" + props.type, "data-zv": '10.0.17' }, { children: props.children }), void 0));
};
var PageSizeChanger = (function (_super) {
__extends(PageSizeChanger, _super);
function PageSizeChanger() {
return _super !== null && _super.apply(this, arguments) || this;
}
PageSizeChanger.prototype.render = function () {
var _a = this.props, total = _a.total, formatTotal = _a.formatTotal, pageSize = _a.pageSize, pageSizeOptions = _a.pageSizeOptions, onPageSizeChange = _a.onPageSizeChange;
if (!pageSizeOptions || pageSizeOptions.length === 0) {
return (_jsx(StaticPageSize, { total: total, formatTotal: formatTotal, pageSize: pageSize }, void 0));
}
var totalText = formatTotal ? formatTotal(total) : total;
return (_jsx(Receiver, __assign({ componentName: "Pagination" }, { children: function (i18n) {
var select = (_jsx(PageSizeSelect, { pageSizeOptions: pageSizeOptions, onPageSizeChange: onPageSizeChange, pageSize: pageSize, i18n: i18n }, void 0));
return (_jsx("div", __assign({ className: "zent-pagination-page-size-changer", "data-zv": '10.0.17' }, { children: i18n.pageStats({
select: select,
total: totalText,
Text: Text,
}) }), void 0));
} }), void 0));
};
return PageSizeChanger;
}(Component));
export default PageSizeChanger;
var PageSizeSelect = (function (_super) {
__extends(PageSizeSelect, _super);
function PageSizeSelect() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.onChange = function (_a) {
var key = _a.key;
_this.props.onPageSizeChange(key);
};
return _this;
}
PageSizeSelect.prototype.render = function () {
var _a = this.props, pageSize = _a.pageSize, i18n = _a.i18n, pageSizeOptions = _a.pageSizeOptions;
var options = memoizedNormalizeSelectOptions(pageSizeOptions, i18n);
return (_jsx(Select, { width: i18n.selectWidth, options: options, value: {
key: pageSize,
text: pageSize + " " + i18n.items,
}, onChange: this.onChange }, void 0));
};
return PageSizeSelect;
}(Component));
var StaticPageSize = (function (_super) {
__extends(StaticPageSize, _super);
function StaticPageSize() {
return _super !== null && _super.apply(this, arguments) || this;
}
StaticPageSize.prototype.render = function () {
var _a = this.props, total = _a.total, formatTotal = _a.formatTotal, pageSize = _a.pageSize;
var totalText = formatTotal ? formatTotal(total) : total;
return (_jsx(Receiver, __assign({ componentName: "Pagination" }, { children: function (i18n) {
return (_jsx("div", __assign({ className: "zent-pagination-page-size-changer", "data-zv": '10.0.17' }, { children: i18n.pageStatsStatic({
total: totalText,
pageSize: pageSize,
Text: Text,
}) }), void 0));
} }), void 0));
};
return StaticPageSize;
}(Component));