-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
RootItem.js
152 lines (139 loc) · 4.14 KB
/
RootItem.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import React from 'react';
import PropTypes from 'prop-types';
import style from 'PVWStyle/ReactWidgets/CompositePipelineWidget.mcss';
import ChildItem from './ChildItem';
/**
* This React component expect the following input properties:
* - model:
* Expect a LokkupTable instance that you want to render and edit.
* - item:
* Root of the tree
* - layer:
* Layer id.
*/
export default class CompositePipelineWidgetRootItem extends React.Component {
constructor(props) {
super(props);
this.state = {
dropDown: false,
};
// Bind callback
this.toggleVisibility = this.toggleVisibility.bind(this);
this.toggleDropDown = this.toggleDropDown.bind(this);
this.updateColorBy = this.updateColorBy.bind(this);
this.toggleEditMode = this.toggleEditMode.bind(this);
this.updateOpacity = this.updateOpacity.bind(this);
}
toggleVisibility() {
this.props.model.toggleLayerVisible(this.props.layer);
}
toggleDropDown() {
if (this.props.model.getColor(this.props.layer).length > 1) {
this.setState({
dropDown: !this.state.dropDown,
});
}
}
updateColorBy(event) {
this.props.model.setActiveColor(
this.props.layer,
event.target.dataset.color
);
this.toggleDropDown();
}
toggleEditMode() {
this.props.model.toggleEditMode(this.props.layer);
}
updateOpacity(e) {
this.props.model.setOpacity(this.props.layer, e.target.value);
this.forceUpdate();
}
render() {
const model = this.props.model;
const layer = this.props.layer;
const visible = model.isLayerVisible(this.props.layer);
const children = this.props.item.children || [];
const inEditMode = this.props.model.isLayerInEditMode(this.props.layer);
const hasChildren = children.length > 0;
const hasOpacity = model.hasOpacity();
const hasDropDown = this.props.model.getColor(this.props.layer).length > 1;
const editButton = hasChildren ? (
<i
className={inEditMode ? style.editButtonOn : style.editButtonOff}
onClick={this.toggleEditMode}
/>
) : (
''
);
return (
<div className={style.section}>
<div className={style.item}>
<div className={style.label}>{this.props.item.name}</div>
<div className={style.actions}>
{editButton}
<i
className={
visible ? style.visibleButtonOn : style.visibleButtonOff
}
onClick={this.toggleVisibility}
/>
<i
className={
hasDropDown ? style.dropDownButtonOn : style.dropDownButtonOff
}
onClick={this.toggleDropDown}
/>
<div
onClick={this.updateColorBy}
className={this.state.dropDown ? style.menu : style.hidden}
>
{model.getColor(layer).map((color) => (
<div
key={color}
data-color={color}
className={
model.isActiveColor(layer, color)
? style.selectedMenuItem
: style.menuItem
}
>
{model.getColorToLabel(color)}
</div>
))}
</div>
</div>
</div>
<div className={hasOpacity && !hasChildren ? style.item : style.hidden}>
<input
className={style.opacity}
type="range"
min="0"
max="100"
value={model.getOpacity(layer)}
onChange={this.updateOpacity}
/>
</div>
<div className={style.children}>
{children.map((item, idx) => (
<ChildItem
key={idx}
item={item}
layer={item.ids.join('')}
model={model}
/>
))}
</div>
</div>
);
}
}
CompositePipelineWidgetRootItem.propTypes = {
item: PropTypes.object,
layer: PropTypes.string,
model: PropTypes.object,
};
CompositePipelineWidgetRootItem.defaultProps = {
item: undefined,
layer: undefined,
model: undefined,
};