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