2017-11-17 14:38:54 +08:00
|
|
|
import * as 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';
|
2016-03-31 17:46:35 +08:00
|
|
|
import MiniSelect from './MiniSelect';
|
2018-08-21 17:13:12 +08:00
|
|
|
import Icon from '../icon';
|
2018-12-05 19:12:18 +08:00
|
|
|
import Select from '../select';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
2016-03-31 17:46:35 +08:00
|
|
|
|
2016-08-15 12:00:05 +08:00
|
|
|
export interface PaginationProps {
|
2017-11-21 13:48:37 +08:00
|
|
|
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-11-21 13:48:37 +08:00
|
|
|
onChange?: (page: number, pageSize?: number) => void;
|
2017-12-29 20:14:53 +08:00
|
|
|
hideOnSinglePage?: boolean;
|
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;
|
2019-02-14 22:39:11 +08:00
|
|
|
showQuickJumper?: boolean | { goButton?: React.ReactNode };
|
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;
|
2018-12-07 20:02:01 +08:00
|
|
|
itemRender?: (
|
|
|
|
page: number,
|
|
|
|
type: 'page' | 'prev' | 'next' | 'jump-prev' | 'jump-next',
|
|
|
|
originalElement: HTMLElement,
|
|
|
|
) => React.ReactNode;
|
2018-07-27 15:14:20 +08:00
|
|
|
role?: string;
|
2016-08-15 12:00:05 +08:00
|
|
|
}
|
|
|
|
|
2018-05-21 21:52:18 +08:00
|
|
|
export interface PaginationConfig extends PaginationProps {
|
|
|
|
position?: 'top' | 'bottom' | 'both';
|
|
|
|
}
|
|
|
|
|
2017-11-21 15:37:39 +08:00
|
|
|
export type PaginationLocale = any;
|
|
|
|
|
|
|
|
export default class Pagination extends React.Component<PaginationProps, {}> {
|
2018-12-05 19:12:18 +08:00
|
|
|
getIconsProps = (prefixCls: string) => {
|
2018-08-21 17:13:12 +08:00
|
|
|
const prevIcon = (
|
|
|
|
<a className={`${prefixCls}-item-link`}>
|
2018-08-22 20:01:00 +08:00
|
|
|
<Icon type="left" />
|
2018-08-21 17:13:12 +08:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
const nextIcon = (
|
|
|
|
<a className={`${prefixCls}-item-link`}>
|
2018-08-22 20:01:00 +08:00
|
|
|
<Icon type="right" />
|
2018-08-21 17:13:12 +08:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
const jumpPrevIcon = (
|
|
|
|
<a className={`${prefixCls}-item-link`}>
|
2018-08-22 20:01:00 +08:00
|
|
|
{/* You can use transition effects in the container :) */}
|
|
|
|
<div className={`${prefixCls}-item-container`}>
|
2018-12-07 20:02:01 +08:00
|
|
|
<Icon className={`${prefixCls}-item-link-icon`} type="double-left" />
|
2018-08-22 20:01:00 +08:00
|
|
|
<span className={`${prefixCls}-item-ellipsis`}>•••</span>
|
|
|
|
</div>
|
2018-08-21 17:13:12 +08:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
const jumpNextIcon = (
|
|
|
|
<a className={`${prefixCls}-item-link`}>
|
2018-08-22 20:01:00 +08:00
|
|
|
{/* You can use transition effects in the container :) */}
|
|
|
|
<div className={`${prefixCls}-item-container`}>
|
2018-12-07 20:02:01 +08:00
|
|
|
<Icon className={`${prefixCls}-item-link-icon`} type="double-right" />
|
2018-08-22 20:01:00 +08:00
|
|
|
<span className={`${prefixCls}-item-ellipsis`}>•••</span>
|
|
|
|
</div>
|
2018-08-21 17:13:12 +08:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
prevIcon,
|
|
|
|
nextIcon,
|
|
|
|
jumpPrevIcon,
|
|
|
|
jumpNextIcon,
|
|
|
|
};
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2018-08-21 17:13:12 +08:00
|
|
|
|
2018-06-21 12:00:09 +08:00
|
|
|
renderPagination = (contextLocale: PaginationLocale) => {
|
2018-12-05 19:12:18 +08:00
|
|
|
const {
|
2018-12-07 20:02:01 +08:00
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
selectPrefixCls: customizeSelectPrefixCls,
|
|
|
|
className,
|
|
|
|
size,
|
|
|
|
locale: customLocale,
|
2018-12-05 19:12:18 +08:00
|
|
|
...restProps
|
|
|
|
} = this.props;
|
2018-06-21 12:00:09 +08:00
|
|
|
const locale = { ...contextLocale, ...customLocale };
|
2017-03-17 15:23:25 +08:00
|
|
|
const isSmall = size === 'small';
|
2016-03-31 17:46:35 +08:00
|
|
|
return (
|
2018-12-05 19:12:18 +08:00
|
|
|
<ConfigConsumer>
|
|
|
|
{({ getPrefixCls }: ConfigConsumerProps) => {
|
|
|
|
const prefixCls = getPrefixCls('pagination', customizePrefixCls);
|
|
|
|
const selectPrefixCls = getPrefixCls('select', customizeSelectPrefixCls);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<RcPagination
|
|
|
|
{...restProps}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
selectPrefixCls={selectPrefixCls}
|
|
|
|
{...this.getIconsProps(prefixCls)}
|
|
|
|
className={classNames(className, { mini: isSmall })}
|
|
|
|
selectComponentClass={isSmall ? MiniSelect : Select}
|
|
|
|
locale={locale}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</ConfigConsumer>
|
2016-03-31 17:46:35 +08:00
|
|
|
);
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2017-03-17 15:23:25 +08:00
|
|
|
|
2017-10-20 14:54:38 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2018-12-07 20:02:01 +08:00
|
|
|
<LocaleReceiver componentName="Pagination" defaultLocale={enUS}>
|
2017-10-20 14:54:38 +08:00
|
|
|
{this.renderPagination}
|
|
|
|
</LocaleReceiver>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|