Created
June 27, 2016 19:07
-
-
Save jmsevold/d92e57de2e07324231982a2a8e8473af to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class TweetBox extends React.Component { | |
constructor(){ | |
super() | |
this.state = { | |
text: "", | |
photoAdded: false | |
}; | |
} | |
render() { | |
let buttonText = this.state.photoAdded ? "Photo Added" : "Add Photo"; | |
return ( | |
<div className="well clearfix"> | |
<textarea | |
className="form-control" | |
onChange={this.handleChange.bind(this)}></textarea> | |
<br/> | |
<button | |
className="btn btn-primary pull-right" | |
disabled={this.state.text.length < 1 && !this.state.photoAdded}> | |
Tweet | |
</button> | |
<span>{remainingCharacters()}</span> | |
<button | |
class="btn btn-default pull-right" | |
onClick={this.handleClick.bind(this)}>{buttonText}</button> | |
</div> | |
); | |
} | |
remainingCharacters(){ | |
let sum = let sum = this.state.photoAdded ? 23 : 0; | |
return 140 - this.state.text.length - sum; | |
} | |
handleClick(){ | |
this.setState({ | |
photoAdded: !this.state.photoAdded | |
}); | |
} | |
handleChange(e){ | |
let value = e.target.value; | |
this.setState({ | |
text: value | |
}); | |
} | |
} | |
ReactDOM.render( | |
<TweetBox />, | |
document.getElementById("container") | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment