<commit_before>import * as React from "react";
const { Col, FormControl, FormGroup, Row } = require("react-bootstrap");

interface Props {
  number: number;
  min?: number;
  max?: number;
  on_change: (n: number) => void;
  unit?: string;
  disabled?: boolean;
}

interface State {
  number: number | string;
}

export class NumberInput extends React.Component<Props, State> {
  constructor(props) {
    super(props);
    this.state = { number: this.props.number };
  }

  componentWillReceiveProps(next_props) {
    if (this.props.number !== next_props.number) {
      this.setState({ number: next_props.number });
    }
  }

  saveChange = (e?) => {
    if (e != undefined) {
      e.preventDefault();
    }
    let n = this.state.number;
    if (typeof n == "string") {
      n = parseInt(n);
      if (isNaN(n)) {
        n = this.props.number;
      }
    }
    if (this.props.min != null && n < this.props.min) {
      n = this.props.min;
    } else if (this.props.max != null && n > this.props.max) {
      n = this.props.max;
    }
    this.setState({ number: n });
    this.props.on_change(n);
  };

  render() {
    const unit = this.props.unit != undefined ? `${this.props.unit}` : "";
    return (
      <Row>
        <Col xs={6}>
          <form onSubmit={this.saveChange}>
            <FormGroup>
              <FormControl
                type="text"
                ref="input"
                value={
                  this.state.number != undefined
                    ? this.state.number
                    : this.props.number
                }
                onChange={(e) =>
                  this.setState({
                    number: e.target.value,
                  })
                }
                onBlur={this.saveChange}
                onKeyDown={(e) => {
                  if (e.keyCode === 27) {
                    // async setState, since it depends on props.
                    this.setState((_, props) => {
                      number: props.number;
                    });
                  }
                }}
                disabled={this.props.disabled}
              />
            </FormGroup>
          </form>
        </Col>
        <Col xs={6} className="lighten">
          {unit}
        </Col>
      </Row>
    );
  }
}<commit_msg>rewrite NumberInput using antd (instead of react-bootstrap)<commit_after>import * as React from "react";
const { Col, Row, Input } = require("antd");

interface Props {
  number: number;
  min?: number;
  max?: number;
  on_change: (n: number) => void;
  unit?: string;
  disabled?: boolean;
}

interface State {
  number: number | string;
}

export class NumberInput extends React.Component<Props, State> {
  constructor(props) {
    super(props);
    this.state = { number: this.props.number };
  }

  componentWillReceiveProps(next_props) {
    if (this.props.number !== next_props.number) {
      this.setState({ number: next_props.number });
    }
  }

  saveChange = (e?) => {
    if (e != undefined) {
      e.preventDefault();
    }
    let n = this.state.number;
    if (typeof n == "string") {
      n = parseInt(n);
      if (isNaN(n)) {
        n = this.props.number;
      }
    }
    if (this.props.min != null && n < this.props.min) {
      n = this.props.min;
    } else if (this.props.max != null && n > this.props.max) {
      n = this.props.max;
    }
    this.setState({ number: n });
    this.props.on_change(n);
  };

  render() {
    const unit = this.props.unit != undefined ? `${this.props.unit}` : "";
    return (
      <Row gutter={16}>
        <Col xs={16}>
          <Input
            type="text"
            ref="input"
            value={
              this.state.number != undefined
                ? this.state.number
                : this.props.number
            }
            onChange={(e) =>
              this.setState({
                number: e.target.value,
              })
            }
            onBlur={this.saveChange}
            onKeyDown={(e) => {
              if (e.keyCode === 27) {
                // async setState, since it depends on props.
                this.setState((_, props) => {
                  number: props.number;
                });
              } else if (e.keyCode === 13) {
                this.saveChange();
              }
            }}
            disabled={this.props.disabled}
          />
        </Col>
        <Col xs={8} className="lighten">
          {unit}
        </Col>
      </Row>
    );
  }
}
{'fraction_non_alphanumeric': 0.14649397052255472, 'fraction_numerical': 0.0029030817329164806, 'mean_word_length': 1.498047964305633, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, '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': '1544862', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1331, 'n_words': 284}