| | |
| | | import React from 'react' |
| | | import { useDrag, useDrop } from 'react-dnd' |
| | | import { Icon, Popover } from 'antd' |
| | | import { Popover } from 'antd' |
| | | import { EditOutlined, CloseOutlined } from '@ant-design/icons' |
| | | |
| | | import MkIcon from '@/components/mk-icon' |
| | | import './index.scss' |
| | | |
| | | const Card = ({ id, card, moveCard, findCard, doubleClickCard, editCard, delCard, hasDrop }) => { |
| | | const Card = ({ id, card, moveCard, findCard, doubleClickCard, editCard, delCard }) => { |
| | | const originalIndex = findCard(id).index |
| | | const [{ isDragging }, drag] = useDrag({ |
| | | item: { type: 'tabs', id, originalIndex }, |
| | |
| | | accept: 'tabs', |
| | | canDrop: () => true, |
| | | drop: (item) => { |
| | | if (!item.hasOwnProperty('originalIndex')) { |
| | | hasDrop(card) |
| | | } |
| | | }, |
| | | hover({ id: draggedId }) { |
| | | if (!draggedId) return |
| | | if (draggedId !== id) { |
| | | const { id: draggedId, originalIndex } = item |
| | | |
| | | if (originalIndex === undefined) { |
| | | item.dropTargetId = id |
| | | } else if (draggedId && draggedId !== id) { |
| | | const { index: overIndex } = findCard(id) |
| | | moveCard(draggedId, overIndex) |
| | | } |
| | |
| | | return ( |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <Icon className="edit" type="edit" onClick={edit} /> |
| | | <Icon className="close" type="close" onClick={del} /> |
| | | <EditOutlined className="edit" onClick={edit} /> |
| | | <CloseOutlined className="close" onClick={del} /> |
| | | </div> |
| | | } trigger="hover"> |
| | | <div className="page-card" style={{ opacity: opacity}}> |
| | | <div ref={node => drag(drop(node))} onDoubleClick={doubleClick}> |
| | | {card.icon ? <Icon type={card.icon} /> : null} |
| | | {card.icon ? <MkIcon type={card.icon} /> : null} |
| | | {card.label} |
| | | </div> |
| | | </div> |