<commit_before>import React, { Component, PropTypes } from 'react'

export default class NumericInput extends Component {
  constructor(props) {
    super(props)
    this.handleOnChange = this.handleOnChange.bind(this)
    this.handleOnBlur = this.handleOnBlur.bind(this)

    this.state = {
      value: this.props.value || null,
    }
  }

  handleOnChange(event) {
    const newValue = event.target.value;
    if (newValue === this.state.value) return;
    if (!/^[+-]?\d*(\.\d*)?$/.test(newValue)) return;
    this.setState({ value: newValue });
  }

  handleOnBlur(event) {
    const newValue = parseFloat(event.target.value) || null;
    if (this.props.value === newValue) return;
    this.setState({ value: newValue });
    this.props.onBlur(newValue);
  }

  render() {
    return (
      <input
        type="text"
        className={this.props.className}
        value={this.state.value}
        onChange={this.handleOnChange}
        onBlur={this.handleOnBlur}
      />
    )
  }
}

NumericInput.propTypes = {
  value: PropTypes.number,
  className: PropTypes.string,
  onBlur: PropTypes.func.isRequired,<commit_msg>update NumericInput<commit_after>import React, { Component, PropTypes } from 'react'

export default class NumericInput extends Component {
  constructor(props) {
    super(props)
    this.handleOnChange = this.handleOnChange.bind(this)
    this.handleOnBlur = this.handleOnBlur.bind(this)

    this.state = {
      value: this.props.value || null,
    }
  }

  handleOnChange(event) {
    const newValue = parseFloat(event.target.value)

    if (/^[+-]?\d*(\.\d*)?$/.test(newValue)) {
      this.setState({ value: newValue })
    } else {
      this.setState({ value: parseFloat(this.state.value) || '' })
    }
  }

  handleOnBlur() {
    if (this.props.value !== this.state.value) {
      this.props.onBlur(this.state.value)
    }
  }

  render() {
    return (
      <input
        type="text"
        className={this.props.className}
        value={this.state.value}
        onChange={this.handleOnChange}
        onBlur={this.handleOnBlur}
      />
    )
  }
}

NumericInput.propTypes = {
  value: PropTypes.number,
  className: PropTypes.string,
  onBlur: PropTypes.func.isRequired,
{'fraction_non_alphanumeric': 0.14485559566787004, 'fraction_numerical': 0.0, 'mean_word_length': 2.882661996497373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6519471', 'n_tokens_mistral': 737, 'n_tokens_neox': 738, 'n_words': 119}