Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 42 additions & 50 deletions src/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,51 @@ import { CSSTransitionGroup } from 'react-transition-group';
import classnames from 'classnames';
import Notification from './Notification';

class Notifications extends React.Component {
static propTypes = {
notifications: PropTypes.array.isRequired,
onRequestHide: PropTypes.func,
enterTimeout: PropTypes.number,
leaveTimeout: PropTypes.number
const Notifications = ({
notifications = [],
onRequestHide = () => { },
enterTimeout = 400,
leaveTimeout = 400
}) => {
const handleRequestHide = notification => () => {
if (onRequestHide) onRequestHide(notification);
};

static defaultProps = {
notifications: [],
onRequestHide: () => {
},
enterTimeout: 400,
leaveTimeout: 400
};

handleRequestHide = notification => () => {
const { onRequestHide } = this.props;
if (onRequestHide) {
onRequestHide(notification);
}
};
const className = classnames('notification-container', {
'notification-container-empty': notifications.length === 0
});

render() {
const { notifications, enterTimeout, leaveTimeout } = this.props;
const className = classnames('notification-container', {
'notification-container-empty': notifications.length === 0
});
return (
<div className={className}>
<CSSTransitionGroup
transitionName="notification"
transitionEnterTimeout={enterTimeout}
transitionLeaveTimeout={leaveTimeout}
>
{notifications.map((notification) => {
const key = notification.id || new Date().getTime();
return (
<Notification
key={key}
type={notification.type}
title={notification.title}
message={notification.message}
timeOut={notification.timeOut}
onClick={notification.onClick}
onRequestHide={this.handleRequestHide(notification)}
/>
);
})}
</CSSTransitionGroup>
</div>
);
}
return (
<div className={className}>
<CSSTransitionGroup
transitionName="notification"
transitionEnterTimeout={enterTimeout}
transitionLeaveTimeout={leaveTimeout}
>
{notifications.map((notification) => {
const key = notification.id || new Date().getTime();
return (
<Notification
key={key}
type={notification.type}
title={notification.title}
message={notification.message}
timeOut={notification.timeOut}
onClick={notification.onClick}
onRequestHide={handleRequestHide(notification)}
/>
);
})}
</CSSTransitionGroup>
</div>
);
}

Notifications.propTypes = {
notifications: PropTypes.array.isRequired,
onRequestHide: PropTypes.func,
enterTimeout: PropTypes.number,
leaveTimeout: PropTypes.number
};

export default Notifications;