forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaginationButton.js
More file actions
83 lines (67 loc) · 1.74 KB
/
Copy pathPaginationButton.js
File metadata and controls
83 lines (67 loc) · 1.74 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
74
75
76
77
78
79
80
81
82
83
import classNames from 'classnames';
import React from 'react';
import elementType from 'react-prop-types/lib/elementType';
import SafeAnchor from './SafeAnchor';
import createChainedFunction from './utils/createChainedFunction';
// TODO: This should be `<Pagination.Item>`.
// TODO: This should use `componentClass` like other components.
const propTypes = {
componentClass: elementType,
className: React.PropTypes.string,
eventKey: React.PropTypes.any,
onSelect: React.PropTypes.func,
disabled: React.PropTypes.bool,
active: React.PropTypes.bool,
onClick: React.PropTypes.func,
};
const defaultProps = {
componentClass: SafeAnchor,
active: false,
disabled: false
};
class PaginationButton extends React.Component {
constructor(props, context) {
super(props, context);
this.handleClick = this.handleClick.bind(this);
}
handleClick(event) {
const { disabled, onSelect, eventKey } = this.props;
if (disabled) {
return;
}
if (onSelect) {
onSelect(eventKey, event);
}
}
render() {
const {
componentClass: Component,
active,
disabled,
onClick,
className,
style,
...props
} = this.props;
if (Component === SafeAnchor) {
// Assume that custom components want `eventKey`.
delete props.eventKey;
}
delete props.onSelect;
return (
<li
className={classNames(className, { active, disabled })}
style={style}
>
<Component
{...props}
disabled={disabled}
onClick={createChainedFunction(onClick, this.handleClick)}
/>
</li>
);
}
}
PaginationButton.propTypes = propTypes;
PaginationButton.defaultProps = defaultProps;
export default PaginationButton;