<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { c } from 'ttag';

import Icon from '../icon/Icon';

const label = (key) => {
    const I18N = {
        on: c('Toggle button').t`On`,
        off: c('Toggle button').t`Off`
    };

    return (
        <span className="pm-toggle-label-text">
            <Icon name={key} alt={I18N[key]} fill="none" className="pm-toggle-label-img" />
        </span>
    );
};

const Toggle = ({ id, className, checked, onChange, disabled, ...rest }) => {
    const handleChange = (event) => {
        if (!disabled && onChange) {
            onChange(event);
        }
    };

    return (
        <>
            <input
                disabled={disabled}
                id={id}
                onChange={handleChange}
                type="checkbox"
                className="pm-toggle-checkbox"
                checked={checked}
                {...rest}
            />
            <label htmlFor={id} className={`pm-toggle-label ${className}`}>
                {label('off')}
                {label('on')}
            </label>
        </>
    );
};

Toggle.propTypes = {
    id: PropTypes.string.isRequired,
    checked: PropTypes.bool.isRequired,
    onChange: PropTypes.func.isRequired,
    className: PropTypes.string,
    disabled: PropTypes.bool
};

Toggle.defaultProps = {
    id: 'toggle',
    className: ''
};

export default Toggle;
<commit_msg>Add loading state on Toggle<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { c } from 'ttag';

import Icon from '../icon/Icon';

const label = (key) => {
    const I18N = {
        on: c('Toggle button').t`On`,
        off: c('Toggle button').t`Off`
    };

    return (
        <span className="pm-toggle-label-text">
            <Icon name={key} alt={I18N[key]} fill="none" className="pm-toggle-label-img" />
        </span>
    );
};

const Toggle = ({ id, className, checked, loading, onChange, disabled, ...rest }) => {
    const handleChange = (event) => {
        if (!disabled && onChange) {
            onChange(event);
        }
    };

    return (
        <>
            <input
                disabled={loading ? true : disabled}
                id={id}
                onChange={handleChange}
                type="checkbox"
                className="pm-toggle-checkbox"
                checked={checked}
                aria-busy={loading}
                {...rest}
            />
            <label htmlFor={id} className={`pm-toggle-label ${className}`}>
                {label('off')}
                {label('on')}
            </label>
        </>
    );
};

Toggle.propTypes = {
    id: PropTypes.string.isRequired,
    checked: PropTypes.bool.isRequired,
    onChange: PropTypes.func.isRequired,
    className: PropTypes.string,
    disabled: PropTypes.bool,
    loading: PropTypes.bool
};

Toggle.defaultProps = {
    id: 'toggle',
    className: '',
    loading: false
};

export default Toggle;

{'fraction_non_alphanumeric': 0.1527638190954774, 'fraction_numerical': 0.002680067001675042, 'mean_word_length': 1.8249763481551562, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '2643400', 'n_tokens_mistral': 869, 'n_tokens_neox': 864, 'n_words': 182}