logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

permalink.js (995B)


  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. export default class Permalink extends React.PureComponent {
  4. static contextTypes = {
  5. router: PropTypes.object,
  6. };
  7. static propTypes = {
  8. className: PropTypes.string,
  9. href: PropTypes.string.isRequired,
  10. to: PropTypes.string.isRequired,
  11. children: PropTypes.node,
  12. onInterceptClick: PropTypes.func,
  13. };
  14. handleClick = e => {
  15. if (this.props.onInterceptClick && this.props.onInterceptClick()) {
  16. e.preventDefault();
  17. return;
  18. }
  19. if (this.context.router && e.button === 0 && !(e.ctrlKey || e.metaKey)) {
  20. e.preventDefault();
  21. this.context.router.history.push(this.props.to);
  22. }
  23. }
  24. render () {
  25. const { href, children, className, onInterceptClick, ...other } = this.props;
  26. return (
  27. <a target='_blank' href={href} onClick={this.handleClick} {...other} className={`permalink${className ? ' ' + className : ''}`}>
  28. {children}
  29. </a>
  30. );
  31. }
  32. }