<commit_before>// @flow

import React, { Component, PropTypes } from 'react';

type Props = {
    checked: boolean,
    onToggle: (checked: boolean) => void,
    className: string
}

export class Favorite extends Component {

    state: {
        checked: boolean
    };

    static defaultProps = {
        checked: false,
        className: ''
    };

    componentWillMount() {
        this._updateState(this.props);
    }

    componentWillReceiveProps(props: Props) {
        this._updateState(props);
    }

    _updateState(props: Props) {
        this.setState({
            checked: props.checked
        });
    }

    toggle(e: Event) {
        if (e.target instanceof HTMLInputElement) {
            const checked = e.target.checked;
            this.setState({
                checked: checked
            });

            if (this.props.onToggle != null){
                this.props.onToggle(checked);
            }
        }
    }

    render() {
        return (
            <label className={`checkbox ${this.props.className}`}>
                <input type="checkbox"
                       onChange={this.toggle.bind(this)}
                       checked={this.state.checked} />
                <span></span>
            </label>
        );
    }
}

Favorite.propTypes = {
    checked: PropTypes.bool,
    className: PropTypes.oneOf(['', 'dark-yellow', 'dark-white']),
    onToggle: PropTypes.func
};<commit_msg>[JENKINS-37023] stop propogation of click events outside the Favorite component, so it can be placed in containers with click listeners without hassle<commit_after>// @flow

import React, { Component, PropTypes } from 'react';

type Props = {
    checked: boolean,
    onToggle: (checked: boolean) => void,
    className: string
}

export class Favorite extends Component {

    state: {
        checked: boolean
    };

    static defaultProps = {
        checked: false,
        className: ''
    };

    componentWillMount() {
        this._updateState(this.props);
    }

    componentWillReceiveProps(props: Props) {
        this._updateState(props);
    }

    _updateState(props: Props) {
        this.setState({
            checked: props.checked
        });
    }

    toggle(e: Event) {
        if (e.target instanceof HTMLInputElement) {
            const checked = e.target.checked;
            this.setState({
                checked: checked
            });

            if (this.props.onToggle != null){
                this.props.onToggle(checked);
            }
        }
    }

    render() {
        return (
            <label className={`checkbox ${this.props.className}`}
              onClick={(event) => event.stopPropagation()}
            >
                <input type="checkbox"
                       onChange={this.toggle.bind(this)}
                       checked={this.state.checked} />
                <span></span>
            </label>
        );
    }
}

Favorite.propTypes = {
    checked: PropTypes.bool,
    className: PropTypes.oneOf(['', 'dark-yellow', 'dark-white']),
    onToggle: PropTypes.func
};
{'fraction_non_alphanumeric': 0.12121212121212122, 'fraction_numerical': 0.0016291951775822744, 'mean_word_length': 1.7607913669064748, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, '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': '5987584', 'n_tokens_mistral': 851, 'n_tokens_neox': 832, 'n_words': 177}