Skip to content

Commit

Permalink
Merge pull request #14 from Jaywaa/modal-duration
Browse files Browse the repository at this point in the history
Adds duration prop to modals
  • Loading branch information
BrandonWade authored Apr 26, 2018
2 parents cce6275 + 4d3ae2b commit dccfae9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ export default Example;
* keyboard - Receive a callback function or a boolean to choose to close the modal when escape key is pressed.
* backdrop - Includes a backdrop element.
* closeOnClick - Close the backdrop element when clicked.
* duration - duration in milliseconds before the modal is hidden
* onShow - Show callback.
* onHide - Hide callback. Argument is the source of the hide action, one of:
* hide - hide() method is the cause of the hide.
* toggle - toggle() method is the cause of the hide
* keyboard - keyboard (escape key) is the cause of the hide
* backdrop - backdrop click is the cause of the hide
* timeout - timeout is the cause of the hide
* [any] - custom argument passed by invoking code into the hide() method when called directly.
* modalStyle - CSS styles to apply to the modal
* backdropStyle - CSS styles to apply to the backdrop
Expand Down
5 changes: 5 additions & 0 deletions src/modalFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export default (animation) => {
};

enter() {
if (this.props.duration >= 0)
setTimeout(() => this.hide("timeout"), parseInt(this.props.duration));

this.props.onShow();
};

Expand Down Expand Up @@ -164,6 +167,7 @@ export default (animation) => {
Factory.propTypes = {
className: PropTypes.string,
keyboard: PropTypes.bool,
duration: PropTypes.number,
onShow: PropTypes.func,
onHide: PropTypes.func,
animation: PropTypes.object,
Expand All @@ -176,6 +180,7 @@ export default (animation) => {

Factory.defaultProps = {
className: '',
duration: -1,
onShow: function(){},
onHide: function(){},
animation: animation,
Expand Down

0 comments on commit dccfae9

Please sign in to comment.