{"size": 1132, "ext": "js", "max_stars_repo_path": "Assets/js/react/components/InputDropdown.js", "max_stars_repo_name": "Gintasp/university-advisor", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Assets/js/react/components/InputDropdown.js", "max_issues_repo_name": "Gintasp/university-advisor", "max_issues_repo_issues_event_min_datetime": "2019-09-14T21:49:27.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T19:03:35.000Z", "max_forks_repo_path": "Assets/js/react/components/InputDropdown.js", "max_forks_repo_name": "Gintasp/university-advisor", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 11, "max_forks_count": null, "avg_line_length": 23.1020408163, "max_line_length": 67, "alphanum_fraction": 0.4946996466}
import React from 'react';
import { TYPE_UNIVERSITY } from '../config/types';

class InputDropdown extends React.PureComponent {
  componentDidMount() {
    window.addEventListener('keyup', e => this.handleClose(e));
  }

  componentWillUnmount() {
    window.removeEventListener('keyup', e => this.handleClose(e));
  }

  handleClose(e) {
    const { onClose } = this.props;
    if (e.which === 27) {
      onClose();
    }
  }

  render() {
    const { items, onItemClick, opened } = this.props;

    if (!opened) {
      return null;
    }

    return (
      <div className="input-dropdown">
        <ul className="list-none p-0 m-0">
          {items.map((item, index) => (
            <li
              className="search-item"
              key={index}
              onClick={() => onItemClick(item)}
            >
              {item.Title}
              {item.Type !== TYPE_UNIVERSITY && (
                <p className="list-subitem">{item.University}</p>
              )}
            </li>
          ))}
        </ul>
      </div>
    );
  }
}

export default InputDropdown;
