2017-04-21 20:05:35 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 16:38:10 +02:00
|
|
|
import { PureComponent } from 'react';
|
2016-12-02 15:05:50 +01:00
|
|
|
|
2023-10-19 19:44:55 +02:00
|
|
|
import { withOptionalRouter, WithOptionalRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
2016-12-02 15:05:50 +01:00
|
|
|
|
2023-10-19 19:44:55 +02:00
|
|
|
class Permalink extends PureComponent {
|
2017-05-12 14:44:10 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
href: PropTypes.string.isRequired,
|
|
|
|
to: PropTypes.string.isRequired,
|
2017-05-20 17:31:47 +02:00
|
|
|
children: PropTypes.node,
|
2018-10-02 16:01:28 +02:00
|
|
|
onInterceptClick: PropTypes.func,
|
2023-10-19 19:44:55 +02:00
|
|
|
...WithOptionalRouterPropTypes,
|
2017-05-12 14:44:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
handleClick = (e) => {
|
2018-10-02 16:01:28 +02:00
|
|
|
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
|
|
|
if (this.props.onInterceptClick && this.props.onInterceptClick()) {
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-19 19:44:55 +02:00
|
|
|
if (this.props.history) {
|
2018-10-02 16:01:28 +02:00
|
|
|
e.preventDefault();
|
2023-10-19 19:44:55 +02:00
|
|
|
this.props.history.push(this.props.to);
|
2018-10-02 16:01:28 +02:00
|
|
|
}
|
2016-12-02 15:05:50 +01:00
|
|
|
}
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2016-12-02 15:05:50 +01:00
|
|
|
|
|
|
|
render () {
|
2018-01-06 05:04:13 +01:00
|
|
|
const {
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
href,
|
|
|
|
to,
|
2018-10-02 16:01:28 +02:00
|
|
|
onInterceptClick,
|
2018-01-06 05:04:13 +01:00
|
|
|
...other
|
|
|
|
} = this.props;
|
2016-12-02 15:05:50 +01:00
|
|
|
|
2017-05-03 02:04:16 +02:00
|
|
|
return (
|
2017-07-11 15:27:59 +02:00
|
|
|
<a target='_blank' href={href} onClick={this.handleClick} {...other} className={`permalink${className ? ' ' + className : ''}`}>
|
2017-05-03 02:04:16 +02:00
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
);
|
2016-12-02 15:05:50 +01:00
|
|
|
}
|
|
|
|
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2023-10-19 19:44:55 +02:00
|
|
|
|
|
|
|
export default withOptionalRouter(Permalink);
|