Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

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.

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="tabs"></div>
              
            
!

CSS

              
                *{ box-sizing: border-box }
body{ padding: 60px; background: rgba(silver, .8); }

.clearfix:after{
  display: table;
  content: '';
  clear: both;
}

button{
  border: none;
  padding: 10px;
  font-size: 20px;
  color: white;
  background: darken(#00ADFF, 15%);
  opacity: .6;
  display: block;
  float: left;
  width: 25%;
  border: solid 1px rgba(black,.1);
  &:hover, &.active{
    background: #FFF470;
    color: black;
    border: solid 1px darken(#FFF470, 25%);
    opacity: 1;
  }
  &:first-of-type{
    border-top-left-radius: 6px;
  }
  &:last-of-type{
    border-top-right-radius: 6px;
  }
  &:focus{
    outline: 0;
  }
}
.tabbed_section{
  box-shadow: 0 3px 5px 0 rgba(black, .3);
  background: white;
  border-radius: 6px;
}

h2{
  text-align: center;
  font-size: 50px;
  margin-top: 0;
}

.tab_content{
  padding: 40px;
  background: white;
  min-height: 250px;
  border-radius: 0 0 10px 10px;
  border-top: solid 1px rgba(#000, .5);
}

              
            
!

JS

              
                var TAB_DATA = {
  tab1: { content: "tab1" }, 
  tab2: { content: "tab2" },
  tab3: { content: "tab3" },
  tab4: { content: "tab4!!" }
};

var Tabs = React.createClass({
  getInitialState: function() {
    return { 
      tab_data: TAB_DATA,
      currentTab: 'tab1'
    };
  },
  updateTab: function(key){
    this.setState({ currentTab: key }); 
  },
  renderTabName: function(key){
    return <TabName 
             key={key} 
             index={key} 
             tab_details={this.state.tab_data[key]} 
             updateTab={this.updateTab} 
             currentTab={this.state.currentTab} 
            />
  },
  renderTabBody: function(key){
    return <TabBody 
             key={key} 
             index={key} 
             tab_details={this.state.tab_data[key]} 
             updateTab={this.updateTab} 
             currentTab={this.state.currentTab} 
            />
  },
  render: function() {
    return (
      <div className="tabbed_section">
        <div className="clearfix">
          { Object.keys(this.state.tab_data).map(this.renderTabName) }
        </div>
        <div>
          { Object.keys(this.state.tab_data).map(this.renderTabBody) }
        </div>
      </div>
    );
  }
});

var TabName = React.createClass({
  handleClick: function(){
    var key = this.props.index;
    var updateTab = this.props.updateTab;
    updateTab(key);
  },
  render: function(){
    var index = this.props.index;
    var currentTab = this.props.currentTab;
    var klass = currentTab.indexOf(index) == 0 ? 'active' : '';
    return (
      <button className={klass} onClick={this.handleClick}>{index}</button>
    );
  }
});

var TabBody = React.createClass({
  render: function(){
    var content = this.props.tab_details.content
    var current = this.props.currentTab
    var index = this.props.index
    var content_display = current.indexOf(index)
    var display = content_display == 0 ? <h2 className="tab_content">{content}</h2> : <div />;
    return display;
  }
});

ReactDOM.render(<Tabs/>, document.getElementById('tabs'));



              
            
!
999px

Console