| | |
| | | import React from 'react' |
| | | import { useDrag, useDrop } from 'react-dnd' |
| | | import { Icon, Button } from 'antd' |
| | | import { Icon, Button, Popover } from 'antd' |
| | | import './index.scss' |
| | | |
| | | const Card = ({ id, card, moveCard, findCard, editCard, delCard, copyCard, profileCard, doubleClickCard }) => { |
| | | const Card = ({ id, cardIds, type, card, moveCard, findCard, editCard, delCard, copyCard, profileCard, doubleClickCard }) => { |
| | | const originalIndex = findCard(id).index |
| | | const [{ isDragging }, drag] = useDrag({ |
| | | item: { type: 'action', id, originalIndex }, |
| | |
| | | drop: () => {}, |
| | | hover({ id: draggedId }) { |
| | | if (!draggedId) return |
| | | if (!cardIds.includes(draggedId)) return |
| | | |
| | | if (draggedId !== id) { |
| | | const { index: overIndex } = findCard(id) |
| | | moveCard(draggedId, overIndex) |
| | |
| | | hasProfile = true |
| | | } |
| | | |
| | | let btnElement = null |
| | | if (type === 'chart') { |
| | | btnElement = (<Icon type={card.icon} className={'mk-icon mk-' + card.class} onClick={() => editCard(id)} />) |
| | | } else { |
| | | btnElement = ( |
| | | <Button |
| | | className={'mk-btn mk-' + card.class} |
| | | icon={card.icon} |
| | | key={card.uuid} |
| | | onDoubleClick={() => doubleClickCard(id)} |
| | | > |
| | | {card.label} |
| | | </Button> |
| | | ) |
| | | } |
| | | |
| | | return ( |
| | | <div className="page-card" style={{ opacity: opacity}}> |
| | | <div ref={node => drag(drop(node))}> |
| | | <Button |
| | | className={'mk-btn mk-' + card.class} |
| | | icon={card.icon} |
| | | key={card.uuid} |
| | | onDoubleClick={() => doubleClickCard(id)} |
| | | > |
| | | {card.label}{card.position === 'grid' && <Icon type="table" />} |
| | | </Button> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <Icon className="edit" title="edit" type="edit" onClick={() => editCard(id)} /> |
| | | <Icon className="copy" title="copy" type="copy" onClick={() => copyCard(id)} /> |
| | | <Icon className="close" title="close" type="close" onClick={() => delCard(id)} /> |
| | | {hasProfile ? <Icon className="profile" title="setting" type="profile" onClick={() => profileCard(id)} /> : null} |
| | | </div> |
| | | <Icon className="edit" title="edit" type="edit" onClick={() => editCard(id)} /> |
| | | <Icon className="edit copy" title="copy" type="copy" onClick={() => copyCard(id)} /> |
| | | <Icon className="edit close" title="close" type="close" onClick={() => delCard(id)} /> |
| | | {hasProfile ? <Icon className="edit profile" title="setting" type="profile" onClick={() => profileCard(id)} /> : null} |
| | | </div> |
| | | } trigger="hover"> |
| | | <div className="page-card" style={{ opacity: opacity}}> |
| | | <div ref={node => drag(drop(node))}> |
| | | {btnElement} |
| | | </div> |
| | | </div> |
| | | </Popover> |
| | | ) |
| | | } |
| | | export default Card |