Preview.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 className="page-editor-preview-body"
  16. ref={(elm) => {
  17. this.previewElement = elm;
  18. this.props.inputRef(elm);
  19. }}
  20. onScroll={(event) => {
  21. if (this.props.onScroll != null) {
  22. this.props.onScroll(event.target.scrollTop);
  23. }
  24. }}>
  25. <RevisionBody
  26. {...this.props}
  27. renderMathJaxInRealtime={renderMathJaxInRealtime}
  28. />
  29. </div>
  30. );
  31. }
  32. }
  33. Preview.propTypes = {
  34. html: PropTypes.string,
  35. inputRef: PropTypes.func.isRequired, // for getting div element
  36. isMathJaxEnabled: PropTypes.bool,
  37. renderMathJaxOnInit: PropTypes.bool,
  38. previewOptions: PropTypes.instanceOf(PreviewOptions),
  39. onScroll: PropTypes.func,
  40. };