UNPKG

2.46 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import classNames from 'classnames';
7import React from 'react';
8import PropTypes from 'prop-types';
9
10import SafeAnchor from './SafeAnchor';
11import createChainedFunction from './utils/createChainedFunction';
12
13var propTypes = {
14 disabled: PropTypes.bool,
15 previous: PropTypes.bool,
16 next: PropTypes.bool,
17 onClick: PropTypes.func,
18 onSelect: PropTypes.func,
19 eventKey: PropTypes.any
20};
21
22var defaultProps = {
23 disabled: false,
24 previous: false,
25 next: false
26};
27
28var PagerItem = function (_React$Component) {
29 _inherits(PagerItem, _React$Component);
30
31 function PagerItem(props, context) {
32 _classCallCheck(this, PagerItem);
33
34 var _this = _possibleConstructorReturn(this, _React$Component.call(this, props, context));
35
36 _this.handleSelect = _this.handleSelect.bind(_this);
37 return _this;
38 }
39
40 PagerItem.prototype.handleSelect = function handleSelect(e) {
41 var _props = this.props,
42 disabled = _props.disabled,
43 onSelect = _props.onSelect,
44 eventKey = _props.eventKey;
45
46
47 if (disabled) {
48 e.preventDefault();
49 return;
50 }
51
52 if (onSelect) {
53 onSelect(eventKey, e);
54 }
55 };
56
57 PagerItem.prototype.render = function render() {
58 var _props2 = this.props,
59 disabled = _props2.disabled,
60 previous = _props2.previous,
61 next = _props2.next,
62 onClick = _props2.onClick,
63 className = _props2.className,
64 style = _props2.style,
65 props = _objectWithoutProperties(_props2, ['disabled', 'previous', 'next', 'onClick', 'className', 'style']);
66
67 delete props.onSelect;
68 delete props.eventKey;
69
70 return React.createElement(
71 'li',
72 {
73 className: classNames(className, { disabled: disabled, previous: previous, next: next }),
74 style: style
75 },
76 React.createElement(SafeAnchor, _extends({}, props, {
77 disabled: disabled,
78 onClick: createChainedFunction(onClick, this.handleSelect)
79 }))
80 );
81 };
82
83 return PagerItem;
84}(React.Component);
85
86PagerItem.propTypes = propTypes;
87PagerItem.defaultProps = defaultProps;
88
89export default PagerItem;
\No newline at end of file