-
Notifications
You must be signed in to change notification settings - Fork 51
/
Handle.tsx
118 lines (114 loc) · 3.27 KB
/
Handle.tsx
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as React from 'react';
import { List, arrayMove, arrayRemove } from '../src/index';
const HandleIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="#555"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="feather feather-move"
>
<polyline points="5 9 2 12 5 15" />
<polyline points="9 5 12 2 15 5" />
<polyline points="15 19 12 22 9 19" />
<polyline points="19 9 22 12 19 15" />
<line x1="2" y1="12" x2="22" y2="12" />
<line x1="12" y1="2" x2="12" y2="22" />
</svg>
);
const buttonStyles = {
border: 'none',
margin: 0,
padding: 0,
width: 'auto',
overflow: 'visible',
cursor: 'pointer',
background: 'transparent'
};
class Handle extends React.Component<{}, { items: string[] }> {
state = {
items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6']
};
render() {
return (
<div
style={{
maxWidth: '300px',
margin: '0px auto',
backgroundColor: '#F7F7F7',
padding: '3em',
textAlign: 'center'
}}
>
<List
values={this.state.items}
onChange={({ oldIndex, newIndex }) =>
this.setState((prevState: { items: string[] }) => ({
items: arrayMove(prevState.items, oldIndex, newIndex)
}))
}
renderList={({ children, props, isDragged }) => (
<ul
{...props}
style={{
padding: '0em 0em 1em 0em',
cursor: isDragged ? 'grabbing' : 'inherit'
}}
>
{children}
</ul>
)}
renderItem={({ value, props, isDragged, isSelected }) => (
<li
{...props}
style={{
...props.style,
padding: '1.5em',
margin: '0.5em 0em',
listStyleType: 'none',
border: '2px solid #CCC',
boxShadow: '3px 3px #AAA',
color: '#333',
borderRadius: '5px',
cursor: isDragged ? 'grabbing' : 'inherit',
fontFamily: 'Arial, "Helvetica Neue", Helvetica, sans-serif',
backgroundColor: isDragged || isSelected ? '#EEE' : '#FFF'
}}
>
<div
style={{
display: 'flex',
alignItems: 'center'
}}
>
{/*
Mark any node with the data-movable-handle attribute if you wish
to use is it as a DnD handle. The rest of renderItem will be then
ignored and not start the drag and drop.
*/}
<button
data-movable-handle
style={{
...buttonStyles,
cursor: isDragged ? 'grabbing' : 'grab',
marginRight: '3em'
}}
tabIndex={-1}
>
<HandleIcon />
</button>
<div>{value}</div>
</div>
</li>
)}
/>
</div>
);
}
}
export default Handle;