Item.js 868 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from 'react';
  2. import withGGEditorContext from '@common/context/GGEditorContext/withGGEditorContext';
  3. class Item extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.bindEvent();
  7. }
  8. handleMouseDown = () => {
  9. const { type, size, shape, model } = this.props;
  10. if (this.page) {
  11. this.page.beginAdd(type, {
  12. type,
  13. size,
  14. shape,
  15. ...model,
  16. });
  17. }
  18. }
  19. bindEvent() {
  20. const { onAfterAddPage } = this.props;
  21. onAfterAddPage(({ page }) => {
  22. this.page = page;
  23. });
  24. }
  25. render() {
  26. const { src, shape, children } = this.props;
  27. return (
  28. <div style={{ cursor: 'pointer' }} onMouseDown={this.handleMouseDown}>
  29. {src ? <img src={src} alt={shape} draggable={false} /> : children}
  30. </div>
  31. );
  32. }
  33. }
  34. export default withGGEditorContext(Item);