UNPKG

8.62 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var React = _interopRequireWildcard(require("react"));
9
10var _overrides = require("../helpers/overrides.js");
11
12var _styledComponents = require("./styled-components.js");
13
14function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
15
16function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
18function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
19
20function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
22function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
23
24function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
25
26function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
27
28function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
29
30function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
32function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
34function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
35
36function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
37
38function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
39
40function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
41
42function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
44function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
45
46function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
47
48function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
49
50function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
51
52var NavItem =
53/*#__PURE__*/
54function (_React$Component) {
55 _inherits(NavItem, _React$Component);
56
57 function NavItem() {
58 var _getPrototypeOf2;
59
60 var _this;
61
62 _classCallCheck(this, NavItem);
63
64 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
65 args[_key] = arguments[_key];
66 }
67
68 _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(NavItem)).call.apply(_getPrototypeOf2, [this].concat(args)));
69
70 _defineProperty(_assertThisInitialized(_this), "handleClick", function (event) {
71 var _this$props = _this.props,
72 item = _this$props.item,
73 onSelect = _this$props.onSelect;
74
75 if (typeof onSelect === 'function') {
76 onSelect({
77 item: item,
78 event: event
79 });
80 }
81 });
82
83 _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (event) {
84 var _this$props2 = _this.props,
85 item = _this$props2.item,
86 onSelect = _this$props2.onSelect;
87
88 if (event.key === 'Enter') {
89 if (typeof onSelect === 'function') {
90 onSelect({
91 item: item,
92 event: event
93 });
94 }
95 }
96 });
97
98 return _this;
99 }
100
101 _createClass(NavItem, [{
102 key: "render",
103 value: function render() {
104 var _this$props3 = this.props,
105 item = _this$props3.item,
106 overrides = _this$props3.overrides,
107 itemMemoizationComparator = _this$props3.itemMemoizationComparator,
108 sharedProps = _objectWithoutProperties(_this$props3, ["item", "overrides", "itemMemoizationComparator"]);
109
110 var _getOverrides = (0, _overrides.getOverrides)(overrides.NavItem, _styledComponents.StyledNavItem),
111 _getOverrides2 = _slicedToArray(_getOverrides, 2),
112 NavItem = _getOverrides2[0],
113 itemProps = _getOverrides2[1];
114
115 var _getOverrides3 = (0, _overrides.getOverrides)(overrides.NavLink, _styledComponents.StyledNavLink),
116 _getOverrides4 = _slicedToArray(_getOverrides3, 2),
117 NavLink = _getOverrides4[0],
118 linkProps = _getOverrides4[1];
119
120 var tabIndex = {
121 tabIndex: item.disabled ? -1 : undefined
122 };
123 return React.createElement(NavLink, _extends({
124 $as: item.disabled ? 'span' : 'a',
125 href: item.disabled ? null : item.itemId
126 }, tabIndex, sharedProps, linkProps, item.itemId && !item.disabled ? {
127 onClick: this.handleClick,
128 onKeyDown: this.handleKeyDown
129 } : {}), React.createElement(NavItem, _extends({
130 item: item
131 }, sharedProps, itemProps), item.title));
132 }
133 }]);
134
135 return NavItem;
136}(React.Component);
137
138_defineProperty(NavItem, "defaultProps", {
139 overrides: {},
140 onSelect: function onSelect() {}
141});
142
143function compare(prevProps, nextProps) {
144 if (nextProps.itemMemoizationComparator) {
145 return nextProps.itemMemoizationComparator(prevProps, nextProps);
146 }
147
148 return false;
149}
150
151var _default = React.memo(NavItem, compare);
152
153exports.default = _default;
\No newline at end of file