king
2021-12-22 bd1dfc9e6c9b9f8076ca2783ce598e0936b4c664
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React from 'react'
import { useDrag, useDrop } from 'react-dnd'
import { Popover } from 'antd'
import { EditOutlined, CloseOutlined } from '@ant-design/icons'
import ItemTypes from './itemtypes'
import './index.scss'
 
const Card = ({ id, text, moveCard, findCard, editCard, delCard }) => {
  const originalIndex = findCard(id).index
  const [{ isDragging }, drag] = useDrag({
    item: { type: ItemTypes.CARD, id, originalIndex },
    collect: monitor => ({
      isDragging: monitor.isDragging(),
    }),
  })
  const [, drop] = useDrop({
    accept: ItemTypes.CARD,
    canDrop: () => true,
    drop: ({ id: draggedId }) => {
      if (draggedId && draggedId !== id) {
        const { index: overIndex } = findCard(id)
        moveCard(draggedId, overIndex)
      }
    },
  })
  const opacity = isDragging ? 0 : 1
 
  const edit = () => {
    editCard(id)
  }
 
  const del = () => {
    delCard(id)
  }
 
  return (
    <Popover overlayClassName="mk-popover-control-wrap header-menu" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
      <div className="mk-popover-control">
        <EditOutlined className="edit" onClick={edit} />
        <CloseOutlined className="close" onClick={del} />
      </div>
    } trigger="hover">
      <div className="card" style={{ opacity }}>
        <div ref={node => drag(drop(node))}>
          {text}
        </div>
      </div>
    </Popover>
  )
}
export default Card