forked from parse-community/parse-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDragHandle.example.js
132 lines (121 loc) · 3.8 KB
/
DragHandle.example.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
import DataBrowserHeader from 'components/DataBrowserHeader/DataBrowserHeader.react';
import DragHandle from 'components/DragHandle/DragHandle.react';
import { HTML5Backend } from 'react-dnd-html5-backend';
import React from 'react';
import { DndProvider } from 'react-dnd';
export const component = DragHandle;
class DragDemo extends React.Component {
constructor() {
super();
this.state = { x: 100, y: 100 };
}
handleDrag(dx, dy) {
this.setState(({ x, y }) => {
const newX = Math.max(0, Math.min(x + dx, 480));
const newY = Math.max(0, Math.min(y + dy, 480));
return { x: newX, y: newY };
});
}
render() {
const style = {
width: 20,
height: 20,
background: '#5298fc',
borderRadius: 10,
cursor: 'move',
position: 'absolute',
left: this.state.x,
top: this.state.y,
};
return (
<div
style={{
position: 'relative',
width: 500,
height: 500,
border: '1px solid #e3e3e3',
margin: '40px auto',
}}
>
<DragHandle onDrag={this.handleDrag.bind(this)} style={style} />
</div>
);
}
}
const lightBg = { background: 'rgba(224,224,234,0.10)' };
const handleStyle = {
position: 'relative',
display: 'inline-block',
width: 4,
height: 30,
marginLeft: -2,
marginRight: -2,
cursor: 'ew-resize',
};
class HeadersDemo extends React.Component {
constructor() {
super();
this.state = {
widths: [140, 140, 140, 140, 140, 140],
};
}
handleDrag(index, dx) {
this.setState(({ widths }) => {
widths[index] = Math.max(40, widths[index] + dx);
return { widths };
});
}
render() {
return (
<DndProvider backend={HTML5Backend}>
<div style={{ height: 30, background: '#66637A', whiteSpace: 'nowrap' }}>
<div style={{ display: 'inline-block', width: this.state.widths[0] }}>
<DataBrowserHeader name="objectId" type="Special" />
</div>
<DragHandle style={handleStyle} onDrag={this.handleDrag.bind(this, 0)} />
<div style={{ display: 'inline-block', width: this.state.widths[1] }}>
<DataBrowserHeader name="createdAt" type="Date" style={lightBg} />
</div>
<DragHandle style={handleStyle} onDrag={this.handleDrag.bind(this, 1)} />
<div style={{ display: 'inline-block', width: this.state.widths[2] }}>
<DataBrowserHeader name="updatedAt" type="Date" />
</div>
<DragHandle style={handleStyle} onDrag={this.handleDrag.bind(this, 2)} />
<div style={{ display: 'inline-block', width: this.state.widths[3] }}>
<DataBrowserHeader name="name" type="String" style={lightBg} />
</div>
<DragHandle style={handleStyle} onDrag={this.handleDrag.bind(this, 3)} />
<div style={{ display: 'inline-block', width: this.state.widths[4] }}>
<DataBrowserHeader name="owner" type="Pointer<_User>" />
</div>
<DragHandle style={handleStyle} onDrag={this.handleDrag.bind(this, 4)} />
<div style={{ display: 'inline-block', width: this.state.widths[5] }}>
<DataBrowserHeader
name="really_long_column_name_that_overflows"
type="String"
style={lightBg}
/>
</div>
<DragHandle style={handleStyle} onDrag={this.handleDrag.bind(this, 5)} />
</div>
</DndProvider>
);
}
}
export const demos = [
{
name: 'Drag the ball',
render: () => <DragDemo />,
},
{
name: 'Data Browser Headers',
render: () => <HeadersDemo />,
},
];