UNPKG

2.65 kBJavaScriptView Raw
1import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
3import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
4import _assertThisInitialized from "@babel/runtime-corejs2/helpers/esm/assertThisInitialized";
5import classNames from 'classnames';
6import React from 'react';
7import PropTypes from 'prop-types';
8import SafeAnchor from './SafeAnchor';
9import createChainedFunction from './utils/createChainedFunction';
10var 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};
19var defaultProps = {
20 active: false,
21 disabled: false
22};
23
24var NavItem =
25/*#__PURE__*/
26function (_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; // These are injected down by `<Nav>` for building `<SubNav>`s.
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
89NavItem.propTypes = propTypes;
90NavItem.defaultProps = defaultProps;
91export default NavItem;
\No newline at end of file