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

              
                <link href="https://fonts.googleapis.com/css?family=Fredoka+One" rel="stylesheet">

<div id="table" class="container"></div>
              
            
!

CSS

              
                /*change in JS also*/
$tdHeight: 50px

@media(max-width: 520px) 
  td
    font-size: 16px !important
  
  th
    font-size: 12px !important
  
  #userName
    width: 130px !important
  
  #title
    font-size: 18px !important
  
tr
  height: $tdHeight
  
.rank
  width: 60px !important
  
.table
  background-color: lightgrey
  max-width: 500px
  font-family: 'Fredoka One', cursive

th
  font-size: 14px

table
  margin: 0px auto !important
  
td
  color: black
  position: relative
  font-size: 22px
  min-width: 2em !important
  
td a /*exclude the header bar*/
  color: black
  text-shadow: 2px 2px 1px white
  position: relative  
  line-height: $tdHeight
  padding-left: 5px
  min-width: 6em !important

.data
  margin-left: 5px
  line-height: 40px
  overflow: hidden
  height: 100%
  top: 0
  bottom: 0
  left: 0
  right: 0
  
#userName
  width: 250px !important

caption
  text-align: center
  font-size: 18px

.tdOverlay
  position: absolute
  background: rgba(211, 211, 211, 0.5) 
  height: 100%
  width: 100%
  libe-height: 20px
  top: 0
  bottom: 0
  left: 0
  right: 0
  
.panel
  border: none
  
.panel:hover
  background: Transparent
  
.panel:hover a
  color: orange !important
  text-shadow: 3px 3px 3px green

  
#title
  background-color: lightgrey
  font-size: 28px
  
body
  background: linear-gradient(270deg, #018e06, #014f8e)
  background-size: 400% 400%
  animation: AnimationName 20s ease infinite
  @keyframes AnimationName  
    0%
      background-position: 0% 50%
    50%
      background-position: 100% 50%
    100%
      background-position: 0% 50%

              
            
!

JS

              
                //The two API calls store the data in these variables.
//This is so it doesn't have to do a new call each time
//the list is sorted.
var last30days = {};
var top100 = {};
var tdHeight = '50px'; //change in CSS also - image & tr height

//make a tag for each user with slots for the
//info from the stored objects
var User = React.createClass({
  render: function() {
    console.log(tdHeight);
    return (
      <tr>
        <td className="rank"><div className="data">{this.props.rank}</div></td>
        <td id="userName" style={
            {backgroundImage: 'url(' + this.props.image + ')',
              backgroundSize: tdHeight, 
                backgroundRepeat: 'no-repeat'}
                                }>
          <div className="tdOverlay panel panel-default">
            <a href={"https://freecodecamp.com/" + this.props.name} target="_blank">
              {this.props.name}
            </a>
          </div>
        </td>
        <td><div className="data">{this.props.last30}</div></td>
        <td><div className="data">{this.props.alltime}</div></td>
      </tr>      
    );
  }
});

//Loop through and add an entry for each user.
//This will be the main readerboard.
//The byTop30 state toggles which set of data
//to display.
var List = React.createClass({
  getInitialState: function() {
    return {byTop100: false};
  },
  
  sortByLast30: function() {
    this.setState({byTop100: false});
  },
  
  sortByAllTime: function() {
    this.setState({byTop100: true});
  },
  
  //Only build table after data is received
  componentWillMount: function() {
    //load data and build an array for each
    $.ajax({   //get the best from the last 30 days
      type: "GET",
      url: "https://fcctop100.herokuapp.com/api/fccusers/top/recent",
      contentType: "application/json; charset=utf-8",
      async: false,
      dataType: "json",
      success: function(data) {
        last30days = $.extend(true, [], data); //deep copy received data from {} to []
      },
      error: function() {
        console.log("couldn't get data");
      }
    });
    
    $.ajax({    //get the all-time top 100
      type: "GET",
      url: "https://fcctop100.herokuapp.com/api/fccusers/top/alltime",
      contentType: "application/json; charset=utf-8",
      async: false,
      dataType: "json",
      success: function(data) {
        top100 = $.extend(true, [], data); //deep copy received data from {} to []
      },
      error: function() {
        console.log("couldn't get data");
      }
    });
  },
  
  render: function() {
    //sortBy is a reference to either top100 or last30days arrays
    //theList is the user list
    var theList = [], sortBy = []; 
    if(this.state.byTop100 === true) sortBy = top100;
    else sortBy = last30days;
    //add entry for each user
    for(var i = 0, len = sortBy.length; i < len; ++i) {
      theList.push(<User rank={i+1} 
                         image={sortBy[i]["img"]}
                         name={sortBy[i]["username"]} 
                         last30={sortBy[i]["recent"]} 
                         alltime={sortBy[i]["alltime"]} />
                  );
    }
    //Couldn't find a simpler way to do this. Open & close JSX tags have to go together.
    return (<div>    
              <table className="table table-hover table-condensed">
                <caption id="title">FCCers by brownie points</caption>
                <thead>
                  <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th><a href='#' onClick={this.sortByLast30}>Last 30 Days</a></th>
                    <th><a href='#' onClick={this.sortByAllTime}>All-time</a></th>
                  </tr>
                </thead>
                <tbody>
                  {theList}
                </tbody>
              </table>
            </div>
           );
  }
});

ReactDOM.render(<List />, document.getElementById("table"));
              
            
!
999px

Console