-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathNotificationBar.jsx
55 lines (49 loc) · 1.71 KB
/
NotificationBar.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
import React from 'react';
import Container from '../Container/Container';
import testLocalStorage from '../../utilities/test-local-storage';
const version = '1';
const localStorageIsEnabled = testLocalStorage() !== false;
export default class NotificationBar extends React.Component {
render() {
let dismissedMod = this._dismissed ? 'notification-bar--dismissed' : '';
return (
<div className={ `notification-bar ${dismissedMod}` }>
<Container className="notification-bar__inner">
<p>
Sponsor webpack and get apparel at the same time! Visit <a href="https://webpack.threadless.com">the official webpack shop!</a> All proceeds go to webpack's <a href="https://opencollective.com/webpack">Open Collective page!</a>
</p>
<p>
Buy the brand-new webpack stickers at <a href="http://www.unixstickers.com/tag/webpack">Unixstickers!</a>
{localStorageIsEnabled ?
<button
className="notification-bar__close icon-cross"
onClick={ this._close.bind(this) } /> :
null
}
</p>
</Container>
</div>
);
}
/**
* Update the notification-dismissed state
*
* @param {object} e - Click event
*/
_close(e) {
if (localStorageIsEnabled) {
localStorage.setItem('notification-dismissed', version);
}
this.forceUpdate();
}
/**
* Determine whether or not the current message was dismissed
*
* @return {boolean} - Whether or not the current message was dismissed
*/
get _dismissed() {
if (localStorageIsEnabled) {
return localStorage.getItem('notification-dismissed') === version;
} else return false;
}
}