-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
51 lines (45 loc) · 1.02 KB
/
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
class Example extends React.Component {
constructor() {
super()
this.selection = new Multiselect()
}
onClick(event, index) {
console.log('click', index)
if (event.metaKey) {
this.selection.commandClick(index)
} else if (event.shiftKey) {
this.selection.shiftClick(index)
} else {
this.selection.click(index)
}
this.forceUpdate()
}
render() {
const indexes = []
for (var i = 0; i < 100; i++) {
indexes.push(i)
}
const elements = []
indexes.forEach((i) => {
let style = {height: '16px', userSelect: 'none', '-webkit-user-select': 'none'}
if (this.selection.isSelected(i)) {
style.backgroundColor = 'blue'
style.color = 'white'
}
elements.push(
<div key={i} style={style} onClick={(event) => { this.onClick(event, i) }}>
element - {i}
</div>
)
})
return (
<div>
{elements}
</div>
)
}
}
ReactDOM.render(
<Example/>,
document.getElementById('root')
)