Last active
August 29, 2015 14:17
-
-
Save sethmcl/eb6153744601a01078c4 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
| const Question = React.createClass({ | |
| handleGetStarted: function(event) { | |
| this.nextQuestion(event); | |
| }, | |
| qdata: [ | |
| { | |
| id: 0, | |
| type: "m-choice", | |
| question: "Are you ready to get started?", | |
| options: [ | |
| { | |
| value: "Oh yeah!", | |
| handler: "handleGetStarted" | |
| } | |
| ] | |
| }, | |
| render: function () { | |
| var currQuestion = qdata[this.state.questionId] | |
| if (currQuestion.type === "m-choice") { | |
| var answers = <MChoiceAnswers options={currQuestion.options} question={this} /> ; | |
| } else if (currQuestion.type === "text") { | |
| var answers = <TextAnswers question={currQuestion} /> ; | |
| } | |
| return ( | |
| <div className="question"> | |
| <p> {currQuestion.question } </p> | |
| {answers} | |
| </div> | |
| ); | |
| } | |
| }); | |
| const MChoiceAnswers = React.createClass({ | |
| render: function() { | |
| var createItem = function(answer) { | |
| return ( | |
| <Button onClick={ this.props.question[answer.handler].bind(this.props.question) }> { answer.value } </Button> | |
| ); | |
| }; | |
| return ( | |
| <div> | |
| {this.props.options.map(createItem) } | |
| </div> | |
| ); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment