-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
69 lines (60 loc) · 1.62 KB
/
index.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
import React from 'react';
import PropTypes from 'prop-types';
import style from 'PVWStyle/ReactWidgets/PresetListWidget.mcss';
export default class PresetListWidget extends React.Component {
constructor(props) {
super(props);
this.state = {
activeName: props.activeName,
};
// Bind callback
this.updateActive = this.updateActive.bind(this);
}
updateActive(event) {
const activeName = event.target.dataset.name;
this.setState({ activeName });
if (this.props.onChange) {
this.props.onChange(activeName);
}
}
render() {
if (!this.props.presets || !this.props.visible) {
return null;
}
const activeName = this.state.activeName;
const height = this.props.height;
const presets = this.props.presets;
const names = Object.keys(presets);
return (
<div className={style.container}>
<div className={style.bottomPadding} />
{names.map((name) => (
<img
alt="Preset"
src={`data:image/png;base64,${presets[name]}`}
key={name}
style={{ height }}
data-name={name}
onClick={this.updateActive}
className={name === activeName ? style.activeLine : style.line}
/>
))}
<div className={style.bottomPadding} />
</div>
);
}
}
PresetListWidget.propTypes = {
activeName: PropTypes.string,
height: PropTypes.string,
onChange: PropTypes.func,
presets: PropTypes.object,
visible: PropTypes.bool,
};
PresetListWidget.defaultProps = {
activeName: '',
height: '1em',
presets: {},
visible: true,
onChange: undefined,
};