summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/components/shared/Modal.js
blob: dec65e627b26e789acc83da86b3878a47149f419 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

import PropTypes from "prop-types";
import React from "react";
import Transition from "react-transition-group/Transition";
const classnames = require("devtools/client/shared/classnames.js");
import "./Modal.css";

export const transitionTimeout = 50;

export class Modal extends React.Component {
  static get propTypes() {
    return {
      additionalClass: PropTypes.string,
      children: PropTypes.node.isRequired,
      handleClose: PropTypes.func.isRequired,
      status: PropTypes.string.isRequired,
    };
  }

  onClick = e => {
    e.stopPropagation();
  };

  render() {
    const { additionalClass, children, handleClose, status } = this.props;

    return (
      <div className="modal-wrapper" onClick={handleClose}>
        <div
          className={classnames("modal", additionalClass, status)}
          onClick={this.onClick}
        >
          {children}
        </div>
      </div>
    );
  }
}

Modal.contextTypes = {
  shortcuts: PropTypes.object,
};

export default function Slide({
  in: inProp,
  children,
  additionalClass,
  handleClose,
}) {
  return (
    <Transition in={inProp} timeout={transitionTimeout} appear>
      {status => (
        <Modal
          status={status}
          additionalClass={additionalClass}
          handleClose={handleClose}
        >
          {children}
        </Modal>
      )}
    </Transition>
  );
}

Slide.propTypes = {
  additionalClass: PropTypes.string,
  children: PropTypes.node.isRequired,
  handleClose: PropTypes.func.isRequired,
  in: PropTypes.bool.isRequired,
};