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

              
                <div id="camper-app"></div>
              
            
!

CSS

              
                body
  background-color: #515151
  a
    transition: color 0.2s
    &:hover, &:active, &:focus
      text-decoration: none

.table
  margin-top: 30px
  margin-bottom: 30px
  box-shadow: 0px 0px 20px 2px rgba(0,0,0,0.75)
    
.table caption
  background-color: #BED2D9
  border-top-left-radius: 4px
  border-top-right-radius: 4px
  box-shadow: 0px 0px 20px 2px rgba(0,0,0,0.75)
  color: #333
  font-family: 'Passion One', sans-serif
  text-align: center
  text-transform: uppercase
  a
    color: #F07509
    &:hover, &:focus, &:active
      color: #F89D4E
thead
  font-family: 'Bitter', serif
  tr
    background-color: #BED2D9
    .points
      text-align: center

tbody
  font-family: 'Lato', sans-serif
  tr
    background-color: #ECF1F2
    &:last-of-type
      td:first-of-type
        border-bottom-left-radius: 4px
      td:last-of-type
        border-bottom-right-radius: 4px
    img
      height: 28px
      margin-right: 10px
    a
      color: #4B8083
      &:hover, &:focus, &:active
        color: #F89D4E
    .points
      text-align: center
    
.table-striped>tbody>tr:nth-of-type(odd)
  background-color: #F7F9FE

.table-hover>tbody>tr:hover
  background-color: #EEEEEE
  
.table>tbody>tr>td
  vertical-align: middle

// sorting 'link' styling
thead span
  &.recent, &.alltime
    color: #4B8083
    transition: color 0.2s
    &:hover, &:focus, &:active
      color: #5E9FA3
  &.active
    color: #F07509
    &:hover, &:focus, &:active
      color: #F89D4E
    .glyphicon
      display: inline
  &:hover
    cursor: pointer
  .glyphicon
    display: none

// transitions
.fade-enter 
  opacity: 0.01

.fade-enter.fade-enter-active 
  opacity: 1
  transition: opacity 500ms ease-in

.fade-leave 
  opacity: 1

.fade-leave.fade-leave-active 
  opacity: 0.01
  transition: opacity 300ms ease-in

              
            
!

JS

              
                var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup; //allow React flavored transitions

class Application extends React.Component {
  // alternative to getInitialState
  constructor() {
    super();
    this.state = {
      search: "alltime",
      camperArr: [],
      asc: true
    };
  }

  // after Component mounts, all the api
  componentDidMount() {
    this.callApi("alltime");
  }

  // accepts a string 'alltime'/'recent' to append to url
  // returns results as this.state.camperArr
  callApi(str) {
    var req = "https://fcctop100.herokuapp.com/api/fccusers/top/" + str;
    this.serverRequest = $.get(req, function(result) {
      // add an id property to each element
      result.map(function(elem, idx) {
        elem["id"] = idx + 1;
      });
      this.setState({
        search: str,
        camperArr: result,
        asc: true
      });
    }.bind(this));
  }

  // toggles the column sorting asc/desc if click on current column
  // else calls the api with the given string
  toggleColumnSort(str) {
    if (this.state.search === str) {
      this.setState({
        camperArr: this.state.camperArr.reverse(),
        asc: this.state.asc ? false : true
      });
    } else {
      this.callApi(str);
    }
  }

  render() {
    // set up class names based on booleans to set active column / sorting icon
    var recentClass = classNames({
      'recent': true,
      'active': this.state.search === 'recent'
    });
    var alltimeClass = classNames({
      'alltime': true,
      'active': this.state.search === 'alltime'
    });
    var glyphiconClass = classNames({
      'glyphicon': true,
      'glyphicon-triangle-bottom': this.state.asc,
      'glyphicon-triangle-top': !this.state.asc
    });
    return (
      <div className="container">
        <div className="row">
          <div className="col-xs-12">
            <table className="table table-striped table-hover">
              <caption><h2><a href="https://www.freecodecamp.com" target="_blank">FreeCodeCamp</a> Leaderboard</h2></caption>
              <thead>
                <tr>
                  <th>Rank</th>
                  <th>Name</th>
                  <th className="points"><span className={recentClass} onClick={this.toggleColumnSort.bind(this, "recent")}>Past 30 Days<span className={glyphiconClass}></span></span></th>
                  <th className="points"><span className={alltimeClass} onClick={this.toggleColumnSort.bind(this, "alltime")}>All Time<span className={glyphiconClass}></span></span></th>
                </tr>
              </thead>
              <CamperList list={this.state.camperArr} />
            </table>
          </div>
        </div>
      </div>
    )
  }
}

// the list of campers
class CamperList extends React.Component {
  render() {
    var list = this.props.list;
    var items = list.map(function(elem, idx) {
      return <Camper key={elem["id"]} id={elem["id"]} name={elem["username"]} image={elem["img"]} alltime={elem["alltime"]} recent={elem["recent"]} link={"https://www.freecodecamp.com/" + elem["username"]} />
    });
    return (
        <ReactCSSTransitionGroup component="tbody" transitionName="fade" transitionEnterTimeout={500} transitionLeaveTimeout={300}>
          {items}
        </ReactCSSTransitionGroup>
    )
  }
}

// single camper
class Camper extends React.Component {
  render() {
    return (
      <tr>
        <td>{this.props.id}</td>
        <td><a href={this.props.link} target="_blank"><img src={this.props.image}></img></a><a href={this.props.link} target="_blank">{this.props.name}</a></td>
        <td className="points">{this.props.recent}</td>
        <td className="points">{this.props.alltime}</td>
      </tr>
    )
  }
}

ReactDOM.render(<Application />, document.getElementById('camper-app'));

              
            
!
999px

Console