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

              
                #react-app
              
            
!

CSS

              
                // ## MIXINS ##
=transform($transforms)
  -moz-transform:    $transforms
  -o-transform:      $transforms
  -ms-transform:     $transforms
  -webkit-transform: $transforms
  transform:         $transforms

=border-radius($radius)
  -webkit-border-radius: $radius
  -moz-border-radius:    $radius
  -ms-border-radius:     $radius
  border-radius:         $radius
  
=appearance($appearance)
  -webkit-appearance: $appearance
  -moz-appearance:    $appearance
  -ms-appearance:     $appearance
  appearance:         $appearance
  
=font-face($name, $path)
  @font-face
    font-family: $name
    src: url($path + $name + ".svg") format("svg"), url($path + $name + ".woff") format("woff"), url($path + $name + ".ttf") format("truetype")
  
// ## ANIMATIONS ##
@keyframes fade-in
  0%
    opacity: 0
    z-index: -100
  100%
    opacity: 1
    z-index: -100

@keyframes scale-bounce
  0%
    +transform(scale(1))
  10%
    +transform(scale(1.3))
  40%
    +transform(scale(1.4))
  50%
    +transform(scale(1.2))
  60%
    +transform(scale(1.4))
  70%
    +transform(scale(1.3))
  80%
    +transform(scale(1.4))
  90%
    +transform(scale(1.35))
  100%
    +transform(scale(1.4))
  
// ## FONTS ##
+font-face("OperatorMono-Bold", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/161040/")
+font-face("OperatorMono-Medium", "https://s3-us-west-2.amazonaws.com/s.cdpn.io/161040/")

// ## VARS ##
$white: white
$yellow: #FFF32B
$blue: #3BB0FF
$trans-blue: rgba(50, 137, 197, .95)
$red: #FF014E
$green: #66FF00
$slate: #1C2025
$normal-stack: "OperatorMono-Medium", "Lucida Console", Monaco, monospace
$bold-stack: "OperatorMono-Bold", "Lucida Console", Monaco, monospace

// ## FIXTURES ##
body
  background: $slate
  text-align: center
  font-family: $normal-stack
  color: $blue
  
h1, h2, h3, h4, h5, h6
  font-family: $bold-stack
  font-size: 3em
  
ol, ul
  list-style: none
  padding: 0
  margin-top: 4em
  
li
  text-align: center
  display: inline-block
  width: 100%
  
input
  margin: 0 .5em 1em
  font-family: $normal-stack
  background: transparent
  font-size: 1.5em
  color: $blue
  outline: none
  border: none
  text-align: center
  border-bottom: 4px solid $white
  &:focus
    outline: 0

select
  border: none !important
  width: 6em
  height: 1.5em
  padding-left: .3em
  outline: solid .2em $white
  
button
  border: none !important
  height: 1.5em
  outline: solid .2em $white
  &:disabled
    cursor: none
  
fieldset
  border: none

// ## SPECIFICS ##
.flex-container
  display: flex
  flex-wrap: no-wrap
  
.flex-item
  justify-content: space-between
  
.heading
  display: inline-block
  text-transform: uppercase
  border-bottom: 5px solid $white
  
.controls
  button, select
    margin: 0 .5em .25em
    font-family: $normal-stack
    background: transparent
    font-size: 1.5em
    color: $blue
    border: 4px solid $white
    transition: .2s
    &:hover
      color: $white
      cursor: pointer
    &:disabled
      cursor: default
      pointer: none
      color: $blue
    
  .checkbox
    font-size: 1.6em
    label
      border: 4px solid $white
      margin: 0 .3em
    .box
      cursor: pointer
      padding: 0 .67em
      &.checked
        padding: 0
      .check
        color: $blue
        padding: 0 .15em
        transition: .2s
      &:hover .check
        color: $white

    .toggle-label
      border-left: none
      border-right: none
      border-top: none
      padding: 0.15em 0.05em 0.012em

.pretty-array
  padding-top: 20px
  padding-bottom: 2.5em
  font-size: 1.4em
  .bracket
    font-size: 1.6em
    color: $white
    padding: 0 .2em
  .value-and-comma
    .comma
      color: $white
    .value
      border-bottom: 4px solid rgba(255,255,255, 0)
      border-top: 4px solid rgba(255,255,255, 0)
      transition: .2s
      &.root
        border-top: 4px solid $white
      &.active
        border-bottom: 4px solid $white

.tree
  animation: fade-in 1s ease-in

.line
  border-bottom: 6px solid $white
  width: 55%
  position: relative
  z-index: -100
  &.left
    left: 45%
    
.node-label
  font-size: 1.2em
  background: $slate
  border: .3em solid $white
  +border-radius(3em)
  padding: .53em .6em
  text-align: center
  position: relative
  cursor: pointer
  &:hover
    .close-btn, .rotate-btn
      visibility: visible
      opacity: 1

.rotate-btn, .close-btn
  position: absolute
  visibility: hidden
  opacity: 0
  top: -.75em
  font-size: .9em
  background: $white
  padding: .15em .35em
  border-radius: 16.66666em
  transition: .2s
  &:hover
    cursor: pointer
    animation: scale-bounce .3s ease-out
    +transform(scale(1.4))
  
.rotate-btn
  left: -.7em
  color: $blue

.close-btn
  right: -.7em
  color: $red
              
            
!

JS

              
                /* Imported Libs & Global vars
** ************************************** */
const React = React
const ReactDOM = ReactDOM
const { connect, Provider } = ReactRedux
const thunkMiddleware = ReduxThunk.default
const { compose, createStore, applyMiddleware } = Redux
const domContainerNode = document.getElementById('react-app')

const minValue = 1
const maxValue = 99

/* Helper Functions
** ************************************** */
const always = x => y => x

const toUpper = str => str.toUpperCase()

const slice = (i, j, coll) => coll.slice(i, j)

const capitalize = str =>
  `${toUpper(str.charAt(0))}${slice(1, Infinity, str)}`

const getNestedValue = (keyPath, obj = {}) =>
  keyPath
    .trim()
    .split('.').reduce((acc, curr) =>
      acc[curr], obj)

const zeroPadDigit = num =>
  num < 10
    ? num > -10 && num < 0
      ? String('-0' + num) // negative digits
      : String('0' + num)  // positive digits
    : String(num)

const getIntRange = (start = 0, count = 99) =>
  Array(count + 1)
    .fill()
    .map((_, i) => i + start)

const getRandomInt = (min = minValue, max = maxValue) =>
  Math.floor(Math.random() * (max - min + 1)) + min

const getRandomArray = (length = 10, min, max) =>
  Array(length)
    .fill()
    .map(getRandomInt.bind(null, min, max))

const mapKeysToObject = (keys, func, obj = {}) =>
  keys.reduce((acc, curr) => {
    acc[curr] = func(curr); return acc }, obj)

/* Data Structures
** ************************************** */
const BinarySearchTreeNode = value =>
  ({
    value,
    left: null,
    right: null,
    parent: null
  })

const BinarySearchTree = (root, autobalancing = false) =>
  ({
    root,
    autobalancing,
    find: function (value) {
      let found = false
      let current = this.root

      while (!found && current) {
        if (value < current.value)
          current = current.left
        else if (value > current.value)
          current = current.right
        else
          found = true
      }

      return found && current
    },
    traverseInOrder: function (callback, startNode = this.root) {
      const inOrder = node => {
        if (node) {
          if (node.left)                    // traverse the left subtree
            inOrder(node.left)

          callback.call(this, node)         // process the callback on the current node
          
          if (node.right)                   // traverse the right subtree
            inOrder(node.right)
        }
      }
      
      inOrder(startNode)
    },
    traverseByDepth: function (callback, startNode = this.root) {
      const byDepth = (...nodes) => {
        if (nodes.length) {
          callback.call(this, nodes)
          const nextNodes = nodes.reduce((nextLevel, node) => {
            if (node.left)
              nextLevel.push(node.left)
            if (node.right)
              nextLevel.push(node.right)
            return nextLevel
          }, [])
          byDepth(...nextNodes)
        }
      }

      byDepth(startNode)
    },
    getValues: function (startNode = this.root) {
      const values = []
      this.traverseInOrder(startNode => values.push(node.value))
      return values
    },
    getMinNode: function (node = this.root) {
      return node.left ? this.getMinNode(node.left) : node
    },
    getMaxNode: function (node = this.root) {
      return node.right ? this.getMaxNode(node.right) : node
    },
    resetParents: function () {
      this.traverseInOrder(node => {
        if (node === this.root)
          node.parent = null
        if (node.left)
          node.left.parent = node
        if (node.right)
          node.right.parent = node
      })
    },
    getNodeSide: function ({parent, value}) {
      if (parent)
        return value < parent.value ? 'left' : 'right'
      return 'root'
    },
    getHeight: function (startNode = this.root) {
      let height = 0
      if (!startNode)
        return height
      this.traverseByDepth(nodes => height++, startNode)
      return height
    },
    getBalanceFactor: function (startNode = this.root) {
      const leftSubtreeHeight = startNode.left
        ? this.getHeight(startNode.left) : 0
      const rightSubtreeHeight = startNode.right
        ? this.getHeight(startNode.right) : 0
      
      return rightSubtreeHeight - leftSubtreeHeight     // a node with a balance factor 1, 0, or -1 is considered balanced
    },
    rotateLeft: function (parentNode) {
      const pivotNode = parentNode.right                // Let ParentNode be PivotNode's right child
      parentNode.right = pivotNode.left                 // Set PivotNode's right child to be ParentNode's left child
      
      if (parentNode.right && parentNode.right.parent)  // Set ParentNode's left-child's parent to PivotNode
        parentNode.right.parent = parentNode
      
      pivotNode.left = parentNode                       // Set ParentNode's left child to be PivotNode
      
      if (parentNode.parent)                            // Set PivotNode's parent to ParentNode
        parentNode.parent[this.getNodeSide(parentNode)] = pivotNode
      else
        this.root = pivotNode
      
      this.resetParents()                               // Reset parent references
    },
    rotateRight: function (parentNode) {
      const pivotNode = parentNode.left                 // Let PivotNode be ParentNode's left child.
      parentNode.left = pivotNode.right                 // Set ParentNode's left child to be PivotNode's right child
      
      if (parentNode.left && parentNode.left.parent)    // Set PivotNode's right-child's parent to ParentNode
        parentNode.left.parent = parentNode

      pivotNode.right = parentNode                      // Set PivotNode's right child to be ParentNode
      
      if (parentNode.parent)                            // Set PivotNode's parent to ParentNode
        parentNode.parent[this.getNodeSide(parentNode)] = pivotNode
      else
        this.root = pivotNode
      
      this.resetParents()                               // Reset parent references
    },
    rotate: function (direction, node) {
      if (direction === 'left')
        this.rotateLeft(node)
      if (direction === 'right')
        this.rotateRight(node)
    },
    balance: function (node) {
      if (node) {
        const parentBalanceFactor = this.getBalanceFactor(node)
        
        if (parentBalanceFactor < -1) {                 // parent node is heavy on the left
          if (this.getBalanceFactor(node.left) > 0)     // pivot node is heavy on the right
            this.rotateLeft(node.left)                  // left-right rotation
          this.rotateRight(node)                        // left-left rotation
        }
        
        if (parentBalanceFactor > 1) {                  // parent node is heavy on the right
          if (this.getBalanceFactor(node.right) < 0)    // pivot node is heavy on the left
            this.rotateRight(node.right)                // right-left rotation
          this.rotateLeft(node)                         // right-right rotation 
        }
        
        return this.balance(node.parent)
      }
    },
    add: function (value) {
      const node = BinarySearchTreeNode(value)
      let current = this.root

      if (!current)                                     // set root if none exists
        this.root = node
      else
        while (value !== current.value) {               // traverse the tree
          const side = value < current.value ? 'left' : 'right'
          if (!current[side]) {
            node.parent = current
            current[side] = node                        // add the node
          }
          current = current[side]
        }

      if (node.parent && this.autobalancing)
        this.balance(node.parent)
    },
    remove: function (value) {
      const node = this.find(value)             // Search for node to remove
      if (!node) return                         // Exit if no node is found
      
      const side = this.getNodeSide(node)
      const leftChild = node.left
      const rightChild = node.right
      const numChildren = [leftChild, rightChild].reduce((acc, curr) =>
        curr ? ++acc : acc, 0)

      switch (numChildren) {                    // Handle one of 3 cases
        case 0 : node.parent                    // 1. Node has zero children
          ? node.parent[side] = null
          : this.root = null
          break
        case 1 : node.parent                    // 2. Node has one child
          ? node.parent[side] = leftChild || rightChild
          : this.root = leftChild || rightChild
          break
        case 2 :                                // 3. Node has two children
          const minNodeValue = this.getMinNode(rightChild).value
          this.remove(minNodeValue)
          node.value = minNodeValue
          break
      }
      
      this.resetParents()                       // Reset parent references
      if (node.parent && this.autobalancing)
        this.balance(node.parent)
    }
  })

/* Action Creators, Initial State & Reducers
** ************************************** */
const treeActionCreators = {
  add: dispatch =>
    payload =>
      dispatch({ type: 'ADD_NODE', payload }),
  remove: dispatch =>
    payload =>
      dispatch({ type: 'REMOVE_NODE', payload }),
  rotate: dispatch =>
    payload =>
      dispatch({ type: 'ROTATE_NODE', payload })
}

const metaActionCreators = {
  changeValue: dispatch =>
    payload =>
      dispatch({ type: 'CHANGE_VALUE', payload }),
  changeActive: dispatch =>
    payload =>
      dispatch({ type: 'CHANGE_ACTIVE', payload }),
  toggleBalanced: dispatch =>
    payload =>
      dispatch({ type: 'TOGGLE_BALANCED', payload })
}

const actionCreators = {
  ...treeActionCreators,
  ...metaActionCreators
}

const seedValues = compose(getRandomArray, getRandomInt)(3, 6)                        // make a small set of random seed values

const tree = compose(BinarySearchTree, BinarySearchTreeNode)(seedValues[0])           // create initial trees; use first seed value as root
const balancedTree = BinarySearchTree(BinarySearchTreeNode(seedValues[0]), true)

for (let value of seedValues.slice(1)) {                                              // seed the tree, with remaining values
  tree.add(value)
  balancedTree.add(value)
}

const initialState = {
  tree,
  balancedTree,
  meta: {
    balanced: true,
    currValue: null,
    activeValue: null,
    containedValues: mapKeysToObject(seedValues, always(true)),
    availableValues: getIntRange(minValue, maxValue - minValue)
  }
}

const rootReducer = (state = initialState, {type, payload}) => {
  const newState = Object.assign({}, state)
  const treeKey = newState.meta.balanced ? 'balancedTree' : 'tree'
  
  switch (type) {
    case 'ADD_NODE':
      newState.tree = BinarySearchTree(newState.tree.root)
      newState.tree.add(payload)
      newState.balancedTree = BinarySearchTree(newState.balancedTree.root, true)
      newState.balancedTree.add(payload)
      newState.meta.containedValues[payload] = true
      return newState

    case 'REMOVE_NODE':
      const nodeToRemove = newState[treeKey].find(payload)
      const nodeToRemoveParent = nodeToRemove.parent
      const nodeSide = newState[treeKey].getNodeSide(nodeToRemove)
      newState.tree = BinarySearchTree(newState.tree.root)
      newState.tree.remove(payload)
      newState.balancedTree = BinarySearchTree(newState.balancedTree.root)
      newState.balancedTree.remove(payload)
      delete newState.meta.containedValues[payload]
      newState.meta.activeValue = nodeToRemoveParent &&
        nodeToRemoveParent[nodeSide] && nodeToRemoveParent[nodeSide].value 
      return newState

    case 'ROTATE_NODE':
      const pivotDirection = payload.direction === 'left' ? 'right' : 'left'
      const newActiveValue = payload.node[pivotDirection].value
      newState[treeKey] = BinarySearchTree(newState[treeKey].root)
      newState[treeKey].rotate(payload.direction, payload.node)
      newState.meta.activeValue = newActiveValue
      return newState

    case 'TOGGLE_BALANCED':
      newState.meta.balanced = !newState.meta.balanced
      return newState

    case 'CHANGE_VALUE':
      newState.meta.currValue = payload
      return newState

    case 'CHANGE_ACTIVE':
      newState.meta.activeValue = payload
      return newState

    default:
      return newState
  }
}

/* Redux Middleware & Store
** ************************************** */
const thunk = thunkMiddleware

const logger = window.reduxLogger
  ? window.reduxLogger({
      collapsed: (getState, action) =>
        true,
      predicate: (getState, {type}) =>
        type !== 'CHANGE_VALUE' &&
        type !== 'CHANGE_ACTIVE' &&
        type !== 'TOGGLE_BALANCED'
    })
  : ({dispatch, getState}) =>
      next =>
        action => {
          console.log({'Action Type': action.type, 'Updated State': getState()})
          return next(action) }

const store = createStore(
  rootReducer,
  initialState,
  applyMiddleware(thunk, logger)
)


/* Displays -- stateless or "dumb" components
** ************************************** */
const PrettyArray = ({values, activeValue, tree}) =>
  <div className='pretty-array'>
    <span className='bracket'>[</span>
    { values.map((value, i) =>
        <span className='value-and-comma' key={i}>
          { i > 0 ? <span className='comma'>,&nbsp;</span> : null }
          <span
            className={
              'value ' +
              (value === activeValue ? 'active ' : ' ') +
              ((tree.root && tree.root.value === value) && 'root')
            }
          >
            { zeroPadDigit(value) }
          </span>
        </span>)
    }
    <span className='bracket'>]</span>
  </div>

const RotateButton = ({direction = 'left', onClick}) =>
  <span className='rotate-btn' onClick={onClick}>
    <i className={'fa fa-rotate-' + direction} />
  </span>

const RemoveButton = ({onClick}) =>
  <span className='close-btn' onClick={onClick} >
    <i className='fa fa-close' />
  </span>

const NodeLabel = props =>
  <label className='node-label'
    onMouseEnter={e =>
      props.changeActive(props.node.value)}
    onMouseLeave={e =>
      props.changeActive(null)}
  >
      { props.balanceFactor > 0
        ? <RotateButton
            direction='left'
            onClick={e =>
              props.rotate({direction: 'left', node: props.node}) }
        /> : null
      }
      { props.balanceFactor < 0
        ? <RotateButton
            direction='right'
            onClick={e =>
              props.rotate({direction: 'right', node: props.node}) }
        /> : null
      }
      <RemoveButton onClick={e => props.remove(props.node.value)} />
      { zeroPadDigit(props.node.value) }
  </label>

const NodeChild = props =>
  <li className='flex-item'>
    { props.node[props.side] ? <Line side={props.side} /> : null }
    { props.node[props.side]
      ? <Node
          {...props}
          node={props.node[props.side]}
          balanceFactor={props.tree.getBalanceFactor(props.node[props.side])}
      /> : null
    }
  </li>

const NodeChildren = props =>
  <ol className='flex-container'>
    <NodeChild {...props} side='left' />
    <NodeChild {...props} side='right' />
  </ol>

const Node = props =>
  <div className='node'>
    <NodeLabel {...props} />
    <NodeChildren {...props} />
  </div>

const Tree = props =>
  <div className='tree'>
    { props.tree.root
      ? <Node
        tree={props.tree}
        node={props.tree.root}
        balanceFactor={props.tree.getBalanceFactor()}
        
        remove={props.remove}
        rotate={props.rotate}
        changeActive={props.changeActive}
      /> : null
    }
  </div>

const Heading = ({children}) =>
  <h1 className='heading'>{children}</h1>

const Select = ({onChange, placeholder, options = []}) =>
  <select onChange={onChange} defaultValue='placeholder'>
    { placeholder
        ? <option value='placeholder' disabled>{placeholder}</option>
        : null }
    { options.map(({value, disabled, label}, i) =>
        <option value={value} disabled={disabled} key={i}>{label}</option>) }
  </select>

const Checkbox = ({checked = true, onClick, children}) =>
  <div className='checkbox'>
    <label className={'box ' + (checked && 'checked')} onClick={onClick}>
      { checked ? <i className='check fa fa-check' /> : null }
    </label>
    <label className='toggle-label'>
      { children || 'Accept' }
    </label>
  </div>

const SubmitButton = ({onClick, disabled, children}) =>
  <button
    className='submit-btn'
    type='submit'
    onClick={onClick}
    disabled={disabled}
  >
    { children || 'Submit' }
  </button>

const Controls = props =>
  <form className='controls'>
    <fieldset>
      <CurrValueSelector />
      <CurrValueAddSubmitButton />
    </fieldset>
    <fieldset>
      <AutoBalancingCheckbox />
    </fieldset>
  </form>

/* Connector Creators & Providers -- connecting functions for decorating Containers
** ************************************** */
const createValueInStateConnector = (
  valuePath,                                  // '.' delimited path to value
  propName = valuePath.split('.').pop(),      // name of property in connector
  valueTransformer = (v, state) => v          // function to transform value
) => 
  connect(
    state =>
      ({ [propName]: valueTransformer(
        getNestedValue(
          valuePath, state
        ), state)
      }) )

const createValueToPropConnector = (value, propName) =>
  createValueInStateConnector('', propName, _ => value)

const createActionConnector = (actionName, propName = actionName) =>
  connect(null, dispatch =>
    ({ [propName]: actionCreators[actionName](dispatch) }) )

const createTransformedActionConnector = (
  actionName,                                 // key of action in actionCreators
  propName = actionName,                      // name of action in connector
  actionTransformer = (a, state) => a         // function to transform action
) =>
  connect(
    state => ({ state }),
    dispatch => ({ dispatch }),
    ({ state }, { dispatch }) =>
      ({ [propName]: actionTransformer(
        actionCreators[actionName](dispatch),
        state)
      }) )

const connectTreeState = createValueInStateConnector('meta.balanced', 'tree',
  (balanced, {balancedTree, tree}) => balanced ? balancedTree : tree )

const connectActionCallAsOnClick = actionName => createTransformedActionConnector(actionName, 'onClick',
  (action, { meta: { currValue }}) => e => {
    e.preventDefault()
    action(currValue)
  })

/* Containers -- decorated or "smart" components
** ************************************** */
const CurrTree = compose(
  connectTreeState,
  createActionConnector('remove'),
  createActionConnector('rotate'),
  createActionConnector('changeActive')
)(Tree)

const CurrValueSelector = compose(
  createTransformedActionConnector('changeValue', 'onChange',
    (onChange, state) => compose(onChange, e => parseInt(e.target.value) || 0) ),
  createValueToPropConnector('Values', 'placeholder'),
  createValueInStateConnector('meta', 'options',
    ({containedValues, availableValues}) =>
        availableValues.map(value => ({ value, label: zeroPadDigit(value), disabled: containedValues[value] }) ) )
)(Select)

const AutoBalancingCheckbox = compose(
  connectActionCallAsOnClick('toggleBalanced'),
  createValueToPropConnector('Auto-Balance', 'children'),
  createValueInStateConnector('meta.balanced', 'checked')
)(Checkbox)

const CurrValueAddSubmitButton = compose(
  connectActionCallAsOnClick('add'),
  createValueInStateConnector('meta', 'disabled',
    ({currValue, containedValues}) => typeof currValue !== 'number' || containedValues[currValue] ),
  createValueToPropConnector('Add', 'children')
)(SubmitButton)

const CurrValuesArray = compose(
  connectTreeState,
  createValueInStateConnector('meta.activeValue'),
  createValueInStateConnector('meta.containedValues', 'values',
    containedValues => Object.keys(containedValues).map(v => parseInt(v)) )
)(PrettyArray)

const Line = React.createClass({
  getDefaultProps () { return { side: 'root' } },
  getInitialState () { return { rotation: 30 } },
  componentDidMount () {
    window.addEventListener('resize', this.updateRotation)  
    this.updateRotation()
  },
  componentWillUnmount () {
    window.removeEventListener('resize', this.updateRotation)
  },
  updateRotation () {
    const opp = 100
    const adj = this.el.offsetWidth
    const rotation = Math.atan(opp / adj)
    this.setState({rotation})
  },
  render () {
    const offsetX = -25
    const offsetY = -25
    const scaleX = this.props.side === 'left' ? -1 : 1
    return <div
      className={'line ' + this.props.side}
      ref={el => this.el = el}
      style={{
        transform: `
          rotate(${this.state.rotation * scaleX}rad)
          translateX(${offsetX * scaleX}px)
          translateY(${offsetY}px)`
      }}
    />
  }
})

/* Main App component
** ************************************** */
const App = props =>
  <main>
    <Heading>Binary Tree</Heading>
    <Controls />
    <CurrValuesArray />
    <CurrTree />
  </main>

ReactDOM.render(
  <Provider store={store}><App /></Provider>,
  domContainerNode
)
              
            
!
999px

Console