Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #45 from sergiofm/master
Browse files Browse the repository at this point in the history
Fix DismissAfter hardcoded in notification stack
  • Loading branch information
Patrick Burtchaell committed Feb 15, 2016
2 parents d2e1836 + a8781d5 commit acfb051
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/notificationStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ import StackedNotification from './stackedNotification';
const NotificationStack = props => (
<div className="notification-list">
{props.notifications.map((notification, index) => {
const dismissAfter = notification.dismissAfter || props.dismissAfter;
const dismissAfter = notification.dismissAfter || props.dismissAfter || 2000;
const lastNotificationDismissAfter = 300;
const isLast = index === 0 && props.notifications.length === 1;

return (
<StackedNotification
{...notification}
key={notification.key}
isLast={isLast}
action={notification.action || props.action}
dismissAfter={isLast ? 2000 : 2000 + (index * 1000)}
dismissAfter={isLast ? dismissAfter : dismissAfter + (index * 1000)}
onClick={() => props.onDismiss(notification)}
onDismiss={() => setTimeout(() => {
setTimeout(props.onDismiss.bind(this, notification), lastNotificationDismissAfter);
}, dismissAfter !== null ? dismissAfter : 2000)}
style={{
}, dismissAfter)}
style={notification.style !== null ? notification.style : {
bar: {
bottom: `${2 + index * 4}rem`,
}
Expand Down
8 changes: 7 additions & 1 deletion test/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import expect from 'expect';
import { Notification, NotificationStack } from '../src/index';

const MOCK = {
key: 1111111,
message: 'Test',
action: 'Dismiss',
dismissAfter: 3000,
onClick: function handleClick() {
return;
},
Expand All @@ -32,6 +34,7 @@ describe('Notification', () => {
message={MOCK.message}
action={MOCK.action}
onClick={MOCK.onClick}
dismissAfter={MOCK.dismissAfter}
/>
);

Expand All @@ -44,6 +47,7 @@ describe('Notification', () => {
message={MOCK.message}
action={MOCK.action}
onClick={MOCK.onClick}
dismissAfter={MOCK.dismissAfter}
/>
);

Expand All @@ -61,6 +65,7 @@ describe('Notification', () => {
message={MOCK.message}
action={MOCK.action}
onClick={MOCK.onClick}
dismissAfter={MOCK.dismissAfter}
/>
);

Expand All @@ -78,11 +83,12 @@ describe('NotificationStack', () => {
it('should be a valid element', done => {
const component = (
<NotificationStack
notifications={[]}
notifications={[MOCK]}
onDismiss={MOCK.onClick}
/>
);

if (TestUtils.isElement(component)) done();
});

});

0 comments on commit acfb051

Please sign in to comment.