-
Notifications
You must be signed in to change notification settings - Fork 38
/
DragItem.js
45 lines (42 loc) 路 1.08 KB
/
DragItem.js
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
// @flow
import React from 'react';
import { DragSource } from 'react-dnd';
import styled from 'styled-components';
import { smColors } from '/vars';
// $FlowStyledIssue
const Wrapper = styled.div`
height: 32px;
line-height: 32px;
text-align: center;
width: 140px;
border-radius: 2px;
background-color: ${({ isDropped }) => (isDropped ? smColors.borderGray : smColors.green)};
margin-right: 10px;
color: ${smColors.white};
opacity: ${({ isDragging }) => (isDragging ? 0.4 : 1)};
cursor: pointer;
`;
type Props = {
word: string,
isDropped: boolean,
isDragging: boolean,
connectDragSource: any
};
const DragItem = (props: Props) => {
const { word, isDropped, isDragging, connectDragSource } = props;
return (
<Wrapper ref={connectDragSource} isDragging={isDragging} isDropped={isDropped}>
{isDropped ? '' : word}
</Wrapper>
);
};
export default DragSource(
'item',
{
beginDrag: (props: Props) => ({ word: props.word })
},
(connect, monitor) => ({
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
})
)(DragItem);