-
-
Notifications
You must be signed in to change notification settings - Fork 329
/
Copy pathPager.tsx
73 lines (64 loc) · 1.51 KB
/
Pager.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* eslint react/prop-types: 0 */
import classNames from 'classnames';
import React from 'react';
import type { PaginationProps } from './interface';
export interface PagerProps extends Pick<PaginationProps, 'itemRender'> {
rootPrefixCls: string;
page: number;
active?: boolean;
className?: string;
style?: React.CSSProperties;
showTitle: boolean;
onClick?: (page: number) => void;
onKeyPress?: (
e: React.KeyboardEvent<HTMLLIElement>,
onClick: PagerProps['onClick'],
page: PagerProps['page'],
) => void;
}
const Pager: React.FC<PagerProps> = (props) => {
const {
rootPrefixCls,
page,
active,
className,
style,
showTitle,
onClick,
onKeyPress,
itemRender,
} = props;
const prefixCls = `${rootPrefixCls}-item`;
const cls = classNames(
prefixCls,
`${prefixCls}-${page}`,
{
[`${prefixCls}-active`]: active,
[`${prefixCls}-disabled`]: !page,
},
className,
);
const handleClick = () => {
onClick(page);
};
const handleKeyPress = (e: React.KeyboardEvent<HTMLLIElement>) => {
onKeyPress(e, onClick, page);
};
const pager = itemRender(page, 'page', <a rel="nofollow">{page}</a>);
return pager ? (
<li
title={showTitle ? String(page) : null}
className={cls}
style={style}
onClick={handleClick}
onKeyDown={handleKeyPress}
tabIndex={0}
>
{pager}
</li>
) : null;
};
if (process.env.NODE_ENV !== 'production') {
Pager.displayName = 'Pager';
}
export default Pager;