Preview.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import RevisionBody from '../Page/RevisionBody';
  4. import { PreviewOptions } from './OptionsSelector';
  5. /**
  6. * Wrapper component for Page/RevisionBody
  7. */
  8. export default class Preview extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. }
  12. render() {
  13. const renderMathJaxInRealtime = this.props.previewOptions.renderMathJaxInRealtime;
  14. return (
  15. <div
  16. className="page-editor-preview-body"
  17. ref={(elm) => {
  18. this.previewElement = elm;
  19. this.props.inputRef(elm);
  20. }}
  21. onScroll={(event) => {
  22. if (this.props.onScroll != null) {
  23. this.props.onScroll(event.target.scrollTop);
  24. }
  25. }}
  26. >
  27. <RevisionBody
  28. {...this.props}
  29. renderMathJaxInRealtime={renderMathJaxInRealtime}
  30. />
  31. </div>
  32. );
  33. }
  34. }
  35. Preview.propTypes = {
  36. html: PropTypes.string,
  37. inputRef: PropTypes.func.isRequired, // for getting div element
  38. isMathJaxEnabled: PropTypes.bool,
  39. renderMathJaxOnInit: PropTypes.bool,
  40. previewOptions: PropTypes.instanceOf(PreviewOptions),
  41. onScroll: PropTypes.func,
  42. };