-
Notifications
You must be signed in to change notification settings - Fork 812
/
Copy pathindex.js
50 lines (46 loc) · 1.02 KB
/
index.js
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
import React, { Component } from "react";
import Modal from "react-modal";
class ModalClose extends Component {
constructor(props) {
super(props);
this.state = {
isOpen: false,
};
}
toggleModal = (event) => {
this.setState({ isOpen: !this.state.isOpen });
};
handleRightClick = (event) => {
this.setState({ isOpen: false });
};
render() {
return (
<div>
<button
type="button"
className="btn btn-primary"
onClick={this.toggleModal}
>
Open Modal
</button>
<Modal
isOpen={this.state.isOpen}
onOverlayRightClick={this.handleRightClick}
>
<h1>Click Right on the Overlay to close the modal</h1>
<button
type="button"
className="btn btn-primary"
onClick={this.toggleModal}
>
Close
</button>
</Modal>
</div>
);
}
}
export default {
label: "Modal close on right click",
app: ModalClose,
};