MCPcopy Create free account
hub / github.com/reactjs/react-modal / SimpleUsage

Class SimpleUsage

examples/basic/simple_usage/index.js:10–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8const DEFAULT_TITLE = 'Default title';
9
10class SimpleUsage extends Component {
11 constructor(props) {
12 super(props);
13 this.state = {
14 title1: DEFAULT_TITLE,
15 currentModal: null
16 };
17 }
18
19 toggleModal = key => event => {
20 event.preventDefault();
21 if (this.state.currentModal) {
22 this.handleModalCloseRequest();
23 return;
24 }
25
26 this.setState({
27 ...this.state,
28 currentModal: key,
29 title1: DEFAULT_TITLE
30 });
31 }
32
33 handleModalCloseRequest = () => {
34 // opportunity to validate something and keep the modal open even if it
35 // requested to be closed
36 this.setState({
37 ...this.state,
38 currentModal: null
39 });
40 }
41
42 handleInputChange = e => {
43 let text = e.target.value;
44 if (text == '') {
45 text = DEFAULT_TITLE;
46 }
47 this.setState({ ...this.state, title1: text });
48 }
49
50 handleOnAfterOpenModal = () => {
51 // when ready, we can access the available refs.
52 this.heading && (this.heading.style.color = '#F00');
53 }
54
55 render() {
56 const { currentModal } = this.state;
57
58 return (
59 <div>
60 <button type="button" className="btn btn-primary" onClick={this.toggleModal(MODAL_A)}>Open Modal A</button>
61 <button type="button" className="btn btn-primary" onClick={this.toggleModal(MODAL_B)}>Open Modal B</button>
62 <MyModal
63 title={this.state.title1}
64 isOpen={currentModal == MODAL_A}
65 onAfterOpen={this.handleOnAfterOpenModal}
66 onRequestClose={this.handleModalCloseRequest}
67 askToClose={this.toggleModal(MODAL_A)}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…