You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

78 lines
2.2 KiB

  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
  4. import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
  5. import React from 'react';
  6. import PropTypes from 'prop-types';
  7. import classNames from 'classnames';
  8. import { mapToCssModules, tagPropType } from './utils';
  9. var propTypes = {
  10. tag: tagPropType,
  11. innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
  12. disabled: PropTypes.bool,
  13. active: PropTypes.bool,
  14. className: PropTypes.string,
  15. cssModule: PropTypes.object,
  16. onClick: PropTypes.func,
  17. href: PropTypes.any
  18. };
  19. var defaultProps = {
  20. tag: 'a'
  21. };
  22. var NavLink =
  23. /*#__PURE__*/
  24. function (_React$Component) {
  25. _inheritsLoose(NavLink, _React$Component);
  26. function NavLink(props) {
  27. var _this;
  28. _this = _React$Component.call(this, props) || this;
  29. _this.onClick = _this.onClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
  30. return _this;
  31. }
  32. var _proto = NavLink.prototype;
  33. _proto.onClick = function onClick(e) {
  34. if (this.props.disabled) {
  35. e.preventDefault();
  36. return;
  37. }
  38. if (this.props.href === '#') {
  39. e.preventDefault();
  40. }
  41. if (this.props.onClick) {
  42. this.props.onClick(e);
  43. }
  44. };
  45. _proto.render = function render() {
  46. var _this$props = this.props,
  47. className = _this$props.className,
  48. cssModule = _this$props.cssModule,
  49. active = _this$props.active,
  50. Tag = _this$props.tag,
  51. innerRef = _this$props.innerRef,
  52. attributes = _objectWithoutPropertiesLoose(_this$props, ["className", "cssModule", "active", "tag", "innerRef"]);
  53. var classes = mapToCssModules(classNames(className, 'nav-link', {
  54. disabled: attributes.disabled,
  55. active: active
  56. }), cssModule);
  57. return React.createElement(Tag, _extends({}, attributes, {
  58. ref: innerRef,
  59. onClick: this.onClick,
  60. className: classes
  61. }));
  62. };
  63. return NavLink;
  64. }(React.Component);
  65. NavLink.propTypes = propTypes;
  66. NavLink.defaultProps = defaultProps;
  67. export default NavLink;