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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

CSS

              
                 @import url('https://fonts.googleapis.com/css?family=Ubuntu');

html {
  background: #fff;
  font-family: sans-serif;
}
h1 {
  color: white;
}

.panel-container {
  display: flex;
  min-height: 300px;
}

.panel {
  background: white;
  margin: 0;
  border: 1px solid #e5e5e5;
  padding: 15px;
}
.panel:first-child {

}

.resizer {
  width: 5px;
  position: relative;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  -webkit-user-select: none;  /* Chrome all / Safari all */
  -moz-user-select: none;     /* Firefox all */
  -ms-user-select: none;      /* IE 10+ */
  user-select: none;          /* Likely future */ 
  
}
.resizer:hover{
    background: #e4e4e4;
}

.resizer::after,
.resizer::before {
  content: "";
  position: absolute;
  top: 50%;
  transform: translateY(-100%);
  right: 0;
  display: inline-block;
  height: 20px;
  margin: 0;
}
.resizer::before {
  left: 0;
}
              
            
!

JS

              
                class Application extends React.Component {
  constructor () {
    super()
    this.state = {
      
    }
  }
  
  render() {
    return (
      <div>
        <h1>ReactJS Resizable Panels</h1>
        <ResizablePanels>
          <div>
            This is the first panel. It will use the rest of the available space.
          </div>
          <div>
            This is the second panel. Starts with 300px.
          </div>
          <div>
            This is the third panel. Starts with 300px.
          </div>
        </ResizablePanels>
      </div>
    )
  }
}

class ResizablePanels extends React.Component {
  eventHandler = null

  constructor () {
    super()
    
    this.state = {
      isDragging: false,
      panels: [300, 300, 300]
    }
  }

  componentDidMount () {
    ReactDOM.findDOMNode(this).addEventListener('mousemove', this.resizePanel)
    ReactDOM.findDOMNode(this).addEventListener('mouseup', this.stopResize)
    ReactDOM.findDOMNode(this).addEventListener('mouseleave', this.stopResize)
  }
  
  startResize = (event, index) => {
    this.setState({
      isDragging: true,
      currentPanel: index,
      initialPos: event.clientX
    })
  }
  
  stopResize = () => {
    if (this.state.isDragging) {
      console.log(this.state)
      this.setState(({panels, currentPanel, delta}) => ({
        isDragging: false,
        panels: {
          ...panels,
          [currentPanel]: (panels[currentPanel] || 0) - delta,
          [currentPanel - 1]: (panels[currentPanel - 1] || 0) + delta
        },
        delta: 0,
        currentPanel: null
      }))
    }
  }
  
  resizePanel = (event) => {
    if (this.state.isDragging) {
      const delta = event.clientX - this.state.initialPos
      this.setState({
        delta: delta
      })
    }
  }
  
  render() {
    const rest = this.props.children.slice(1)
    return (
      <div className="panel-container" onMouseUp={() => this.stopResize()}>
        <div className="panel" style={{width: `calc(100% - ${this.state.panels[1]}px - ${this.state.panels[2]}px)`}}>
          {this.props.children[0]}
        </div>
        {[].concat(...rest.map((child, i) => {
          return [
            <div onMouseDown={(e) => this.startResize(e, i + 1)}
              key={"resizer_" + i}
              style={this.state.currentPanel === i+1 ? {left: this.state.delta} : {}}
              className="resizer"></div>,
            <div key={"panel_" + i} className="panel" style={{width: this.state.panels[i + 1]}}>
              {child}
            </div>
          ]
        }))}
      </div>
    )
  }
}

/*
 * Render the above component into the div#app
 */
ReactDOM.render(<Application />, document.getElementById('app'));
              
            
!
999px

Console