forked from igorprado/react-notification-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationContainer.jsx
70 lines (62 loc) · 1.83 KB
/
NotificationContainer.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var React = require('react');
var PropTypes = require('prop-types');
var NotificationItem = require('./NotificationItem');
var Constants = require('./constants');
class NotificationContainer extends React.Component {
constructor(props) {
super(props);
// Fix position if width is overrided
this._style = props.getStyles.container(props.position);
if (
props.getStyles.overrideWidth &&
(props.position === Constants.positions.tc ||
props.position === Constants.positions.bc)
) {
this._style.marginLeft = -(props.getStyles.overrideWidth / 2);
}
}
render() {
var notifications;
if (
[
Constants.positions.bl,
Constants.positions.br,
Constants.positions.bc
].indexOf(this.props.position) > -1
) {
this.props.notifications.reverse();
}
notifications = this.props.notifications.map((notification) => {
return (
<NotificationItem
ref={ 'notification-' + notification.uid }
key={ notification.uid }
notification={ notification }
getStyles={ this.props.getStyles }
onRemove={ this.props.onRemove }
noAnimation={ this.props.noAnimation }
allowHTML={ this.props.allowHTML }
children={ this.props.children }
/>
);
});
return (
<div
className={ 'notifications-' + this.props.position }
style={ this._style }
>
{notifications}
</div>
);
}
}
NotificationContainer.propTypes = {
position: PropTypes.string.isRequired,
notifications: PropTypes.array.isRequired,
getStyles: PropTypes.object,
onRemove: PropTypes.func,
noAnimation: PropTypes.bool,
allowHTML: PropTypes.bool,
children: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
};
module.exports = NotificationContainer;