<commit_before>/* eslint-disable max-len */

import React, { Component, PropTypes } from 'react';
import { injectStyles, removeAllStyles } from './inject-style';
import style from './styles';
import ComboBoxItem from './ComboBoxItem';
import Input from '../Input';
import filter from 'lodash/filter';
import isEmpty from 'lodash/isEmpty';
import map from 'lodash/map';
import uniqueId from 'lodash/uniqueId';
import styles from './styles.css';

/**
 * Update hover style for the specified styleId.
 *
 * @param caretStyleId {string} - unique is assigned as class to caret span
 * @param props {object} - the components props optionally containing hoverStyle
 */
function updatePseudoClassStyle(caretStyleId) {
  const caretFocusStyle = {
    ...style.caretFocusStyle,
  };

  const legacyStyles = [
    {
      id: caretStyleId,
      style: caretFocusStyle,
      pseudoClass: 'focus',
    },
  ];
  injectStyles(legacyStyles);
}

/**
 * Default function used for filtering options.
 */
function filterFunction(inputValue, optionValue) {
  if (inputValue && optionValue) {
    return optionValue.toString().toLowerCase().indexOf(inputValue.toString().toLowerCase()) > -1;
  }

  return false;
}

/**
 * ComboBox React Component.
 */
export default class ComboBox extends Component {

  static propTypes = {
    options: PropTypes.array,
    value: PropTypes.any,
    disabled: PropTypes.bool,
    onChange: PropTypes.func,
    tabIndex: PropTypes.number,
    onKeyDown: PropTypes.func,
    onFocus: PropTypes.func,
    onBlur: PropTypes.func,
    className: PropTypes.string,
    caretClassName: PropTypes.string,
    style: PropTypes.object,
    wrapperStyle: PropTypes.object,
    menuStyle: PropTypes.object,
    focusStyle: PropTypes.object,
    disabledStyle: PropTypes.object,
    disabledHoverStyle: PropTypes.object,
    hoverStyle: PropTypes.object,
    caretToOpenStyle: PropTypes.object,
    caretToCloseStyle: PropTypes.object,
    disabledCaretToOpenStyle: PropTypes.object,
    maxOptions: PropTypes.number,
    filterFunction: PropTypes.func,
    'aria-label': PropTypes.string,
  };

  static defaultProps = {
    disabled: false,
    'aria-label': 'ComboBox',
    filterFunction,
    tabIndex: 0,
    children: [],
  };

  static childContextTypes = {
    isHoveredIndex: PropTypes.number,
  };

  /**
   * Function to filter options using input value.
   */
  static filterOptions(inputValue, props) {
    let filteredOptions = props.options;
    if (!isEmpty(props.options)) {
      if (inputValue) {
        filteredOptions = filter(props.options, (entry) => (
          props.filterFunction(inputValue, entry.value)
        ));
      }

      if (props.maxOptions) {
        filteredOptions = filteredOptions.splice(0, props.maxOptions);
      }
    }

    return filteredOptions;
  }

  constructor(props) {
    super(props);

    this.state = {
      isOpen: false,
      focusedOptionIndex: undefined,
      filteredOptions: props.options,
    };
  }

  getChildContext() {
    return {
      isHoveredIndex: this.state.focusedOptionIndex,
    };<commit_msg>make combobox input controlled all the time<commit_after>/* eslint-disable max-len */

import React, { Component, PropTypes } from 'react';
import { injectStyles, removeAllStyles } from './inject-style';
import style from './styles';
import ComboBoxItem from './ComboBoxItem';
import Input from '../Input';
import filter from 'lodash/filter';
import isEmpty from 'lodash/isEmpty';
import map from 'lodash/map';
import uniqueId from 'lodash/uniqueId';
import styles from './styles.css';

/**
 * Update hover style for the specified styleId.
 *
 * @param caretStyleId {string} - unique is assigned as class to caret span
 * @param props {object} - the components props optionally containing hoverStyle
 */
function updatePseudoClassStyle(caretStyleId) {
  const caretFocusStyle = {
    ...style.caretFocusStyle,
  };

  const legacyStyles = [
    {
      id: caretStyleId,
      style: caretFocusStyle,
      pseudoClass: 'focus',
    },
  ];
  injectStyles(legacyStyles);
}

/**
 * Default function used for filtering options.
 */
function filterFunction(inputValue, optionValue) {
  if (inputValue && optionValue) {
    return optionValue.toString().toLowerCase().indexOf(inputValue.toString().toLowerCase()) > -1;
  }

  return false;
}

/**
 * ComboBox React Component.
 */
export default class ComboBox extends Component {

  static propTypes = {
    options: PropTypes.array,
    value: PropTypes.any,
    disabled: PropTypes.bool,
    onChange: PropTypes.func,
    tabIndex: PropTypes.number,
    onKeyDown: PropTypes.func,
    onFocus: PropTypes.func,
    onBlur: PropTypes.func,
    className: PropTypes.string,
    caretClassName: PropTypes.string,
    style: PropTypes.object,
    wrapperStyle: PropTypes.object,
    menuStyle: PropTypes.object,
    focusStyle: PropTypes.object,
    disabledStyle: PropTypes.object,
    disabledHoverStyle: PropTypes.object,
    hoverStyle: PropTypes.object,
    caretToOpenStyle: PropTypes.object,
    caretToCloseStyle: PropTypes.object,
    disabledCaretToOpenStyle: PropTypes.object,
    maxOptions: PropTypes.number,
    filterFunction: PropTypes.func,
    'aria-label': PropTypes.string,
  };

  static defaultProps = {
    disabled: false,
    'aria-label': 'ComboBox',
    filterFunction,
    tabIndex: 0,
    children: [],
  };

  static childContextTypes = {
    isHoveredIndex: PropTypes.number,
  };

  /**
   * Function to filter options using input value.
   */
  static filterOptions(inputValue, props) {
    let filteredOptions = props.options;
    if (!isEmpty(props.options)) {
      if (inputValue) {
        filteredOptions = filter(props.options, (entry) => (
          props.filterFunction(inputValue, entry.value)
        ));
      }

      if (props.maxOptions) {
        filteredOptions = filteredOptions.splice(0, props.maxOptions);
      }
    }

    return filteredOptions;
  }

  constructor(props) {
    super(props);

    this.state = {
      isOpen: false,
      focusedOptionIndex: undefined,
      filteredOptions: props.options,
      inputValue: '',
    };
  }

  getChildContext() {
    return {
      isHoveredIndex: this.state.focusedOptionIndex,
    };
{'fraction_non_alphanumeric': 0.11193309745899004, 'fraction_numerical': 0.0009649404953361209, 'mean_word_length': 3.3459119496855347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2010827', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1813, 'n_words': 441}