-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
layer-selector.js
65 lines (57 loc) · 1.71 KB
/
layer-selector.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
import React, {PureComponent} from 'react';
import LayerControls from './layer-controls';
import PropTypes from 'prop-types';
const propTypes = {
examples: PropTypes.object,
activeExamples: PropTypes.object,
onToggleLayer: PropTypes.func.isRequired,
onUpdateLayer: PropTypes.func.isRequired
};
export default class LayerSelector extends PureComponent {
_renderExampleButton(exampleName, example) {
const {activeExamples} = this.props;
const settings = activeExamples[exampleName];
return (
<div key={exampleName}>
<div className="checkbox">
<input
type="checkbox"
id={exampleName}
checked={Boolean(settings)}
onChange={() => this.props.onToggleLayer(exampleName, example)}
/>
<label htmlFor={exampleName}>
<span>{exampleName}</span>
</label>
</div>
{settings && (
<LayerControls
settings={settings}
layer={example.layer}
propTypes={example.propTypes}
onChange={this.props.onUpdateLayer.bind(this, exampleName)}
/>
)}
</div>
);
}
_renderExampleCategories(examples) {
return Object.keys(examples).map(categoryName => {
const category = examples[categoryName];
return (
<div key={categoryName}>
<h4>{categoryName}</h4>
{Object.keys(category).map(exampleName =>
this._renderExampleButton(exampleName, category[exampleName])
)}
</div>
);
});
}
render() {
return (
<div className="layer-selector">{this._renderExampleCategories(this.props.examples)}</div>
);
}
}
LayerSelector.propTypes = propTypes;