BlockDel.jsx 881 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react'
  2. import newEventActions from 'actions/newEvent'
  3. import { shallowEqualImmutable } from 'utils/utils'
  4. export default class BlockDel extends React.Component {
  5. constructor(props) {
  6. super(props)
  7. this.onDelBlock = this.onDelBlock.bind(this)
  8. }
  9. shouldComponentUpdate(nextProps, nextState) {
  10. return (
  11. !shallowEqualImmutable(this.props, nextProps) ||
  12. !shallowEqualImmutable(this.state, nextState)
  13. )
  14. }
  15. onDelBlock(e) {
  16. e.stopPropagation()
  17. newEventActions.deleteBlock({ blockId: this.props.bid })
  18. }
  19. getStyle() {
  20. return {
  21. left: -(8 + this.props.layer * 20 + (this.props.layer + 1)) - 38 + 'px'
  22. }
  23. }
  24. render() {
  25. return this.props.isActive ? (
  26. <button
  27. className="btn-clear btn-block-del"
  28. style={this.getStyle()}
  29. onClick={this.onDelBlock}
  30. />
  31. ) : null
  32. }
  33. }