UNPKG

3.31 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _react = _interopRequireDefault(require("react"));
8var _propTypes = _interopRequireDefault(require("prop-types"));
9var _classnames = _interopRequireDefault(require("classnames"));
10var _utils = require("./utils");
11const _excluded = ["className", "cssModule", "active", "tag", "innerRef"];
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13function _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); }
14function _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; }
15function _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; }
16const propTypes = {
17 /** Add active class to NavLink */
18 active: _propTypes.default.bool,
19 /** Add custom class */
20 className: _propTypes.default.string,
21 /** Change underlying component's CSS base class name */
22 cssModule: _propTypes.default.object,
23 /** Disable the link */
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 /** Function to be triggered on click */
28 onClick: _propTypes.default.func,
29 /** Set a custom element for this component */
30 tag: _utils.tagPropType
31};
32class 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 /*#__PURE__*/_react.default.createElement(Tag, _extends({}, attributes, {
64 ref: innerRef,
65 onClick: this.onClick,
66 className: classes
67 }));
68 }
69}
70NavLink.propTypes = propTypes;
71var _default = NavLink;
72exports.default = _default;
\No newline at end of file