<commit_before>import React, { Component } from "react";
import PropTypes from "prop-types";
import { filterProps } from "../../helpers/functions";
import classes from "./Form.scss";
import WithWrapper from "./_WithWrapper";
import debounce from "lodash.debounce";

export class InputCheckbox extends Component {
  static defaultProps = {
    checked: false
  };

  static propTypes = {
    /**
     * Whether the checkbox is checked or not.
     */
    checked: PropTypes.bool,

    /**
     * The value of the input.
     */
    value: PropTypes.any,

    /**
     * The label for the input.
     */
    label: PropTypes.string,

    /**
     * The input name.
     */
    name: PropTypes.string
  };

  constructor(props) {
    super(props);

    this.state = {
      checked: props.checked
    };
  }

  /**
   * Sync the value.
   */
  componentWillReceiveProps(nextProps) {
    if (nextProps.checked !== this.props.checked) {
      this.setState({ checked: nextProps.checked });
    }
  }

  /**
   * Toggle the input checkbox.
   */
  toggle = debounce(() => {
    this.setState({ checked: !this.state.checked }, () => {
      if (typeof this.props.onChange === "function") {
        const { name, checked, value } = this.props;
        const newValue = this.state.checked ? value : false;
        this.props.onChange(newValue, {
          name,
          initialValue: checked,
          formValue: newValue // Required for the getKeyValuePair function
        });
      }
    });
  }, 100, { leading: true, trailing: false })

  render() {
    const { value, checked } = this.state;
    const { label, name } = this.props;
    const props = filterProps(InputCheckbox.propTypes, this.props);

    return (
      // We do not use a real label here because react complains
      // about uncontrolled/controlled components.
      <span onClick={this.toggle} className={classes.cbLabel}>
        <input
          {...props}
          name={name}
          type="checkbox"
          value={value}
          checked={checked}<commit_msg>Do not allow toggling when checkbox is disabled<commit_after>import React, { Component } from "react";
import PropTypes from "prop-types";
import { filterProps } from "../../helpers/functions";
import classes from "./Form.scss";
import WithWrapper from "./_WithWrapper";
import debounce from "lodash.debounce";

export class InputCheckbox extends Component {
  static defaultProps = {
    checked: false
  };

  static propTypes = {
    /**
     * Whether the checkbox is checked or not.
     */
    checked: PropTypes.bool,

    /**
     * The value of the input.
     */
    value: PropTypes.any,

    /**
     * The label for the input.
     */
    label: PropTypes.string,

    /**
     * The input name.
     */
    name: PropTypes.string
  };

  constructor(props) {
    super(props);

    this.state = {
      checked: props.checked
    };
  }

  /**
   * Sync the value.
   */
  componentWillReceiveProps(nextProps) {
    if (nextProps.checked !== this.props.checked) {
      this.setState({ checked: nextProps.checked });
    }
  }

  /**
   * Toggle the input checkbox.
   */
  toggle = debounce(() => {
    if (this.props.disabled) {
      return;
    }

    this.setState({ checked: !this.state.checked }, () => {
      if (typeof this.props.onChange === "function") {
        const { name, checked, value } = this.props;
        const newValue = this.state.checked ? value : false;
        this.props.onChange(newValue, {
          name,
          initialValue: checked,
          formValue: newValue // Required for the getKeyValuePair function
        });
      }
    });
  }, 100, { leading: true, trailing: false })

  render() {
    const { value, checked } = this.state;
    const { label, name } = this.props;
    const props = filterProps(InputCheckbox.propTypes, this.props);

    return (
      // We do not use a real label here because react complains
      // about uncontrolled/controlled components.
      <span onClick={this.toggle} className={classes.cbLabel}>
        <input
          {...props}
          name={name}
          type="checkbox"
          value={value}
          checked={checked}
{'fraction_non_alphanumeric': 0.1298607777244359, 'fraction_numerical': 0.0014402304368698992, 'mean_word_length': 2.235248447204969, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2541036', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1184, 'n_words': 319}