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