Skip to content

Instantly share code, notes, and snippets.

@jennielees
Forked from anonymous/index.html
Last active August 29, 2015 14:25
Show Gist options
  • Save jennielees/6b795b17a32e97b38117 to your computer and use it in GitHub Desktop.
Save jennielees/6b795b17a32e97b38117 to your computer and use it in GitHub Desktop.
<!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>
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