-
Notifications
You must be signed in to change notification settings - Fork 0
/
13-application-paintlist-1.html
68 lines (60 loc) · 2.1 KB
/
13-application-paintlist-1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>React Workshop</title>
<link href="https://rawgit.com/kouphax/static/master/react-workshop/stylesheets/styles.css" rel="stylesheet">
</head>
<body>
<!-- NOT REQUIRED FOR REACT BUT MAY BE HANDY LATER -->
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- REACT CORE LIBRARY (DEVELOPMENT VERSION) -->
<script src="http://fb.me/react-0.11.1.js"></script>
<!-- ONLY NEEDED FOR JSX FOR DEVELOPMENT AND PROTOTYPING -->
<script src="http://fb.me/JSXTransformer-0.11.1.js"></script>
<div id="container"></div>
<script>
var BuyButton = React.createClass({
render: function(){
if(this.props.quantity == 0) {
return React.DOM.div({className: 'buy'},
React.DOM.button({disabled: true}, "OUT OF STOCK"))
} else {
return React.DOM.div({className: 'buy'},
"£" + this.props.price.toFixed(2) + " ", React.DOM.button(null, 'Buy'))
}
}
})
var Paint = React.createClass({
render: function() {
return React.DOM.div({className: 'paint'},
React.DOM.div({
className: 'preview',
style: {
backgroundColor: this.props.code
}
}),
React.DOM.p(null, this.props.title),
BuyButton({quantity: this.props.quantity, price: this.props.price}))
}
})
var PaintList = React.createClass({
render: function(){
return React.DOM.div(null, [
Paint({title: "Blue", quantity: 10, price: 2.30, code: '#006', key: 1}),
Paint({title: "Green", quantity: 0, price: 1.50, code: '#060', key: 2}),
Paint({title: "Red", quantity: 1, price: 1.00, code: '#600', key: 3}),
Paint({title: "Black", quantity: 14, price: 4.00, code: '#000', key: 4})
])
}
})
var Application = React.createClass({
render: function() {
return React.DOM.div(null, PaintList());
}
})
React.renderComponent(Application(),
document.getElementById('container'))
</script>
</body>
</html>