From bf5e2acf88c0e5ac0de4e954bd8aeb3a52bdfcf0 Mon Sep 17 00:00:00 2001 From: Clint Walker Date: Mon, 4 May 2015 15:34:38 +0800 Subject: [PATCH] Add a timeout prop to dismiss the notification --- README.md | 1 + src/notification.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index f5c053b..b365391 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ See [here](/bin/tests/test.js). | message | string | The message for the notification | true | | action | string | The name of the action, e.g., "close" or "undo" | | | styles | object || bool | Styles to apply to the component* | | +| dismissAfter | integer | Time in milliseconds to dismiss the notification (eg. `2000` for 2 seconds) | | *Setting this prop to `false` will disable all inline styles. This is useful if you aren't using React inline styles and would like to use CSS instead. See [styles](#styles) for more. diff --git a/src/notification.js b/src/notification.js index b7b6bc7..b08d74c 100644 --- a/src/notification.js +++ b/src/notification.js @@ -123,6 +123,15 @@ var Notification = React.createClass({ }; }, + componentWillReceiveProps: function (nextProps) { + if (!nextProps.dismissAfter) return; + + if (this.state.timeoutId) clearTimeout( this.state.timeoutId ); + this.state.timeoutId = setTimeout( this.hide(), nextProps.dismissAfter ); + + this.setState(this.state); + }, + render: function () { return (