forked from qynAUGMN/react-drag-guideline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (55 loc) · 1.58 KB
/
index.js
File metadata and controls
61 lines (55 loc) · 1.58 KB
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
import React from 'react'
import ReactDOM from 'react-dom'
import { DraggableContainer, DraggableChild } from './src/index'
const initialChildren = [
{ id: 1, background: '#8ce8df', size: 100, position: { x: 100, y: 10 } },
{ id: 2, background: '#8ce8df', size: 100, position: { x: 400, y: 106 } },
{ id: 3, background: '#d2aff6', size: 150, position: { x: 100, y: 316 } },
{ id: 4, background: '#fee493', size: 200, position: { x: 480, y: 376 } },
]
function App() {
const containerStyle = {
position: 'relative',
height: 600,
boxShadow: '0 0 5px 1px #CCC inset',
background: '#F5F8FA',
color: '#4A4A4A',
margin: 20,
}
const childStyle = {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
cursor: 'move',
}
return (
<div>
<style>{'.active { opacity: .5; }'}</style>
<DraggableContainer style={containerStyle}>
{
initialChildren.map(({ id, background, size, position }) => (
<DraggableChild
key={id}
defaultPosition={position}
>
<div
className="item"
style={{
...childStyle,
background,
width: size,
height: size,
}}
>
<span>size: {size}</span>
<span>drag me</span>
</div>
</DraggableChild>
))
}
</DraggableContainer>
</div>
)
}
ReactDOM.render(<App />, document.getElementById('root'))