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