<commit_before>import PropTypes from 'prop-types'
import React from 'react'
import classNames from 'classnames'
import uncontrollableInput from 'uncontrollable-input'

import Component from '../base-component'
import Icon from '../icon'

@uncontrollableInput()
export default class Toggle extends Component {
  static propTypes = {
    className: PropTypes.string,
    onChange: PropTypes.func.isRequired,
    icon: PropTypes.string,
    iconOn: PropTypes.string,
    iconOff: PropTypes.string,
    iconSize: PropTypes.number,
    value: PropTypes.bool.isRequired,
  }

  static defaultProps = {
    iconOn: 'toggle-on',
    iconOff: 'toggle-off',
    iconSize: 2,
  }

  _toggle = () => {
    const { props } = this
    props.onChange(!props.value)
  }

  render () {
    const { props } = this

    return (
      <Icon
        className={classNames(
          props.disabled ? 'text-muted' : props.value ? 'text-success' : null,
          props.className
        )}
        icon={props.icon || (props.value ? props.iconOn : props.iconOff)}
        onClick={this._toggle}
        size={props.iconSize}
      /><commit_msg>fix(xo-web/form/Toggle): dont emit onChange if disabled (#3643)<commit_after>import PropTypes from 'prop-types'
import React from 'react'
import classNames from 'classnames'
import uncontrollableInput from 'uncontrollable-input'

import Component from '../base-component'
import Icon from '../icon'

@uncontrollableInput()
export default class Toggle extends Component {
  static propTypes = {
    className: PropTypes.string,
    onChange: PropTypes.func.isRequired,
    icon: PropTypes.string,
    iconOn: PropTypes.string,
    iconOff: PropTypes.string,
    iconSize: PropTypes.number,
    value: PropTypes.bool.isRequired,
  }

  static defaultProps = {
    iconOn: 'toggle-on',
    iconOff: 'toggle-off',
    iconSize: 2,
  }

  _toggle = () => {
    const { props } = this

    if (!props.disabled) {
      props.onChange(!props.value)
    }
  }

  render () {
    const { props } = this

    return (
      <Icon
        className={classNames(
          props.disabled ? 'text-muted' : props.value ? 'text-success' : null,
          props.className
        )}
        icon={props.icon || (props.value ? props.iconOn : props.iconOff)}
        onClick={this._toggle}
        size={props.iconSize}
      />
{'fraction_non_alphanumeric': 0.12125107112253641, 'fraction_numerical': 0.002570694087403599, 'mean_word_length': 2.8531353135313533, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2966663', 'n_tokens_mistral': 706, 'n_tokens_neox': 703, 'n_words': 166}