Last active
August 29, 2015 14:04
-
-
Save kouphax/97be0808b32f8a9fa004 to your computer and use it in GitHub Desktop.
React Workshop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- IN STOCK ITEM --> | |
<div class="paint"> | |
<div class="preview"></div> | |
<p>{ name }</p> | |
<div class="buy"> | |
{ quantity } Left <button>Buy</button> | |
</div> | |
</div> | |
<!-- OUT OF STOCK ITEM --> | |
<div class="paint"> | |
<div class="preview"></div> | |
<p>{ name }</p> | |
<div class="buy"> | |
<button disabled>OUT OF STOCK</button> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Paint = React.createClass({ | |
renderPreview: function() { | |
return React.DOM.div({ | |
className: "preview", | |
style: { | |
backgroundColor: this.props.preview | |
} | |
}); | |
}, | |
renderButton: function() { | |
if(this.props.quantity == 0) { | |
return React.DOM.div({ className: "buy" }, | |
React.DOM.button(null, "OUT OF STOCK")); | |
} else { | |
return React.DOM.div({ className: "buy"}, | |
this.props.quantity + " Left ", | |
React.DOM.button(null, "Buy")); | |
} | |
}, | |
render: function() { | |
return React.DOM.div( { className: "paint" }, | |
this.renderPreview(), | |
React.DOM.p(null, this.props.name), | |
this.renderButton()); | |
} | |
}); | |
var Paints = React.createClass({ | |
render: function() { | |
var list = this.props.paints.map(function(paint){ | |
paint["key"] = paint["preview"]; | |
return Paint(paint); | |
}); | |
return React.DOM.div(null, list); | |
} | |
}); | |
React.renderComponent(Paints({ paints: [ | |
{name: "Blue", quantity: 0, preview: "#666"}, | |
{name: "Black", quantity: 10, preview: "#111"}, | |
{name: "Other", quantity: 8, preview: "#999"} | |
]}), | |
document.getElementById("container")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment