about summary refs log tree commit diff
path: root/app/assets/javascripts/components/components/permalink.jsx
blob: ccbe4944f1f1ecd03ecc3cfd1c16c054a9259bfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import PropTypes from 'prop-types';

class Permalink extends React.Component {

  constructor (props, context) {
    super(props, context);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick (e) {
    if (e.button === 0) {
      e.preventDefault();
      this.context.router.push(this.props.to);
    }
  }

  render () {
    const { href, children, className, ...other } = this.props;

    return <a href={href} onClick={this.handleClick} {...other} className={'permalink ' + className}>{children}</a>;
  }

}

Permalink.contextTypes = {
  router: PropTypes.object
};

Permalink.propTypes = {
  className: PropTypes.string,
  href: PropTypes.string.isRequired,
  to: PropTypes.string.isRequired,
  children: PropTypes.node
};

export default Permalink;