forked from herstand/learning-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter12.html
More file actions
94 lines (90 loc) · 1.94 KB
/
Chapter12.html
File metadata and controls
94 lines (90 loc) · 1.94 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Chapter 12!</title>
<style type='text/css'>
html, body {
padding:0;
margin:0;
width:100%;
height:100%;
}
#container {
width:100%;
height:100%;
padding:50px;
background-color:#FFFFFF;
}
.colorSquare {
box-shadow: 0px 0px 25px 0px #333;
width: 242px;
height: 242px;
margin-bottom: 15px;
}
.colorArea input {
padding: 10px;
font-size: 16px;
border: 2px solid #CCC;
}
.colorArea button {
padding: 10px;
font-size: 16px;
margin: 10px;
background-color: #666;
color: #FFF;
border: 2px solid #666;
}
.colorArea button:hover {
background-color: #111;
border-color: #111;
cursor: pointer;
}
</style>
<script src="react/react.js"></script>
<script src="react/react-dom.js"></script>
<script src="react/babel.min.js"></script>
</head>
<body>
<main id="container"></main>
<script type="text/babel">
(function(){
var destination = document.querySelector("#container");
var Colorizer = React.createClass({
getInitialState: function() {
return {
color: '',
bgColor: ''
}
},
colorValue: function(e) {
this.setState({color: e.target.value});
},
setNewColor: function(e){
this.setState({bgColor: this.state.color});
e.preventDefault();
},
render: function() {
var squareStyle = {
backgroundColor: this.state.bgColor
};
return (
<div className="colorArea">
<div style={squareStyle} className="colorSquare"></div>
<form onSubmit={this.setNewColor}>
<input onChange={this.colorValue} placeholder="Enter a color value"></input>
<button type="submit">go</button>
</form>
</div>
);
}
});
ReactDOM.render(
<div>
<Colorizer/>
</div>,
destination
);
}());
</script>
</body>
</html>