1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | var _react = _interopRequireDefault(require("react"));
|
8 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
9 | var _classnames = _interopRequireDefault(require("classnames"));
|
10 | var _utils = require("./utils");
|
11 | const _excluded = ["className", "cssModule", "active", "tag", "innerRef"];
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 | 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); }
|
14 | 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; }
|
15 | 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; }
|
16 | const propTypes = {
|
17 |
|
18 | active: _propTypes.default.bool,
|
19 |
|
20 | className: _propTypes.default.string,
|
21 |
|
22 | cssModule: _propTypes.default.object,
|
23 |
|
24 | disabled: _propTypes.default.bool,
|
25 | href: _propTypes.default.any,
|
26 | innerRef: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.func, _propTypes.default.string]),
|
27 |
|
28 | onClick: _propTypes.default.func,
|
29 |
|
30 | tag: _utils.tagPropType
|
31 | };
|
32 | class NavLink extends _react.default.Component {
|
33 | constructor(props) {
|
34 | super(props);
|
35 | this.onClick = this.onClick.bind(this);
|
36 | }
|
37 | onClick(e) {
|
38 | if (this.props.disabled) {
|
39 | e.preventDefault();
|
40 | return;
|
41 | }
|
42 | if (this.props.href === '#') {
|
43 | e.preventDefault();
|
44 | }
|
45 | if (this.props.onClick) {
|
46 | this.props.onClick(e);
|
47 | }
|
48 | }
|
49 | render() {
|
50 | let _this$props = this.props,
|
51 | {
|
52 | className,
|
53 | cssModule,
|
54 | active,
|
55 | tag: Tag = 'a',
|
56 | innerRef
|
57 | } = _this$props,
|
58 | attributes = _objectWithoutProperties(_this$props, _excluded);
|
59 | const classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, 'nav-link', {
|
60 | disabled: attributes.disabled,
|
61 | active: active
|
62 | }), cssModule);
|
63 | return _react.default.createElement(Tag, _extends({}, attributes, {
|
64 | ref: innerRef,
|
65 | onClick: this.onClick,
|
66 | className: classes
|
67 | }));
|
68 | }
|
69 | }
|
70 | NavLink.propTypes = propTypes;
|
71 | var _default = NavLink;
|
72 | exports.default = _default; |
\ | No newline at end of file |