RevisionUrl.js 945 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import CopyButton from '../CopyButton';
  4. export default class RevisionUrl extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. // retrieve xss library from window
  8. this.xss = window.xss;
  9. }
  10. render() {
  11. const buttonStyle = {
  12. fontSize: '1em'
  13. };
  14. const pagePath = this.xss.process(this.props.pagePath);
  15. const url = (this.props.pageId == null)
  16. ? decodeURIComponent(location.href)
  17. : `${location.origin}/${this.props.pageId}`;
  18. const copiedText = pagePath + '\n' + url;
  19. return (
  20. <span>
  21. {url}
  22. <CopyButton buttonId="btnCopyRevisionUrl" text={copiedText}
  23. buttonClassName="btn btn-default btn-copy-link" buttonStyle={buttonStyle} iconClassName="ti-clipboard" />
  24. </span>
  25. );
  26. }
  27. }
  28. RevisionUrl.propTypes = {
  29. pageId: PropTypes.string,
  30. pagePath: PropTypes.string.isRequired,
  31. };