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