<commit_before>'use strict';
import React        from 'react';
import objectAssign from 'object-assign';
import styles       from '../styles/SweetAlertStyles';

export default class Buttons extends React.Component {

    static propTypes = {
        confirmBtnText    : React.PropTypes.oneOfType([React.PropTypes.node, React.PropTypes.string]),
        cancelBtnText     : React.PropTypes.oneOfType([React.PropTypes.node, React.PropTypes.string]),
        cancelBtnBsStyle  : React.PropTypes.oneOf(['default', 'primary', 'link', 'info', 'success', 'warning', 'danger']),
        confirmBtnBsStyle : React.PropTypes.oneOf(['default', 'primary', 'link', 'info', 'success', 'warning', 'danger']),
        onCancel          : React.PropTypes.func,
        onConfirm         : React.PropTypes.func,
        showCancel        : React.PropTypes.bool,
        focusConfirmBtn   : React.PropTypes.bool
    };

    static defaultProps = {
        confirmBtnText    : 'OK',
        cancelBtnText     : 'Cancel',
        cancelBtnBsStyle  : 'link',
        confirmBtnBsStyle : 'primary',
        focusConfirmBtn   : true,
        showCancel        : false
    };

    componentDidMount() {
        if (this.props.focusConfirmBtn && this.refs.confirmBtn) {
            try {
                this.refs.confirmBtn.focus(); 
            } catch (e) {
                // whoops
            }
        }
    }

    getButtonStyle = (bsStyle) => {
        let borderColor = '';
        let shadowColor = '';
        switch (bsStyle) {
            case 'primary':
                borderColor = '#286090';
                shadowColor = 'rgb(165, 202, 234)';
                break;
            case 'success':
                borderColor = '#4cae4c';
                shadowColor = 'rgba(76, 174, 76, 0.6)';
                break;
            case 'info':
                borderColor = '#46b8da';
                shadowColor = 'rgba(70, 184, 218, 0.6)';
                break;
            case 'danger':
            case 'error':
                borderColor = '#d43f3a';
                shadowColor = 'rgba(212, 63, 58, 0.6)';
                break;
            case 'warning':
                borderColor = '#eea236';
                shadowColor = 'rgba(238, 162, 54, 0.6)';
                break;
            case 'default':
            default:
                borderColor = '#cccccc;';
                shadowColor = 'rgba(204, 204, 204, 0.6)';
                break;
        }
        return ` borderColor: ${borderColor} !important; boxShadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px ${shadowColor} !important;`;
    };

    render() {
        const cancelBtnBsStyle = this.props.cancelBtnBsStyle === 'error' ? 'danger' : this.props.cancelBtnBsStyle;
        const confirmBtnBsStyle = this.props.confirmBtnBsStyle === 'error' ? 'danger' : this.props.confirmBtnBsStyle;
        return (
            <p style={{marginTop: 20}}>
                {this.props.showCancel && (
                    <span>
                        <style type="text/css" scoped>
                            {'button { outline: 0 !important; ' + this.getButtonStyle(cancelBtnBsStyle) + '}'} 
                        </style>
                        <button 
                            style={styles.button} 
                            className={'btn btn-lg btn-' + cancelBtnBsStyle}
                            onClick={this.props.onCancel}
                            type="button" >
                            {this.props.cancelBtnText}
                        </button>
                    </span>
                )}
                <span>
                    <style type="text/css" scoped><commit_msg>optimize style generation for buttons<commit_after>'use strict';
import React        from 'react';
import objectAssign from 'object-assign';
import styles       from '../styles/SweetAlertStyles';

export default class Buttons extends React.Component {

    static propTypes = {
        confirmBtnText    : React.PropTypes.oneOfType([React.PropTypes.node, React.PropTypes.string]),
        cancelBtnText     : React.PropTypes.oneOfType([React.PropTypes.node, React.PropTypes.string]),
        cancelBtnBsStyle  : React.PropTypes.oneOf(['default', 'primary', 'link', 'info', 'success', 'warning', 'danger']),
        confirmBtnBsStyle : React.PropTypes.oneOf(['default', 'primary', 'link', 'info', 'success', 'warning', 'danger']),
        onCancel          : React.PropTypes.func,
        onConfirm         : React.PropTypes.func,
        showCancel        : React.PropTypes.bool,
        focusConfirmBtn   : React.PropTypes.bool
    };

    static defaultProps = {
        confirmBtnText    : 'OK',
        cancelBtnText     : 'Cancel',
        cancelBtnBsStyle  : 'link',
        confirmBtnBsStyle : 'primary',
        focusConfirmBtn   : true,
        showCancel        : false
    };

    static styles = {
        primary : {
            borderColor : '#286090',
            shadowColor : 'rgb(165, 202, 234)'
        },
        success : {
            borderColor : '#4cae4c',
            shadowColor : 'rgba(76, 174, 76, 0.6)'
        },
        info : {
            borderColor : '#46b8da',
            shadowColor : 'rgba(70, 184, 218, 0.6)'
        },
        danger : {
            borderColor : '#d43f3a',
            shadowColor : 'rgba(212, 63, 58, 0.6)'
        },
        warning : {
            borderColor : '#eea236',
            shadowColor : 'rgba(238, 162, 54, 0.6)'
        },
        default : {
            borderColor : '#cccccc',
            shadowColor : 'rgba(204, 204, 204, 0.6)'
        }
    };

    buttonStyles = {};

    componentDidMount() {
        if (this.props.focusConfirmBtn && this.refs.confirmBtn) {
            try {
                this.refs.confirmBtn.focus(); 
            } catch (e) {
                // whoops
            }
        }
    }

    getButtonStyle = (bsStyle) => {
        if (bsStyle === 'error') bsStyle = 'danger';
        if (this.buttonStyles[bsStyle] == null) {
            const style       = Buttons.styles[bsStyle] || Buttons.styles.default;
            const borderColor = `borderColor: ${style.borderColor} !important`;
            const boxShadow   = `boxShadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px ${style.shadowColor} !important;`;
            this.buttonStyles[bsStyle] = ` ${borderColor} ${boxShadow}`;
        }
        return this.buttonStyles[bsStyle];
    };

    render() {
        const cancelBtnBsStyle = this.props.cancelBtnBsStyle === 'error' ? 'danger' : this.props.cancelBtnBsStyle;
        const confirmBtnBsStyle = this.props.confirmBtnBsStyle === 'error' ? 'danger' : this.props.confirmBtnBsStyle;
        return (
            <p style={{marginTop: 20}}>
                {this.props.showCancel && (
                    <span>
                        <style type="text/css" scoped>
                            {'button { outline: 0 !important; ' + this.getButtonStyle(cancelBtnBsStyle) + '}'} 
                        </style>
                        <button 
                            style={styles.button} 
                            className={'btn btn-lg btn-' + cancelBtnBsStyle}
                            onClick={this.props.onCancel}
                            type="button" >
                            {this.props.cancelBtnText}
                        </button>
                    </span>
                )}
                <span>
                    <style type="text/css" scoped>
{'fraction_non_alphanumeric': 0.12546916890080428, 'fraction_numerical': 0.024128686327077747, 'mean_word_length': 1.551641586867305, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '2234138', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2007, 'n_words': 411}