From 1063cbe12770d1c0abb956a6978b44044ebff7ec Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Wed, 3 Aug 2016 16:48:04 -0700 Subject: [PATCH 1/3] can render a react component within the notification --- README.md | 1 + src/NotificationItem.jsx | 18 ++++++++++++++---- src/constants.js | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 09f8e84..8885a0f 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ The notification object has the following properties: |------------ |--------------- |--------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | title | string | null | Title of the notification | | message | string | null | Message of the notification | +| getContentComponent | function | null | Return a React component to display in the notification (override other settings) | | level | string | null | Level of the notification. Available: **success**, **error**, **warning** and **info** | | position | string | tr | Position of the notification. Available: **tr (top right)**, **tl (top left)**, **tc (top center)**, **br (bottom right)**, **bl (bottom left)**, **bc (bottom center)** | | autoDismiss | integer | 5 | Delay in seconds for the notification go away. Set this to **0** to not auto-dismiss the notification | diff --git a/src/NotificationItem.jsx b/src/NotificationItem.jsx index eba803d..0473525 100644 --- a/src/NotificationItem.jsx +++ b/src/NotificationItem.jsx @@ -241,6 +241,7 @@ var NotificationItem = React.createClass({ var actionButton = null; var title = null; var message = null; + var getContentComponent = notification.getContentComponent; if (this.state.visible) { className = className + ' notification-visible'; @@ -304,12 +305,21 @@ var NotificationItem = React.createClass({ ); } + var content; + if (getContentComponent) { + content = getContentComponent(); + } else { + content = [ + title, + message, + dismiss, + actionButton, + ] + } + return (
- { title } - { message } - { dismiss } - { actionButton } + { content }
); } diff --git a/src/constants.js b/src/constants.js index 59538d5..db67b0d 100644 --- a/src/constants.js +++ b/src/constants.js @@ -26,7 +26,8 @@ var CONSTANTS = { position: 'tr', autoDismiss: 5, dismissible: true, - action: null + action: null, + getContentComponent: null } }; From 70f4f3247db960f5a4cfaf3d0d13746892f1428a Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Wed, 3 Aug 2016 16:54:09 -0700 Subject: [PATCH 2/3] pass the notification id to the child component --- src/NotificationItem.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NotificationItem.jsx b/src/NotificationItem.jsx index 0473525..f5d26ac 100644 --- a/src/NotificationItem.jsx +++ b/src/NotificationItem.jsx @@ -307,7 +307,7 @@ var NotificationItem = React.createClass({ var content; if (getContentComponent) { - content = getContentComponent(); + content = getContentComponent(notification.uid); } else { content = [ title, From d950ccc5836332e4228dfdf86beca23d1f0c94bf Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Wed, 3 Aug 2016 17:24:39 -0700 Subject: [PATCH 3/3] lint --- src/NotificationItem.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NotificationItem.jsx b/src/NotificationItem.jsx index f5d26ac..b09b71a 100644 --- a/src/NotificationItem.jsx +++ b/src/NotificationItem.jsx @@ -241,6 +241,7 @@ var NotificationItem = React.createClass({ var actionButton = null; var title = null; var message = null; + var content; var getContentComponent = notification.getContentComponent; if (this.state.visible) { @@ -305,7 +306,6 @@ var NotificationItem = React.createClass({ ); } - var content; if (getContentComponent) { content = getContentComponent(notification.uid); } else { @@ -313,8 +313,8 @@ var NotificationItem = React.createClass({ title, message, dismiss, - actionButton, - ] + actionButton + ]; } return (