2017-05-02 20:04:16 -04:00
|
|
|
import React from 'react';
|
2017-04-21 14:05:35 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2016-12-02 09:05:50 -05:00
|
|
|
|
2017-06-23 13:36:54 -04:00
|
|
|
export default class Permalink extends React.PureComponent {
|
2016-12-02 09:05:50 -05:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
static contextTypes = {
|
2017-05-20 11:31:47 -04:00
|
|
|
router: PropTypes.object,
|
2017-05-12 08:44:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
href: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string.isRequired,
|
2017-05-20 11:31:47 -04:00
|
|
|
children: PropTypes.node,
|
2017-05-12 08:44:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
handleClick = (e) => {
|
2017-05-15 16:36:38 -04:00
|
|
|
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
2016-12-02 09:05:50 -05:00
|
|
|
e.preventDefault();
|
2017-06-20 14:40:03 -04:00
|
|
|
this.context.router.history.push(this.props.to);
|
2016-12-02 09:05:50 -05:00
|
|
|
}
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2016-12-02 09:05:50 -05:00
|
|
|
|
|
|
|
render () {
|
2017-04-22 22:26:55 -04:00
|
|
|
const { href, children, className, ...other } = this.props;
|
2016-12-02 09:05:50 -05:00
|
|
|
|
2017-05-02 20:04:16 -04:00
|
|
|
return (
|
|
|
|
<a href={href} onClick={this.handleClick} {...other} className={'permalink ' + className}>
|
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
);
|
2016-12-02 09:05:50 -05:00
|
|
|
}
|
|
|
|
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|