<commit_before>import * as React from 'react';

import styles from './Checkbox.css';

import {IInputCallbackData} from '../_utils/types/commonTypes';
import {H2} from '../index';

export interface ICheckBoxGroupProps {

    /** what data is being used, helps whn extracting user input, you know on what field changes are made */
    dataLabel?: string;

    /** group id attribute */
    id?: string;

    /** group title attribute */
    title?: string;

    /** horizontal align Checkboxes */
    horizontal?: boolean;

    /** Spacing between Checkboxes */
    spacing?: number;

    /** CheckboxGroup class */
    className?: string;

    /** override CheckboxGroup styles */
    style?: {[key: string]: string};

    /** childrens must be a Checkbox Component */
    children?: Array<React.ReactElement<ICheckBoxProps>> | React.ReactElement<ICheckBoxProps>;

    /** Callback that fires when Checkbox Group state changes */
    onChange?: (e: React.MouseEvent<HTMLElement>, data: IInputCallbackData) => void;
}

export interface ICheckBoxProps {
    onClick?: (e: React.MouseEvent<HTMLElement>, data: IInputCallbackData) => void;

    /** what data is being used, helps whn extracting user input, you know on what field changes are made */
    dataLabel?: string;

    /** Checkbox id attribute */
    id?: string;

    /** provide to make the Checkbox disabled */
    disabled?: boolean;

    /** Checkbox matches the selected prop from parent component */
    checked?: boolean;

    /** value for this Checkbox */
    value: string;

    /** horizontal align Checkboxes */
    horizontal?: boolean;

    /** Spacing Checkbox */
    spacing?: number;

    /** Checkbox class */
    className?: string;

    /** name identifier for Checkbox */
    name?: string;

    /** override Checkbox styles */
    style?: {[key: string]: string};

    /** Checkbox label */
    label?: string;

    /** Checkbox description */
    description?: string;
}

class CheckBoxGroup extends React.Component<ICheckBoxGroupProps, {}>{

    public static defaultProps = {
        className: '',
        style: {},
    };

    public static CheckBox: React.StatelessComponent<ICheckBoxProps>;

    private name: string;

    constructor(props: ICheckBoxGroupProps){
        super(props);

        this.name = this.generateName();
    }

    public render() {

        const {id, className, style, title} = this.props;

        const align = this.props.horizontal ? styles.horizontal : '';

        const checkBoxes = this.assignCheckBoxes();

        return (
            <div
                id={id}
                className={`checkboxgroup-component ${className}`}
                style={{...style}}
            >
                <H2>{title}</H2>
                <div className={align}>
                    {checkBoxes}
                </div>
            </div>
        );
    }

    private onClick = (data: {checked: boolean, value: string, label: string}) => {
        return (e: React.MouseEvent<HTMLElement>) => {
            this.props.onChange && this.props.onChange(e, {value: data, dataLabel: this.props.dataLabel});
        };
    }<commit_msg>backup commit<commit_after>import * as React from 'react';

import styles from './Checkbox.css';

import {IInputCallbackData} from '../_utils/types/commonTypes';
import {H2} from '../index';

export interface ICheckBoxGroupProps {

    /** what data is being used, helps whn extracting user input, you know on what field changes are made */
    dataLabel?: string;

    /** group id attribute */
    id?: string;

    /** group title attribute */
    title?: string;

    /** horizontal align Checkboxes */
    horizontal?: boolean;

    /** Spacing between Checkboxes */
    spacing?: number;

    /** CheckboxGroup class */
    className?: string;

    /** override CheckboxGroup styles */
    style?: {[key: string]: string};

    /** childrens must be a Checkbox Component */
    children?: Array<React.ReactElement<ICheckBoxProps>> | React.ReactElement<ICheckBoxProps>;

    /** Callback to be passed to all checkboxes if no individual callbacks are specified */
    onClick?: (e: React.MouseEvent<HTMLElement>, data: IInputCallbackData) => void;

    /** Callback that fires when Checkbox Group state changes */
    onChange?: (e: React.MouseEvent<HTMLElement>, data: IInputCallbackData) => void;
}

export interface ICheckBoxProps {
    onClick?: (e: React.MouseEvent<HTMLElement>, data: IInputCallbackData) => void;

    /** what data is being used, helps whn extracting user input, you know on what field changes are made */
    dataLabel?: string;

    /** Checkbox id attribute */
    id?: string;

    /** provide to make the Checkbox disabled */
    disabled?: boolean;

    /** Checkbox matches the selected prop from parent component */
    checked?: boolean;

    /** value for this Checkbox */
    value: string;

    /** horizontal align Checkboxes */
    horizontal?: boolean;

    /** Spacing Checkbox */
    spacing?: number;

    /** Checkbox class */
    className?: string;

    /** name identifier for Checkbox */
    name?: string;

    /** override Checkbox styles */
    style?: {[key: string]: string};

    /** Checkbox label */
    label?: string;

    /** Checkbox description */
    description?: string;
}

export interface ICheckBoxState{
    data: ICheckBoxData[];
}

export interface ICheckBoxData{
    checked?: boolean;
    value?: string;
    label?: string;
}

class CheckBoxGroup extends React.Component<ICheckBoxGroupProps, ICheckBoxState>{

    public static defaultProps = {
        className: '',
        style: {},
    };

    public static CheckBox: React.StatelessComponent<ICheckBoxProps>;

    private name: string;

    constructor(props: ICheckBoxGroupProps){
        super(props);

        this.name = this.generateName();

        this.state = {
            data: [{}]
        };
    }

    public render() {

        const {id, className, style, title} = this.props;

        const headingStyle = title ? {} : {display: 'none'};

        const align = this.props.horizontal ? styles.horizontal : '';

        const checkBoxes = this.assignCheckBoxes();

        return (
            <div
                id={id}
                className={`checkboxgroup-component ${className}`}
                style={{...style}}
            >
                <H2 style={headingStyle} >{title}</H2>
                <div className={align}>
                    {checkBoxes}
                </div>
            </div>
        );
    }

    public componentDidMount() {
        this.setData();
    }

    private onClick = (data: {checked: boolean, value: string, label: string}) => {
        return (e: React.MouseEvent<HTMLElement>) => {
            this.props.onClick && this.props.onClick(e, {value: data, dataLabel: this.props.dataLabel});
        };
    }

    private setData = () => {
        const data: ICheckBoxData[] = [];
        React.Children.map(this.props.children, (child) => {
            if (React.isValidElement<ICheckBoxProps>(child)){
                data.push({
                    checked: child.props.checked,
                    label: child.props.label,
                    value: child.props.value
                });
            }
        });
        this.setState({data});
    }
{'fraction_non_alphanumeric': 0.12805380181169365, 'fraction_numerical': 0.0008234971177600879, 'mean_word_length': 2.3642659279778395, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 44, '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': '4603833', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1928, 'n_words': 568}