-
Notifications
You must be signed in to change notification settings - Fork 295
/
Notification.tsx
103 lines (91 loc) · 2.57 KB
/
Notification.tsx
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// @flow
import React, { Component, Fragment } from 'react';
import type { Node } from 'react';
import SVGInline from 'react-svg-inline';
import classNames from 'classnames';
import styles from './Notification.scss';
import closeCross from '../../assets/images/close-cross.inline.svg';
import NotificationActions from './NotificationActions';
import type { NotificationActionItems } from './NotificationActions';
export type NotificationDataProps = {
icon?: string,
clickToClose?: boolean,
hasCloseButton?: boolean,
hasEllipsis?: boolean,
themeOverride?: 'grey', // if left empty, the notification will have its normal colors
labelValues?: Object,
hasSpinner?: boolean,
actions?: NotificationActionItems,
};
type Props = {
...$Exact<NotificationDataProps>,
children?: Node,
onClose?: Function,
isVisible: boolean,
index?: number,
};
export default class Notification extends Component<Props> {
static defaultProps = {
clickToClose: true,
hasCloseButton: true,
hasEllipsis: false,
hasSpinner: false,
};
render() {
const {
actions,
children,
clickToClose,
hasCloseButton,
hasEllipsis,
hasSpinner,
icon,
index,
isVisible,
onClose,
themeOverride,
} = this.props;
const isClickToClose = clickToClose && !actions;
const notificationMessageStyles = classNames([
styles.component,
isVisible ? styles.isVisible : null,
isClickToClose ? styles.clickToClose : null,
themeOverride ? styles[`theme-override-${themeOverride}`] : null,
]);
const messageStyles = classNames([
styles.message,
hasEllipsis ? styles.hasEllipsis : null,
]);
const iconStyles = classNames([
styles.icon,
hasSpinner ? styles.spinnerIcon : null,
]);
return (
<div
className={notificationMessageStyles}
onClick={() => isClickToClose && onClose && onClose()}
role="link"
aria-hidden
style={{
zIndex: 9999999 + (index || 0),
}}
>
{isVisible && (
<Fragment>
{icon && <SVGInline svg={icon} className={iconStyles} />}
<div className={messageStyles}>{children}</div>
{!!actions && <NotificationActions actions={actions} />}
{hasCloseButton && (
<button
className={styles.closeButton}
onClick={() => onClose && onClose()}
>
<SVGInline svg={closeCross} />
</button>
)}
</Fragment>
)}
</div>
);
}
}