ant-design/components/pagination/Pagination.tsx

116 lines
3.2 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2016-03-31 17:46:35 +08:00
import RcPagination from 'rc-pagination';
import enUS from 'rc-pagination/lib/locale/en_US';
import classNames from 'classnames';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
2016-03-31 17:46:35 +08:00
import Select from '../select';
import MiniSelect from './MiniSelect';
2018-08-21 17:13:12 +08:00
import Icon from '../icon';
2016-03-31 17:46:35 +08:00
export interface PaginationProps {
2017-11-21 13:48:37 +08:00
total?: number;
defaultCurrent?: number;
current?: number;
defaultPageSize?: number;
pageSize?: number;
2017-11-21 13:48:37 +08:00
onChange?: (page: number, pageSize?: number) => void;
hideOnSinglePage?: boolean;
showSizeChanger?: boolean;
pageSizeOptions?: string[];
onShowSizeChange?: (current: number, size: number) => void;
showQuickJumper?: boolean;
2017-08-02 13:03:42 +08:00
showTotal?: (total: number, range: [number, number]) => React.ReactNode;
size?: string;
simple?: boolean;
style?: React.CSSProperties;
locale?: Object;
className?: string;
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;
role?: string;
}
export interface PaginationConfig extends PaginationProps {
position?: 'top' | 'bottom' | 'both';
}
export type PaginationLocale = any;
export default class Pagination extends React.Component<PaginationProps, {}> {
2016-03-31 17:46:35 +08:00
static defaultProps = {
prefixCls: 'ant-pagination',
selectPrefixCls: 'ant-select',
2016-07-13 11:14:24 +08:00
};
2016-03-31 17:46:35 +08:00
2018-08-21 17:13:12 +08:00
getIconsProps = () => {
const { prefixCls } = this.props;
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`}>
<Icon
className={`${prefixCls}-item-link-icon`}
2018-08-24 18:11:02 +08:00
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`}>
<Icon
className={`${prefixCls}-item-link-icon`}
type="double-right"
/>
<span className={`${prefixCls}-item-ellipsis`}></span>
</div>
2018-08-21 17:13:12 +08:00
</a>
);
return {
prevIcon,
nextIcon,
jumpPrevIcon,
jumpNextIcon,
};
}
renderPagination = (contextLocale: PaginationLocale) => {
2018-08-21 17:13:12 +08:00
const { className, size, locale: customLocale, ...restProps } = this.props;
const locale = { ...contextLocale, ...customLocale };
const isSmall = size === 'small';
2016-03-31 17:46:35 +08:00
return (
<RcPagination
{...restProps}
2018-08-21 17:13:12 +08:00
{...this.getIconsProps()}
className={classNames(className, { mini: isSmall })}
selectComponentClass={isSmall ? MiniSelect : Select}
2016-03-31 17:46:35 +08:00
locale={locale}
/>
2016-03-31 17:46:35 +08:00
);
}
render() {
return (
<LocaleReceiver
componentName="Pagination"
defaultLocale={enUS}
>
{this.renderPagination}
</LocaleReceiver>
);
}
}