cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              const {
  Router,
  Route,
  Link,
  IndexRoute,
  hashHistory
} = ReactRouter;

class PromptContainer extends React.Component {
  constructor(props) {
    super(props)
    this.state = { username: '' }
    this.onUpdateUser = this.onUpdateUser.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  onUpdateUser(event) {
    this.setState({
      username: event.target.value
    });
  }

  handleSubmit(event) {
    event.preventDefault()

    if (this.props.params.playerOne) {
      // go to battle
      alert("sorry game isn't quite finished yet");
    } else {
      this.context.router.push('/playerTwo/' + this.state.username)
    }
    this.setState({ username: '' })
  }

  render () {
    return (
       <div className="jumbotron col-sm-6 col-sm-offset-3 text-center transparentBg">
        <h1>{this.props.route.header}</h1>
        <div className="col-sm-12">
          <form onSubmit={this.handleSubmit}>
            <div className="form-group">
              <input 
                className="form-control" 
                placeholder="Github Username"
                type="text"
                onChange={this.onUpdateUser} 
                value={this.state.username} />
            </div>
            <div className="form-group col-sm-4 col-sm-offset-4">
              <button
                className="btn btn-block btn-success"
                type="submit">
                  Continue
              </button>
            </div>
          </form>
        </div>
       </div>
    );
  }
}

PromptContainer.contextTypes = {
  router: React.PropTypes.object
};

class App extends React.Component {
  render() {
    return (
      <div>
        <h1 className='text-center'>Github Battle</h1>
        {this.props.children}
      </div>
    ) 
  }
}

class Home extends React.Component {
  render() {
    return (
      <div className="jumbotron col-sm-12 text-center transparentBg" >
        <Link to='/playerOne'>
          <button type='button' className='btn btn-lg btn-success'>
            Get Started
          </button>
        </Link>
      </div>
    )
  }
}

class Routes extends React.Component {
  render() {
    return (
       <Router history={hashHistory}>
          <Route path='/' component={App}>
            <IndexRoute component={Home}></IndexRoute>
            <Route path='playerOne' header='Player One' component={PromptContainer} />
            <Route path='playerTwo/:playerOne' header='Player Two' component={PromptContainer} />
          </Route>
      </Router>
     )
  }
}

ReactDOM.render(<Routes />, document.getElementById('app'))
            
          
!
999px
Loading ..................

Console