-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifications.js
More file actions
76 lines (59 loc) · 1.89 KB
/
Notifications.js
File metadata and controls
76 lines (59 loc) · 1.89 KB
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
71
72
73
74
75
import React from 'react';
import ReactDOM from 'react-dom';
import "./style.scss"
const styles = {
container: {
position: "absolute",
top: "0px",
left: window.innerWidth/2 - 500/2 + "px",
width: "500px",
height: "60px",
backgroundColor: "#ff7600fa",
borderRadius: "10px",
display: "table",
textAlign: "center"
},
textStyle: {
color: "white",
display: "table-cell",
verticalAlign: "middle"
}
}
export const showNotification = (data) => {
let el = document.querySelector("#notificationsBar");
el.dispatchEvent(new CustomEvent('showNotification', { detail: data}));
}
export default class Notifications extends React.Component {
constructor(props){
super(props)
this._handleShowNotificationEvent = this._handleShowNotificationEvent.bind(this)
this.onNotificationsClick = this.onNotificationsClick.bind(this)
this.state = {
text: null,
shown: false
}
}
_handleShowNotificationEvent = (event) => {
this.setState({
text: event.detail.text,
shown: !this.state.shown
})
};
onNotificationsClick(){
this.setState({shown: !this.state.shown})
}
componentDidMount(){
ReactDOM.findDOMNode(this).addEventListener('showNotification', this._handleShowNotificationEvent);
}
componentWillUnmount(){
ReactDOM.findDOMNode(this).removeEventListener('showNotification', this._handleShowNotificationEvent);
}
render(){
let notificationsActiveClass = this.state.shown && this.state.text ? "active" : null;
return (
<div id="notificationsBar" onClick={this.onNotificationsClick} className={notificationsActiveClass}>
<span style={styles.textStyle}>{this.state.text}</span>
</div>
)
}
}