-
-
Save jennielees/6b795b17a32e97b38117 to your computer and use it in GitHub Desktop.
From http://reactfordesigners.com/labs/reactjs-introduction-for-people-who-know-just-enough-jquery-to-get-by/ - http://jsbin.com/fenofa/
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> | |
<head> | |
<script src="http://fb.me/react-0.13.1.js"></script> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="jsbin.fenofa.js"></script> | |
</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
var TweetBox = React.createClass({displayName: 'TweetBox', | |
render: function() { | |
return ( | |
React.createElement("div", {className: "well clearfix"}, | |
this.overflow(), | |
React.createElement("textarea", {className: "form-control", onChange: this.handleChange}), | |
React.createElement("br", null), | |
this.remainingCharacters(), | |
React.createElement("button", {className: "btn btn-primary pull-right", disabled: this.state.text.length == 0 && !this.state.photo}, "Tweet"), | |
React.createElement("button", {onClick: this.togglePhoto, className: "btn btn-default pull-right"}, " ", this.state.photo ? "✓ Photo Added" : "Add Photo" | |
) | |
) | |
); | |
}, | |
overflow: function() { | |
if (this.remainingCharacters() < 0) { | |
var okText = this.state.text.substring(140-10, 140); | |
var badText = this.state.text.substring(140); | |
return ( | |
React.createElement("div", {className: "alert alert-warning"}, | |
"Oops! Too Long: ...", okText, React.createElement("strong", {className: "bg-danger"}, badText) | |
) | |
) | |
} | |
}, | |
handleChange: function(event) { | |
this.setState({ text: event.target.value }); | |
}, | |
togglePhoto: function(event) { | |
this.setState({ photo: !this.state.photo }); | |
}, | |
remainingCharacters: function() { | |
base = 140 - this.state.text.length; | |
if (this.state.photo) { | |
base -= 23; | |
} | |
return base; | |
}, | |
getInitialState: function () { | |
return { | |
text: "", | |
photo: false | |
}; | |
} | |
}); | |
React.render( | |
React.createElement(TweetBox, null), | |
document.body | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment