forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModalDestructuring.js
More file actions
48 lines (42 loc) · 1.85 KB
/
Copy pathModalDestructuring.js
File metadata and controls
48 lines (42 loc) · 1.85 KB
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
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
import React, { useState } from 'react';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Label, Form, FormGroup } from 'reactstrap';
const ModalExample = (props) => {
const {
buttonLabel,
className
} = props;
const [modal, setModal] = useState(false);
const [unmountOnClose, setUnmountOnClose] = useState(true);
const toggle = () => setModal(!modal);
const changeUnmountOnClose = e => {
let value = e.target.value;
setUnmountOnClose(JSON.parse(value));
}
return (
<div>
<Form inline onSubmit={(e) => e.preventDefault()}>
<FormGroup>
<Label for="unmountOnClose">UnmountOnClose value</Label>{' '}
<Input type="select" name="unmountOnClose" id="unmountOnClose" onChange={changeUnmountOnClose}>
<option value="true">true</option>
<option value="false">false</option>
</Input>
</FormGroup>
{' '}
<Button color="danger" onClick={toggle}>{buttonLabel}</Button>
</Form>
<Modal isOpen={modal} toggle={toggle} className={className} unmountOnClose={unmountOnClose}>
<ModalHeader toggle={toggle}>Modal title</ModalHeader>
<ModalBody>
<Input type="textarea" placeholder="Write something (data should remain in modal if unmountOnClose is set to false)" rows={5} />
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={toggle}>Do Something</Button>{' '}
<Button color="secondary" onClick={toggle}>Cancel</Button>
</ModalFooter>
</Modal>
</div>
);
}
export default ModalExample;