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

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,600);

html {
  font-size: 16px;
}
body {
  font-family: "Open Sans", sans-serif;
  line-height: 1;
}

.Root {
  height: 100vh;
}

.Tabs {
  height: 100%;
  display: flex;
}

.TabList {
  width: 10rem;
  background: #263238;
}

.TabPanel {
  flex: 1;
  display: none;
  padding: 1.5rem 2rem;
}
.TabPanel.is-active {
  display: block;
}

.Button {
  display: inline-block;
  width: 100%;
  padding: 1rem 2rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: bold;
  color: #fff;
}
.Button:focus,
.Button:hover {
  outline: 0;
  background: #37474F;
}
.Tab.is-active .Button {
  background: #0091EA;
}
              
            
!

JS

              
                const { Component } = React
const { render } = ReactDOM

const Root = () => (
  <div className="Root">
    <Tabs selected={ 1 }>
      <TabList>
        <Tab>
          <Button>Foo</Button>
        </Tab>
        <Tab>
          <Button>Bar</Button>
        </Tab>
        <Tab>
          <Button>Baz</Button>
        </Tab>
      </TabList>

      <TabPanel>
        Related to foo
      </TabPanel>

      <TabPanel>
        Related to bar
      </TabPanel>

      <TabPanel>
        Related to baz
      </TabPanel>
    </Tabs>
  </div>
)

/*
 * Tabs is the stateful component.
 * You can pass an index in the `selected` prop
 * to specify which tab is active by default.
 *
 * This component handles the entire tabs system.
 * It transforms its own children (if they are Tab or TabPanel) to pass the
 * required props in order to run automatically the system.
 */

class Tabs extends Component {
  state = { selected: this.props.selected };

  setSelected(selected) {
    if (selected !== this.state.selected) {
      this.setState({ selected })
    }
  }

  handleClick(tab) {
    return () => this.setSelected(tab)
  }

  renderTabList(child) {
    let tab = 0

    return React.cloneElement(child, {
      children: React.Children.map(child.props.children, (childTab) => {
        if (childTab.type.name === "Tab") {
          const _isActive = (tab === this.state.selected)
          const _onClick = this.handleClick(tab)

          tab++

          return React.cloneElement(childTab, { _isActive, _onClick })
        }

        return childTab
      }),
    })
  }

  renderChildren(children) {
    let panel = 0

    return React.Children.map(children, (child) => {
      if (child.type.name === "TabList") {
        return this.renderTabList(child)
      }

      if (child.type.name === "TabPanel") {
        const _isActive = (panel === this.state.selected)

        panel++

        return React.cloneElement(child, { _isActive })
      }

      return child
    })
  }

  render() {
    return (
      <div className="Tabs">
        { this.renderChildren(this.props.children) }
      </div>
    )
  }
}

const TabList = ({ children }) => (
  <ul className="TabList">
    { children }
  </ul>
)

const Tab = ({
  _onClick,
  _isActive,
  children,
}) => (
  <li
    className={ `Tab  ${ _isActive ? "is-active" : "" }` }
    onClick={ _onClick }>
    { children }
  </li>
)

const TabPanel = ({
  _isActive,
  children,
}) => (
  <div className={ `TabPanel  ${ _isActive ? "is-active" : "" }` }>
    { children }
  </div>
)

/* --- */

const Button = ({ children }) => (
  <button className="Button">
    { children }
  </button>
)

render(<Root />, document.querySelector("#root"))
              
            
!
999px

Console