index.js 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React from 'react';
  2. import Editor from '@components/Base/Editor';
  3. import { pick } from '@utils';
  4. import { TOOLBAR_CONTAINER } from '@common/constants';
  5. import withGGEditorContext from '@common/context/GGEditorContext/withGGEditorContext';
  6. class Toolbar extends React.Component {
  7. toolbar = null;
  8. get containerId() {
  9. const { editor } = this.props;
  10. return `${TOOLBAR_CONTAINER}_${editor.id}`;
  11. }
  12. constructor(props) {
  13. super(props);
  14. const { editor, onAfterAddPage } = props;
  15. onAfterAddPage(() => {
  16. this.toolbar = new Editor.Toolbar({
  17. container: this.containerId,
  18. });
  19. editor.add(this.toolbar);
  20. });
  21. }
  22. render() {
  23. const { children } = this.props;
  24. return (
  25. <div id={this.containerId} {...pick(this.props, ['style', 'className'])}>
  26. {children}
  27. </div>
  28. );
  29. }
  30. }
  31. export default withGGEditorContext(Toolbar);