CommentEditorLazyRenderer.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import CommentEditor from './CommentEditor';
  4. export default class CommentEditorLazyRenderer extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. isEditorShown: false,
  9. isLayoutTypeGrowi: false,
  10. };
  11. this.showCommentFormBtnClickHandler = this.showCommentFormBtnClickHandler.bind(this);
  12. }
  13. componentWillMount() {
  14. this.init();
  15. }
  16. init() {
  17. const layoutType = this.props.crowi.getConfig().layoutType;
  18. this.setState({ isLayoutTypeGrowi: layoutType === 'crowi-plus' || layoutType === 'growi' });
  19. }
  20. showCommentFormBtnClickHandler() {
  21. this.setState({ isEditorShown: true });
  22. }
  23. render() {
  24. return (
  25. <React.Fragment>
  26. { !this.state.isEditorShown
  27. && (
  28. <button
  29. type="button"
  30. className={`btn btn-lg ${this.state.isLayoutTypeGrowi ? 'btn-link' : 'btn-primary'} center-block`}
  31. onClick={this.showCommentFormBtnClickHandler}
  32. >
  33. <i className="icon-bubble"></i> Add Comment
  34. </button>
  35. )
  36. }
  37. { this.state.isEditorShown
  38. && <CommentEditor {...this.props}></CommentEditor>
  39. }
  40. </React.Fragment>
  41. );
  42. }
  43. }
  44. CommentEditorLazyRenderer.propTypes = {
  45. crowi: PropTypes.object.isRequired,
  46. crowiOriginRenderer: PropTypes.object.isRequired,
  47. editorOptions: PropTypes.object,
  48. slackChannels: PropTypes.string,
  49. };