-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathApp.js
90 lines (85 loc) · 2.14 KB
/
App.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
import React, { Component } from 'react';
import objectAssign from 'object-assign';
import RegionSelect from '../RegionSelect';
require('./style.css');
class App extends Component {
constructor (props) {
super(props);
this.regionRenderer = this.regionRenderer.bind(this);
this.onChange = this.onChange.bind(this);
this.state = {
regions: []
};
}
onChange (regions) {
this.setState({
regions: regions
});
}
changeRegionData (index, event) {
const region = this.state.regions[index];
let color;
switch (event.target.value) {
case '1':
color = 'rgba(0, 255, 0, 0.5)';
break;
case '2':
color = 'rgba(0, 0, 255, 0.5)';
break;
case '3':
color = 'rgba(255, 0, 0, 0.5)';
break;
default:
color = 'rgba(0, 0, 0, 0.5)';
}
region.data.regionStyle = {
background: color
};
this.onChange([
...this.state.regions.slice(0, index),
objectAssign({}, region, {
data: objectAssign({}, region.data, { dataType: event.target.value })
}),
...this.state.regions.slice(index + 1)
]);
}
regionRenderer (regionProps) {
if (!regionProps.isChanging) {
return (
<div style={{ position: 'absolute', right: 0, bottom: '-1.5em' }}>
<select onChange={(event) => this.changeRegionData(regionProps.index, event)} value={regionProps.data.dataType}>
<option value='1'>Green</option>
<option value='2'>Blue</option>
<option value='3'>Red</option>
</select>
</div>
);
}
}
render() {
const regionStyle = {
background: 'rgba(255, 0, 0, 0.5)'
};
return (
<div style={{ display: 'flex' }}>
<div style={{ flexGrow: 1, flexShrink: 1, width: '50%' }}>
<RegionSelect
maxRegions={1}
regions={this.state.regions}
regionStyle={regionStyle}
constraint
onChange={this.onChange}
regionRenderer={this.regionRenderer}
style={{ border: '1px solid black' }}
>
<img src='/static/example-doc.jpg' width='100%'/>
</RegionSelect>
</div>
<div style={{ flexGrow: 1, flexShrink: 1, width: '50%', padding: 15 }}>
Select something with your mouse on the left side
</div>
</div>
);
}
}
module.exports = App;