1
1
import React , { Children } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { TransitionGroup , CSSTransition } from 'react-transition-group' ;
4
- import classNames from 'classnames' ;
5
4
import * as Composite from '../Composite' ;
6
5
import CloseButton from '../CloseButton' ;
7
6
import TextLabel from './TextLabel' ;
8
7
import ActionButton from './ActionButton' ;
9
- import css from './Notification.scss ' ;
8
+ import styles from './Notification.st.css ' ;
10
9
import StatusComplete from 'wix-ui-icons-common/StatusComplete' ;
11
10
import StatusWarning from 'wix-ui-icons-common/StatusWarning' ;
12
11
import StatusAlert from 'wix-ui-icons-common/StatusAlert' ;
12
+ import { dataHooks } from './constants' ;
13
13
14
14
export const LOCAL_NOTIFICATION = 'local' ;
15
15
export const GLOBAL_NOTIFICATION = 'global' ;
16
16
export const STICKY_NOTIFICATION = 'sticky' ;
17
17
export const DEFAULT_AUTO_HIDE_TIMEOUT = 6000 ;
18
18
export const DEFAULT_TIMEOUT = DEFAULT_AUTO_HIDE_TIMEOUT ;
19
19
20
- export const notificationTypeToPosition = {
21
- [ LOCAL_NOTIFICATION ] : 'absolute' ,
22
- [ GLOBAL_NOTIFICATION ] : 'relative' ,
23
- [ STICKY_NOTIFICATION ] : 'fixed' ,
24
- } ;
25
-
26
20
const animationsTimeouts = {
27
21
enter : 500 ,
28
22
exit : 350 ,
29
23
} ;
30
24
31
25
const themeIcon = {
32
- error : < StatusAlert className = { css . iconStyling } /> ,
33
- success : < StatusComplete className = { css . iconStyling } /> ,
34
- warning : < StatusWarning className = { css . iconStyling } /> ,
26
+ error : < StatusAlert className = { styles . iconStyling } /> ,
27
+ success : < StatusComplete className = { styles . iconStyling } /> ,
28
+ warning : < StatusWarning className = { styles . iconStyling } /> ,
35
29
} ;
36
30
37
31
function FirstChild ( props ) {
@@ -69,26 +63,26 @@ class Notification extends React.PureComponent {
69
63
hideByTimer : false ,
70
64
} ;
71
65
72
- this . startCloseTimer ( props ) ;
66
+ this . _startCloseTimer ( props ) ;
73
67
}
74
68
75
- startCloseTimer ( { autoHideTimeout } ) {
69
+ _startCloseTimer ( { autoHideTimeout } ) {
76
70
if ( autoHideTimeout ) {
77
71
this . closeTimeout = setTimeout (
78
- ( ) => this . hideNotificationOnTimeout ( ) ,
72
+ ( ) => this . _hideNotificationOnTimeout ( ) ,
79
73
autoHideTimeout || DEFAULT_AUTO_HIDE_TIMEOUT ,
80
74
) ;
81
75
}
82
76
}
83
77
84
- clearCloseTimeout ( ) {
78
+ _clearCloseTimeout ( ) {
85
79
if ( this . closeTimeout ) {
86
80
clearTimeout ( this . closeTimeout ) ;
87
81
this . closeTimeout = null ;
88
82
}
89
83
}
90
84
91
- hideNotificationOnCloseClick = ( ) => {
85
+ _hideNotificationOnCloseClick = ( ) => {
92
86
this . setState ( { hideByCloseClick : true } ) ;
93
87
94
88
setTimeout (
@@ -97,7 +91,7 @@ class Notification extends React.PureComponent {
97
91
) ;
98
92
} ;
99
93
100
- hideNotificationOnTimeout = ( ) => {
94
+ _hideNotificationOnTimeout = ( ) => {
101
95
this . setState ( { hideByTimer : true } ) ;
102
96
103
97
setTimeout (
@@ -106,7 +100,7 @@ class Notification extends React.PureComponent {
106
100
) ;
107
101
} ;
108
102
109
- bypassCloseFlags ( ) {
103
+ _bypassCloseFlags ( ) {
110
104
this . setState ( {
111
105
hideByCloseClick : false ,
112
106
hideByTimer : false ,
@@ -115,67 +109,63 @@ class Notification extends React.PureComponent {
115
109
116
110
UNSAFE_componentWillReceiveProps ( nextProps ) {
117
111
if ( nextProps . show ) {
118
- this . bypassCloseFlags ( ) ;
119
- this . clearCloseTimeout ( ) ;
120
- this . startCloseTimer ( nextProps ) ;
112
+ this . _bypassCloseFlags ( ) ;
113
+ this . _clearCloseTimeout ( ) ;
114
+ this . _startCloseTimer ( nextProps ) ;
121
115
}
122
116
}
123
117
124
118
componentWillUnmount ( ) {
125
- this . clearCloseTimeout ( ) ;
119
+ this . _clearCloseTimeout ( ) ;
126
120
}
127
121
128
- shouldShowNotification ( ) {
122
+ _shouldShowNotification ( ) {
129
123
return (
130
124
this . props . show && ! this . state . hideByCloseClick && ! this . state . hideByTimer
131
125
) ;
132
126
}
133
127
134
- renderNotification ( ) {
135
- const { zIndex, children, type , theme } = this . props ;
128
+ _renderNotification ( ) {
129
+ const { zIndex, children, theme } = this . props ;
136
130
const childrenComponents = mapChildren ( children ) ;
137
131
138
132
return (
139
133
< CSSTransition
140
134
classNames = { {
141
- enter : css . notificationAnimationEnter ,
142
- enterActive : css . notificationAnimationEnterActive ,
143
- exit : css . notificationAnimationExit ,
144
- exitActive : css . notificationAnimationExitActive ,
135
+ enter : styles . notificationAnimationEnter ,
136
+ enterActive : styles . notificationAnimationEnterActive ,
137
+ exit : styles . notificationAnimationExit ,
138
+ exitActive : styles . notificationAnimationExitActive ,
145
139
} }
146
140
timeout = { animationsTimeouts }
147
141
>
148
142
< div
149
- data-hook = "notification-wrapper"
143
+ data-hook = { dataHooks . notificationWrapper }
150
144
style = { { zIndex } }
151
- className = { classNames (
152
- css . notification ,
153
- css [ `${ theme } Theme` ] ,
154
- css [ `${ notificationTypeToPosition [ type ] } Position` ] ,
155
- ) }
145
+ className = { styles . notification }
156
146
role = "alert"
157
147
aria-labelledby = "notification-label"
158
148
aria-live = "polite"
159
149
>
160
150
{ themeIcon [ theme ] }
161
151
< div
162
152
id = "notification-label"
163
- className = { css . label }
153
+ className = { styles . label }
164
154
children = { childrenComponents . label }
165
155
/>
166
156
167
157
{ childrenComponents . ctaButton && (
168
158
< div
169
- className = { css . button }
159
+ className = { styles . button }
170
160
children = { childrenComponents . ctaButton }
171
161
/>
172
162
) }
173
163
174
164
{ childrenComponents . closeButton && (
175
165
< div
176
- data-hook = "notification-close-button"
177
- className = { css . closeButton }
178
- onClick = { this . hideNotificationOnCloseClick }
166
+ data-hook = { dataHooks . notificationCloseButton }
167
+ className = { styles . closeButton }
168
+ onClick = { this . _hideNotificationOnCloseClick }
179
169
children = { childrenComponents . closeButton }
180
170
/>
181
171
) }
@@ -185,11 +175,16 @@ class Notification extends React.PureComponent {
185
175
}
186
176
187
177
render ( ) {
188
- const { dataHook } = this . props ;
178
+ const { dataHook, theme , type } = this . props ;
189
179
return (
190
- < div data-hook = { dataHook } className = { css . root } >
180
+ < div
181
+ { ...styles ( 'root' , { theme, type } , this . props ) }
182
+ data-hook = { dataHook }
183
+ data-theme = { theme }
184
+ data-type = { type }
185
+ >
191
186
< TransitionGroup component = { FirstChild } >
192
- { this . shouldShowNotification ( ) ? this . renderNotification ( ) : null }
187
+ { this . _shouldShowNotification ( ) ? this . _renderNotification ( ) : null }
193
188
</ TransitionGroup >
194
189
</ div >
195
190
) ;
0 commit comments