<commit_before>import React, {Component, PropTypes} from 'react';
import defaultStyles from './styles';
import Header from './header';
import Body from './body';

class ModalView extends Component {

    constructor(props) {
        super(props);
        this.state = {isVisible: props.isVisible || false};
    }

    componentWillUpdate(nextProps, nextState) {

        const {isVisible} = this.state;
        const {beforeOpen, beforeClose} = this.props;

        if (nextState.isVisible && !isVisible && beforeOpen) {
            beforeOpen();
        }

        if (!nextState.isVisible && isVisible && beforeClose) {
            beforeClose();
        }
    }

    componentDidUpdate(prevProps, prevState) {

        const {isVisible} = this.state;
        const {afterOpen, afterClose} = this.props;

        if (!prevState.isVisible && isVisible && afterOpen) {
            afterOpen();
        }

        if (prevState.isVisible && !isVisible && afterClose) {<commit_msg>[UX-320] Escape closes modals<commit_after>import React, {Component, PropTypes} from 'react';
import defaultStyles from './styles';
import Header from './header';
import Body from './body';

class ModalView extends Component {

    constructor(props) {
        super(props);
        this.state = {isVisible: props.isVisible || false};
        this._handleKeys = this._handleKeys.bind(this);
    }

    componentWillMount() {
        document.addEventListener("keydown", this._handleKeys, false);
    }

    componentWillUnmount() {
        document.removeEventListener("keydown", this._handleKeys, false);
    }

    _handleKeys(event){
        if (event.keyCode == 27) {
            this.hide();
        }
    }
    
    componentWillUpdate(nextProps, nextState) {

        const {isVisible} = this.state;
        const {beforeOpen, beforeClose} = this.props;

        if (nextState.isVisible && !isVisible && beforeOpen) {
            beforeOpen();
        }

        if (!nextState.isVisible && isVisible && beforeClose) {
            beforeClose();
        }
    }

    componentDidUpdate(prevProps, prevState) {

        const {isVisible} = this.state;
        const {afterOpen, afterClose} = this.props;

        if (!prevState.isVisible && isVisible && afterOpen) {
            afterOpen();
        }

        if (prevState.isVisible && !isVisible && afterClose) {
{'fraction_non_alphanumeric': 0.12468085106382978, 'fraction_numerical': 0.002127659574468085, 'mean_word_length': 2.482962962962963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3382155', 'n_tokens_mistral': 661, 'n_tokens_neox': 638, 'n_words': 148}