content: /**
   * adddr (https://www.adddr.io/)
   *
   * Copyright © 2014-present Kriasoft, LLC. All rights reserved.
   *
   * This source code is licensed under the MIT license found in the
   * LICENSE.txt file in the root directory of this source tree.
   */
  
  import React from 'react';
  import PropTypes from 'prop-types';
  import history from '../../history';
  
  function isLeftClickEvent(event) {
    return event.button === 0;
  }
  
  function isModifiedEvent(event) {
    return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
  }
  
  class Link extends React.Component {
    static propTypes = {
      to: PropTypes.string.isRequired,
      children: PropTypes.node.isRequired,
      onClick: PropTypes.func,
    };
  
    static defaultProps = {
      onClick: null,
    };
  
    handleClick = event => {
      if (this.props.onClick) {
        this.props.onClick(event);
      }
  
      if (isModifiedEvent(event) || !isLeftClickEvent(event)) {
        return;
      }
  
      if (event.defaultPrevented === true) {
        return;
      }
  
      event.preventDefault();
      history.push(this.props.to);
    };
  
    render() {
      const { to, children, ...props } = this.props;
      return (
        <a href={to} {...props} onClick={this.handleClick}>
          {children}
        </a>
      );
    }
  }
  
  export default Link;
  