1 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2 | var _excluded = ["className", "cssModule", "active", "tag", "innerRef"];
|
3 | function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
|
4 | function _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; }
|
5 | function _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; }
|
6 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
7 | function _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); } }
|
8 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
9 | function _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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
10 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
11 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
12 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
13 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
14 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
15 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
16 | import React from 'react';
|
17 | import PropTypes from 'prop-types';
|
18 | import classNames from 'classnames';
|
19 | import { mapToCssModules, tagPropType } from './utils';
|
20 | var propTypes = {
|
21 |
|
22 | active: PropTypes.bool,
|
23 |
|
24 | className: PropTypes.string,
|
25 |
|
26 | cssModule: PropTypes.object,
|
27 |
|
28 | disabled: PropTypes.bool,
|
29 | href: PropTypes.any,
|
30 | innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
|
31 |
|
32 | onClick: PropTypes.func,
|
33 |
|
34 | tag: tagPropType
|
35 | };
|
36 | var NavLink = function (_React$Component) {
|
37 | _inherits(NavLink, _React$Component);
|
38 | var _super = _createSuper(NavLink);
|
39 | function NavLink(props) {
|
40 | var _this;
|
41 | _classCallCheck(this, NavLink);
|
42 | _this = _super.call(this, props);
|
43 | _this.onClick = _this.onClick.bind(_assertThisInitialized(_this));
|
44 | return _this;
|
45 | }
|
46 | _createClass(NavLink, [{
|
47 | key: "onClick",
|
48 | value: function onClick(e) {
|
49 | if (this.props.disabled) {
|
50 | e.preventDefault();
|
51 | return;
|
52 | }
|
53 | if (this.props.href === '#') {
|
54 | e.preventDefault();
|
55 | }
|
56 | if (this.props.onClick) {
|
57 | this.props.onClick(e);
|
58 | }
|
59 | }
|
60 | }, {
|
61 | key: "render",
|
62 | value: function render() {
|
63 | var _this$props = this.props,
|
64 | className = _this$props.className,
|
65 | cssModule = _this$props.cssModule,
|
66 | active = _this$props.active,
|
67 | _this$props$tag = _this$props.tag,
|
68 | Tag = _this$props$tag === void 0 ? 'a' : _this$props$tag,
|
69 | innerRef = _this$props.innerRef,
|
70 | attributes = _objectWithoutProperties(_this$props, _excluded);
|
71 | var classes = mapToCssModules(classNames(className, 'nav-link', {
|
72 | disabled: attributes.disabled,
|
73 | active: active
|
74 | }), cssModule);
|
75 | return React.createElement(Tag, _extends({}, attributes, {
|
76 | ref: innerRef,
|
77 | onClick: this.onClick,
|
78 | className: classes
|
79 | }));
|
80 | }
|
81 | }]);
|
82 | return NavLink;
|
83 | }(React.Component);
|
84 | NavLink.propTypes = propTypes;
|
85 | export default NavLink; |
\ | No newline at end of file |