-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (44 loc) · 1.34 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
'use strict';
class App extends React.Component {
constructor(props) {
super(props);
this.state = { currentColor: 'rgb(255,0,0)' }; // todo find initial value
this.setColor = this.setColor.bind(this);
}
componentDidMount() {
const { currentColor } = this.state;
const colorPicker = new iro.ColorPicker("#color-picker", {
width: 320,
color: currentColor,
});
colorPicker.on('color:change', color => {
this.setState({ currentColor: color.rgbString });
});
}
setColor() {
const { currentColor } = this.state;
// we don't really care about response...
fetch(`/set-color?color=${this.trimRgbString(currentColor)}`);
}
// trims "rgb(255,0,0)" string from color picker to only include the comma delimited numbers (removes "rgb" & the parenthesis)
trimRgbString(rgb) {
return rgb.substr(4, rgb.length - 5);
}
render() {
return (
<div className="container">
<div>
<div id="color-picker"></div>
<div className="button">
<div className="buttonFace">
<button className="circle" onClick={this.setColor}></button>
</div>
</div>
</div>
</div>
);
}
}
// Mount the React app.
const domContainer = document.querySelector('#app');
ReactDOM.render(React.createElement(App), domContainer);