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