text: /**
   * React Static Boilerplate
   * https://github.com/koistya/react-static-boilerplate
   *
   * Copyright © 2015-2016 Konstantin Tarkus (@koistya)
   *
   * 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, { PropTypes } from 'react';
  import history from '../../core/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.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
      onClick: PropTypes.func,
    };
  
    handleClick = (event) => {
      let allowTransition = true;
  
      if (this.props.onClick) {
        this.props.onClick(event);
      }
  
      if (isModifiedEvent(event) || !isLeftClickEvent(event)) {
        return;
      }
  
      if (event.defaultPrevented === true) {
        allowTransition = false;
      }
  
      event.preventDefault();
  
      if (allowTransition) {
        if (this.props.to) {
          history.push(this.props.to);
        } else {
          history.push({
            pathname: event.currentTarget.pathname,
            search: event.currentTarget.search,
          });
        }
      }
    };
  
    render() {
      const { to, ...props } = this.props; // eslint-disable-line no-use-before-define
      return <a href={history.createHref(to)} {...props} onClick={this.handleClick} />;
    }
  
  }
  
  export default Link;
  