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

CSS

              
                * {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Georgia", serif;
  color: #aaa;
}


// variables
$col-primary-text: #4c4c4c;
$col-link: #0088ff;
$col-border-separator: #cccccc;
$col-icon-grey: #929292;
$font-family-default: "Courier", sans-serif;
body {
  font-family: $font-family-default;
  color: $col-primary-text;
}

.tab-left-control {
    max-width: 220px;
    min-height: 100vh; // default 480px
    height: calc(100vh - 68px);
    background: white;
    box-sizing: border-box;
    border-right: 1px solid $col-border-separator;
    overflow-y: scroll;
}

button.tab-control {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  font-size: 16px;
  text-align: left;
  font-family: $font-family-default;
}

.t-l-c__main {
    letter-spacing: 1px;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding-top: 0.8rem;
    padding-bottom: 0.8rem;
    padding-left: 1rem;
    box-sizing: border-box;
    cursor: pointer;

    &.selected {
        background: $col-link;
        color: white;
    }
}

.t-l-c__child {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    padding-left: 1rem;
    background: none;
    color: $col-link;
    cursor: pointer;

    &.selected {
        background: $col-link;
        color: white;
    }
}

.tab-left-main {
    position: relative;
}



.t-l__content-h2 {
    padding-bottom: 5px;
    border-bottom: 1px solid $col-icon-grey;
}

.t-l__content-li {
    line-height: 1.6;
    margin: 1rem;
}

.tab-content {
  width: 100%;
  height: 100vh;
  background: orange;
  opacity: 0;
  visibility: hidden;  
  right: 0;
  position: absolute;
  top: 0;
  padding: 1rem;
  box-sizing: border-box;
  
  &.selected{
    opacity: 1;
    visibility: visible;    
  }
}

.tab-content-wrapper {
  width: calc(100% - 220px);
  height: 100%;
  top: 0;
  position: absolute;
  right: 0;
}
              
            
!

JS

              
                const { Component, createContext, Fragment } = React;
const { render } = ReactDOM;
console.clear();

/*************************************************/
// TabContent
/*************************************************/
// this passes down this.props.activeId to the children
class TabContentWrapper extends Component {
  render() {
    const content = React.Children.map(this.props.children, child =>
      React.cloneElement(child, { activeId: this.props.activeId })
    );
    return <div className="tab-content-wrapper">{content}</div>;
  }
}
// this handles display of active Tab Content by comparing it's own this.props.id vs this.props.activeId
const TabContent = ({ id, activeId, children }) => {
  const activeClass = id === activeId ? "selected" : "";
  return <div className={`tab-content ${activeClass}`}>{children}</div>;
};

const Joker = ({ id, activeId }) => (
  <TabContent id={id} activeId={activeId}>
    <h2>Joker</h2>
  </TabContent>
);

const Monkey = ({ id, activeId }) => (
  <TabContent id={id} activeId={activeId}>
    <h2>Monkey</h2>
  </TabContent>
);

const Mango = ({ id, activeId }) => (
  <TabContent id={id} activeId={activeId}>
    <h2>Mango</h2>
  </TabContent>
);

const Something = ({ id, activeId }) => (
  <TabContent id={id} activeId={activeId}>
    <h1>Something</h1>
  </TabContent>
);

/*************************************************/
// navData ~ with nested child nav content
/*************************************************/
const navData = [
  {
    id: "0.0",
    title: "Funny",
    defaultActive: "0.1",
    children: [
      {
        id: "0.1",
        title: "Joker"
      },
      {
        id: "0.2",
        title: "Monkey"
      }
    ]
  },
  {
    id: "1.0",
    title: "Food",
    defaultActive: "1.1",
    children: [
      {
        id: "1.1",
        title: "Mango"
      }
    ]
  },
  {
    id: "2.0",
    title: "Something Big",
    defaultActive: "2.0",
    children: []
  }
];

/*************************************************/
// TabNav Components
/*************************************************/
const TabControlUnitMain = ({ mainItem, updateActive, children, active }) => {
  if (mainItem.defaultActive === active && !children) {
    if (!children) {
      return (
        <button className="t-l-c__main tab-control selected">
          {mainItem.title}
        </button>
      );
    }
  } else {
    return (
      <div className="t-l-c__main__wrapper">
        <button
          className="t-l-c__main tab-control"
          onClick={() => {
            updateActive(mainItem.defaultActive);
          }}
        >
          {mainItem.title}
        </button>
        {children}
      </div>
    );
  }
};
const TabControlUnitChild = ({ childItem, updateActive, active }) => {
  const selectedClass = active === childItem.id ? "selected" : "";
  return (
    <button
      className={`t-l-c__child ${selectedClass} tab-control`}
      onClick={() => {
        updateActive(childItem.id);
      }}
    >
      {childItem.title}
    </button>
  );
};
class MyTabNav extends Component {
  render() {
    const { updateActive, navData, active } = this.props;
    return (
      <div className="tab-left-control">
        {navData.map(mainItem => {
          if (mainItem.children.length === 0) {
            return (
              <TabControlUnitMain
                active={active}
                mainItem={mainItem}
                key={mainItem.id}
                updateActive={updateActive}
              />
            );
          } else {
            return (
              <TabControlUnitMain
                mainItem={mainItem}
                key={mainItem.id}
                updateActive={updateActive}
              >
                {mainItem.children.map(childItem => (
                  <TabControlUnitChild
                    key={childItem.id}
                    childItem={childItem}
                    updateActive={updateActive}
                    active={active}
                  />
                ))}
              </TabControlUnitMain>
            );
          }
        })}
      </div>
    );
  }
}

/*************************************************/
// Main Tab Components
/*************************************************/
const TabContext = createContext();
class Tab extends Component {
  static Consumer = TabContext.Consumer;
  static defaultProps = {
    initialActiveId: "0.1"
  };
  initialState = {
    activeId: this.props.initialActiveId
  };
  state = this.initialState;
  updateActiveId = id => {
    this.setState({
      activeId: id
    });
  };
  render() {
    return (
      <div className="tab">
        <TabContext.Provider
          value={{
            activeId: this.state.activeId,
            updateActiveId: this.updateActiveId
          }}
        >
          {this.props.children}
        </TabContext.Provider>
      </div>
    );
  }
}

const App = () => (
  <div className="app">
    <Tab>
      <TabContext.Consumer>
        {({ activeId, updateActiveId }) => (
          <Fragment>
            <MyTabNav
              updateActive={updateActiveId}
              navData={navData}
              active={activeId}
            />
            <TabContentWrapper activeId={activeId}>
              <Joker id="0.1" />
              <Monkey id="0.2" />
              <Mango id="1.1" />
              <Something id="2.0" />
            </TabContentWrapper>
          </Fragment>
        )}
      </TabContext.Consumer>
    </Tab>
  </div>
);

render(<App />, document.getElementById("root"));

              
            
!
999px

Console