Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(Modal): add unmountOnClose functionality (#1381)
- Loading branch information
1 parent
e8a2945
commit 42a32c7
Showing
4 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */ | ||
|
||
import React from 'react'; | ||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Label, Form, FormGroup } from 'reactstrap'; | ||
|
||
class ModalExample extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
modal: false, | ||
unmountOnClose: true | ||
}; | ||
|
||
this.toggle = this.toggle.bind(this); | ||
this.changeUnmountOnClose = this.changeUnmountOnClose.bind(this); | ||
} | ||
|
||
toggle() { | ||
this.setState({ | ||
modal: !this.state.modal | ||
}); | ||
} | ||
|
||
changeUnmountOnClose(e) { | ||
let value = e.target.value; | ||
this.setState({ unmountOnClose: JSON.parse(value) }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<Form inline onSubmit={(e) => e.preventDefault()}> | ||
<FormGroup> | ||
<Label for="unmountOnClose">UnmountOnClose value</Label>{' '} | ||
<Input type="select" name="unmountOnClose" id="unmountOnClose" onChange={this.changeUnmountOnClose}> | ||
<option value="true">true</option> | ||
<option value="false">false</option> | ||
</Input> | ||
</FormGroup> | ||
{' '} | ||
<Button color="danger" onClick={this.toggle}>{this.props.buttonLabel}</Button> | ||
</Form> | ||
<Modal isOpen={this.state.modal} toggle={this.toggle} className={this.props.className} unmountOnClose={this.state.unmountOnClose}> | ||
<ModalHeader toggle={this.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={this.toggle}>Do Something</Button>{' '} | ||
<Button color="secondary" onClick={this.toggle}>Cancel</Button> | ||
</ModalFooter> | ||
</Modal> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default ModalExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters