summaryrefslogtreecommitdiffstats
path: root/web/react/components/modal.jsx
blob: 758a688471e204f00b63982b8fe2890f7ec9b406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

export default class Modal extends ReactBootstrap.Modal {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        if (this.props.show && this.props.onPreshow) {
            this.props.onPreshow();
        }
    }

    componentDidMount() {
        super.componentDidMount();

        if (this.props.show && this.props.onShow) {
            this.props.onShow();
        }
    }

    componentDidUpdate(prevProps) {
        super.componentDidUpdate(prevProps);

        if (this.props.show && !prevProps.show && this.props.onShow) {
            this.props.onShow();
        }
    }

    componentWillReceiveProps(nextProps) {
        super.componentWillReceiveProps(nextProps);

        if (nextProps.show && !this.props.show && this.props.onPreshow) {
            this.props.onPreshow();
        }
    }
}

Modal.propTypes = {
    ...ReactBootstrap.Modal.propTypes,

    // called before showing the dialog to allow for a state change before rendering
    onPreshow: React.PropTypes.func,

    // called after the dialog has been shown and rendered
    onShow: React.PropTypes.func
};