CommentFormBase.jsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. // import { withTranslation } from 'react-i18next';
  4. /**
  5. * @author Shin Oka <okas@weseek.co.jp>
  6. *
  7. * @export
  8. * @class CommentFormBase
  9. * @extends {React.Component}
  10. */
  11. export default class CommentFormBase extends React.Component {
  12. render() {
  13. let childrenWithProps;
  14. if (this.props.data !== undefined) {
  15. childrenWithProps = React.Children.map(this.props.children, (child) => {
  16. return React.cloneElement(child, this.props.data);
  17. });
  18. }
  19. else {
  20. const data = {
  21. pageId: this.props.pageId,
  22. pagePath: this.props.pagePath,
  23. onPostComplete: this.props.onPostComplete,
  24. revisionId: this.props.revisionId,
  25. revisionCreatedAt: this.props.revisionCreatedAt,
  26. editorOptions: this.props.editorOptions,
  27. slackChannels: this.props.slackChannels,
  28. };
  29. childrenWithProps = React.Children.map(this.props.children, (child) => {
  30. return React.cloneElement(child, data);
  31. });
  32. }
  33. return <div>{childrenWithProps}</div>;
  34. }
  35. }
  36. CommentFormBase.propTypes = {
  37. children: PropTypes.node,
  38. pageId: PropTypes.string,
  39. pagePath: PropTypes.string,
  40. onPostComplete: PropTypes.func,
  41. editorOptions: PropTypes.object,
  42. slackChannels: PropTypes.string,
  43. revisionId: PropTypes.string,
  44. revisionCreatedAt: PropTypes.number,
  45. data: PropTypes.object,
  46. };