1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _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; };
|
8 |
|
9 | var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
10 |
|
11 | var _react = require('react');
|
12 |
|
13 | var _react2 = _interopRequireDefault(_react);
|
14 |
|
15 | var _classnames = require('classnames');
|
16 |
|
17 | var _classnames2 = _interopRequireDefault(_classnames);
|
18 |
|
19 | var _utils = require('./utils');
|
20 |
|
21 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22 |
|
23 | function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
24 |
|
25 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
26 |
|
27 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
28 |
|
29 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
30 |
|
31 | var propTypes = {
|
32 | tag: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]),
|
33 | getRef: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]),
|
34 | disabled: _react.PropTypes.bool,
|
35 | active: _react.PropTypes.bool,
|
36 | className: _react.PropTypes.string,
|
37 | cssModule: _react.PropTypes.object,
|
38 | onClick: _react.PropTypes.func,
|
39 | href: _react.PropTypes.any
|
40 | };
|
41 |
|
42 | var defaultProps = {
|
43 | tag: 'a'
|
44 | };
|
45 |
|
46 | var NavLink = function (_React$Component) {
|
47 | _inherits(NavLink, _React$Component);
|
48 |
|
49 | function NavLink(props) {
|
50 | _classCallCheck(this, NavLink);
|
51 |
|
52 | var _this = _possibleConstructorReturn(this, (NavLink.__proto__ || Object.getPrototypeOf(NavLink)).call(this, props));
|
53 |
|
54 | _this.onClick = _this.onClick.bind(_this);
|
55 | return _this;
|
56 | }
|
57 |
|
58 | _createClass(NavLink, [{
|
59 | key: 'onClick',
|
60 | value: function onClick(e) {
|
61 | if (this.props.disabled) {
|
62 | e.preventDefault();
|
63 | return;
|
64 | }
|
65 |
|
66 | if (this.props.href === '#') {
|
67 | e.preventDefault();
|
68 | }
|
69 |
|
70 | if (this.props.onClick) {
|
71 | this.props.onClick(e);
|
72 | }
|
73 | }
|
74 | }, {
|
75 | key: 'render',
|
76 | value: function render() {
|
77 | var _props = this.props,
|
78 | className = _props.className,
|
79 | cssModule = _props.cssModule,
|
80 | active = _props.active,
|
81 | Tag = _props.tag,
|
82 | getRef = _props.getRef,
|
83 | attributes = _objectWithoutProperties(_props, ['className', 'cssModule', 'active', 'tag', 'getRef']);
|
84 |
|
85 | var classes = (0, _utils.mapToCssModules)((0, _classnames2.default)(className, 'nav-link', {
|
86 | disabled: attributes.disabled,
|
87 | active: active
|
88 | }), cssModule);
|
89 |
|
90 | return _react2.default.createElement(Tag, _extends({}, attributes, { ref: getRef, onClick: this.onClick, className: classes }));
|
91 | }
|
92 | }]);
|
93 |
|
94 | return NavLink;
|
95 | }(_react2.default.Component);
|
96 |
|
97 | NavLink.propTypes = propTypes;
|
98 | NavLink.defaultProps = defaultProps;
|
99 |
|
100 | exports.default = NavLink; |
\ | No newline at end of file |