-
-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathPager.jsx
More file actions
73 lines (62 loc) · 1.58 KB
/
Pager.jsx
File metadata and controls
73 lines (62 loc) · 1.58 KB
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
import React from 'react';
import PropTypes from 'prop-types';
const Pager = (props) => {
const prefixCls = `${props.rootPrefixCls}-item`;
const ariaAttributes = {};
let cls = `${prefixCls} ${prefixCls}-${props.page}`;
if (props.active) {
cls = `${cls} ${prefixCls}-active`;
ariaAttributes['aria-current'] = 'page';
}
if (props.className) {
cls = `${cls} ${props.className}`;
}
if (!props.page) {
cls = `${cls} ${prefixCls}-disabled`;
}
const renderVisuallyHiddenText = () => (
<span className="visuallyHidden">
{props.active
? props.locale.aria_current_page
: props.locale.aria_page
}
</span>
);
const renderLink = () => (
<a href="#" {...ariaAttributes}>
{renderVisuallyHiddenText()}
{props.page}
</a>
);
const handleClick = () => {
props.onClick(props.page);
};
const handleKeyPress = e => {
props.onKeyPress(e, props.onClick, props.page);
};
return (
<li
title={props.showTitle ? props.page : null}
className={cls}
onClick={handleClick}
onKeyPress={handleKeyPress}
tabIndex={props.focusOnListItem ? 0 : null}
>
{props.itemRender(props.page, 'page', renderLink())}
</li>
);
};
Pager.propTypes = {
page: PropTypes.number,
active: PropTypes.bool,
last: PropTypes.bool,
locale: PropTypes.object,
className: PropTypes.string,
showTitle: PropTypes.bool,
focusOnListItem: PropTypes.bool,
rootPrefixCls: PropTypes.string,
onClick: PropTypes.func,
onKeyPress: PropTypes.func,
itemRender: PropTypes.func,
};
export default Pager;