2016-09-21 11:54:53 +08:00
|
|
|
import React from 'react';
|
2016-03-31 17:46:35 +08:00
|
|
|
import RcPagination from 'rc-pagination';
|
2017-09-26 23:12:47 +08:00
|
|
|
import enUS from 'rc-pagination/lib/locale/en_US';
|
2017-03-17 15:23:25 +08:00
|
|
|
import classNames from 'classnames';
|
2017-10-20 14:54:38 +08:00
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2016-03-31 17:46:35 +08:00
|
|
|
import Select from '../select';
|
|
|
|
import MiniSelect from './MiniSelect';
|
|
|
|
|
2016-08-15 12:00:05 +08:00
|
|
|
export interface PaginationProps {
|
|
|
|
total: number;
|
2017-03-17 15:23:25 +08:00
|
|
|
defaultCurrent?: number;
|
|
|
|
current?: number;
|
2016-08-15 12:00:05 +08:00
|
|
|
defaultPageSize?: number;
|
|
|
|
pageSize?: number;
|
2017-02-10 22:59:46 +08:00
|
|
|
onChange?: (page: number, pageSize: number) => void;
|
2016-08-15 12:00:05 +08:00
|
|
|
showSizeChanger?: boolean;
|
2017-03-17 15:23:25 +08:00
|
|
|
pageSizeOptions?: string[];
|
2016-08-15 12:00:05 +08:00
|
|
|
onShowSizeChange?: (current: number, size: number) => void;
|
|
|
|
showQuickJumper?: boolean;
|
2017-08-02 13:03:42 +08:00
|
|
|
showTotal?: (total: number, range: [number, number]) => React.ReactNode;
|
2016-08-15 12:00:05 +08:00
|
|
|
size?: string;
|
2017-03-06 15:48:03 +08:00
|
|
|
simple?: boolean;
|
2016-08-15 12:00:05 +08:00
|
|
|
style?: React.CSSProperties;
|
|
|
|
locale?: Object;
|
2017-03-17 15:23:25 +08:00
|
|
|
className?: string;
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls?: string;
|
|
|
|
selectPrefixCls?: string;
|
2017-07-06 19:17:36 +08:00
|
|
|
itemRender?: (page: number, type: 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next') => React.ReactNode;
|
2016-08-15 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2017-10-20 14:54:38 +08:00
|
|
|
export default class Pagination extends React.Component<PaginationProps, any> {
|
2016-03-31 17:46:35 +08:00
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-pagination',
|
2016-09-14 16:18:33 +08:00
|
|
|
selectPrefixCls: 'ant-select',
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-31 17:46:35 +08:00
|
|
|
|
2017-10-20 14:54:38 +08:00
|
|
|
renderPagination = (locale) => {
|
2017-03-17 15:23:25 +08:00
|
|
|
const { className, size, ...restProps } = this.props;
|
|
|
|
const isSmall = size === 'small';
|
2016-03-31 17:46:35 +08:00
|
|
|
return (
|
2016-11-23 17:53:10 +08:00
|
|
|
<RcPagination
|
2017-03-17 15:23:25 +08:00
|
|
|
{...restProps}
|
|
|
|
className={classNames(className, { mini: isSmall })}
|
|
|
|
selectComponentClass={isSmall ? MiniSelect : Select}
|
2016-03-31 17:46:35 +08:00
|
|
|
locale={locale}
|
2016-06-06 13:54:10 +08:00
|
|
|
/>
|
2016-03-31 17:46:35 +08:00
|
|
|
);
|
|
|
|
}
|
2017-03-17 15:23:25 +08:00
|
|
|
|
2017-10-20 14:54:38 +08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<LocaleReceiver
|
|
|
|
componentName="Pagination"
|
|
|
|
defaultLocale={enUS}
|
|
|
|
>
|
|
|
|
{this.renderPagination}
|
|
|
|
</LocaleReceiver>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|