{"size": 797, "ext": "js", "max_stars_repo_path": "src/website/Sidebar.js", "max_stars_repo_name": "DefinityLabs/website", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/website/Sidebar.js", "max_issues_repo_name": "DefinityLabs/website", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/website/Sidebar.js", "max_forks_repo_name": "DefinityLabs/website", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.9761904762, "max_line_length": 84, "alphanum_fraction": 0.5846925972}
import React, { Component } from 'react';
import './Sidebar.css';

class Sidebar extends Component {
  render() {
    return (
      <div className="sidebar">
        <ul>
          {this.props.children}
        </ul>
      </div>
    );
  }
}

class SidebarItem extends Component {
  goTo(id) {
    window.scroll(0, findElementPosition(document.querySelector(id)) - 40);
    return false;
  }

  render() {
    return (
      <li>
        <a onClick={this.goTo.bind(this, this.props.href)}>{this.props.children}</a>
      </li>
    );
  }
}

function findElementPosition(obj) {
    var curtop = 0;
    let element = obj;
    while (element.offsetParent) {
        curtop += element.offsetTop;
        element = element.offsetParent;
    }
    return [curtop];
}

export { Sidebar, SidebarItem };
