Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                doctype html
html(lang="en")
  head
    title="Camper Leaderboard"
  header
    div.title-div
      h1 Free Code Camper Leaderboard
  body
    div#react-app 
  footer
    p by Jennifer Hsu
              
            
!

CSS

              
                $color1: #381F0B
$color2: #1866e2
$color3: #FFFFFF

body
  background: $color3
header, footer
  background: $color1
  color: $color3
  text-align: center
.title-div
  min-height: 100px
  padding: 30px
footer
  min-height: 50px
  padding: 15px
.coderimg
  height: 50px
  width: 50px
  margin: 5px 20px 5px 5px
.table
  width: 80%
  margin-top: 30px
  margin-left: auto
  margin-right: auto
  text-align: center
  .col1
    width: 15%
  .col2
    width: 55%
    text-align: left
  .col3
    width: 15%
  .col4
    width: 15%
.table > tbody > tr > td
  vertical-align: middle
.table > thead > tr > td
  vertical-align: middle
  font-weight: bold
  background-color: $color2
button
  background: none
  border: none

              
            
!

JS

              
                const top_30_days_url = "https://fcctop100.herokuapp.com/api/fccusers/top/recent";
const top_all_time_url = "https://fcctop100.herokuapp.com/api/fccusers/top/alltime";

var CoderList = React.createClass({
  propsTypes: {
    url: React.PropTypes.object.isRequired
  },
  render: function () {
    var coderRows = this.props.data.map(function(coder, idx) {
      return (
        <tr key={"coder_idx"+idx}>
          <td className="col1">{idx+1}</td>
          <td className="col2"><img src={coder.img} className="coderimg" />{coder.username}</td>
          <td className="col3">{coder.recent}</td>
          <td className="col4">{coder.alltime}</td>
        </tr>
      );
    });
    return <tbody>{coderRows}</tbody>;
  }
});

var CoderData = React.createClass({
  propsTypes: {
    url: React.PropTypes.string.isRequired
  },
  loadCodersFromServer: function() {
    $.ajax({
      url: this.props.url,
      dataType: 'json',
      cache: false,
      success: function(data) {
        this.setState({data: data});
      }.bind(this),
      error: function(xhr, status, err) {
        console.error(this.props.url, status, err.toString());
      }.bind(this)
    });
  },
  getInitialState: function() {
    return {data: []};
  },
  componentDidMount: function() {
    this.loadCodersFromServer();
  },
  componentDidUpdate: function() {
    this.loadCodersFromServer();
  },
  render: function() {
    return (
      <CoderList data={this.state.data} />
    );
  }
});

var CoderTable = React.createClass({
    getInitialState: function() {
      return {url: top_all_time_url};
    },
    handleSortBy30: function() {
      if (this.state.url === top_all_time_url) {
        this.setState({url: top_30_days_url});
      }
    },
    handleSortByAll: function() {
      if (this.state.url !== top_all_time_url) {
        this.setState({url: top_all_time_url});
      }
    },
    render: function() {
        return (
          <table className="table table-striped">
            <thead>
              <tr>
                <td className="col1">#</td>
                <td className="col2">User</td>
                <td className="col3"><button onClick={this.handleSortBy30}>Points in past 30 days <span className="glyphicon glyphicon-chevron-down" aria-hidden="true"></span></button></td>
                <td className="col4"><button onClick={this.handleSortByAll}>Points in all time <span className="glyphicon glyphicon-chevron-down" aria-hidden="true"></span></button></td>
              </tr>
            </thead>
            <CoderData url={this.state.url} />
          </table>
        );
    }
});

ReactDOM.render(<CoderTable />, document.getElementById('react-app'));
              
            
!
999px

Console