UNPKG

acud

Version:

acg react 组件库

76 lines • 2.93 kB
/** * @file pagination/rc-pagination/Options * @author chenyaqiu */ import React from 'react'; ; var defaultPageSizeOptions = ['10', '20', '50', '100']; var Options = function Options(_ref) { var _ref$pageSizeOptions = _ref.pageSizeOptions, pageSizeOptions = _ref$pageSizeOptions === void 0 ? defaultPageSizeOptions : _ref$pageSizeOptions, changeSize = _ref.changeSize, pageSize = _ref.pageSize, rootPrefixCls = _ref.rootPrefixCls, selectComponentClass = _ref.selectComponentClass, buildOptionText = _ref.buildOptionText, selectPrefixCls = _ref.selectPrefixCls, disabled = _ref.disabled, Option = _ref.Option, locale = _ref.locale; var prefixCls = "".concat(rootPrefixCls, "-options"); var Select = selectComponentClass; var handleBuildOptionText = React.useCallback(function (value) { return "".concat(value); }, []); buildOptionText = React.useCallback(function (value) { return "".concat(value, " ").concat(locale.items_per_page); }, [locale]); var handleChangeSize = React.useCallback(function (value) { changeSize(Number(value)); }, [changeSize]); var curPageSizeOptions = React.useMemo(function () { if (pageSizeOptions.some(function (option) { return option.toString() === pageSize.toString(); })) { return pageSizeOptions; } return pageSizeOptions.concat([pageSize.toString()]).sort(function (a, b) { // eslint-disable-next-line no-restricted-globals var numberA = isNaN(Number(a)) ? 0 : Number(a); // eslint-disable-next-line no-restricted-globals var numberB = isNaN(Number(b)) ? 0 : Number(b); return numberA - numberB; }); }, [pageSize, pageSizeOptions]); var changeSelect = React.useMemo(function () { if (changeSize && Select) { var options = curPageSizeOptions.map(function (opt) { return /*#__PURE__*/React.createElement(Option, { key: opt.toString(), value: opt.toString() }, (buildOptionText || handleBuildOptionText)(opt)); }); return /*#__PURE__*/React.createElement(Select, { disabled: disabled, prefixCls: selectPrefixCls, showSearch: false, className: "".concat(prefixCls, "-size-changer"), optionLabelProp: "children", dropdownMatchSelectWidth: false, value: (pageSize || curPageSizeOptions[0]).toString(), onChange: handleChangeSize, getPopupContainer: function getPopupContainer(triggerNode) { return triggerNode.parentNode; } }, options); } return null; }, [Select, buildOptionText, changeSize, handleChangeSize, disabled, pageSize, curPageSizeOptions, handleBuildOptionText, prefixCls, selectPrefixCls, Option]); if (!changeSize || !Select) { return null; } return /*#__PURE__*/React.createElement("li", { className: "".concat(prefixCls) }, changeSelect); }; export default Options;