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
|
const React = require('react');
const HotKeys = require('./HotKeys');
/**
* Backdrop for modals, dropdown, etc. that covers the whole screen
* and handles click and pressing escape.
*
* <Backdrop onClose={onCloseModal} />
*/
const Backdrop = React.createClass({
propTypes: {
// Callback when backdrop is closed
onClose: React.PropTypes.func.isRequired,
// Z-index for the backdrop
zIndex: React.PropTypes.number,
children: React.PropTypes.node
},
getDefaultProps() {
return {
zIndex: 200
};
},
onClick(event) {
const { onClose } = this.props;
event.preventDefault();
event.stopPropagation();
onClose();
},
render() {
const { zIndex, children, onClose } = this.props;
const style = {
zIndex,
position: 'fixed',
top: 0,
right: 0,
width: '100%',
height: '100%'
};
const keyMap = {
'escape': onClose
};
return (
<HotKeys keyMap={keyMap}>
<div style={style} onClick={this.onClick}>{children}</div>
</HotKeys>
);
}
});
module.exports = Backdrop;
|