@@ -21,8 +21,9 @@ export type SnackBarButtonAttrs = {
21
21
type SnackBarAttrs = {
22
22
message : MaybeTranslation
23
23
button : ButtonAttrs | null
24
+ onHoverChange : ( hovered : boolean ) => void
24
25
}
25
- type QueueItem = SnackBarAttrs & {
26
+ type QueueItem = Omit < SnackBarAttrs , "onHoverChange" > & {
26
27
onClose : ( ( timedOut : boolean ) => unknown ) | null
27
28
onShow : ( ( ) => unknown ) | null
28
29
doCancel : { cancel : ( ) => unknown }
@@ -36,10 +37,21 @@ let cancelCurrentSnackbar: (() => unknown) | null = null
36
37
class SnackBar implements Component < SnackBarAttrs > {
37
38
view ( vnode : Vnode < SnackBarAttrs > ) {
38
39
// use same padding as MinimizedEditor
39
- return m ( ".snackbar-content.flex.flex-space-between.border-radius.plr.pb-xs.pt-xs" , [
40
- m ( ".flex.center-vertically.smaller" , lang . getTranslationText ( vnode . attrs . message ) ) ,
41
- vnode . attrs . button ? m ( ".flex-end.center-vertically.pl" , m ( Button , vnode . attrs . button ) ) : null ,
42
- ] )
40
+ return m (
41
+ ".snackbar-content.flex.flex-space-between.border-radius.plr.pb-xs.pt-xs" ,
42
+ {
43
+ onmouseenter : ( ) => {
44
+ vnode . attrs . onHoverChange ( true )
45
+ } ,
46
+ onmouseleave : ( ) => {
47
+ vnode . attrs . onHoverChange ( false )
48
+ } ,
49
+ } ,
50
+ [
51
+ m ( ".flex.center-vertically.smaller" , lang . getTranslationText ( vnode . attrs . message ) ) ,
52
+ vnode . attrs . button ? m ( ".flex-end.center-vertically.pl" , m ( Button , vnode . attrs . button ) ) : null ,
53
+ ] ,
54
+ )
43
55
}
44
56
}
45
57
@@ -147,13 +159,18 @@ function showNextNotification() {
147
159
const { message, button, onClose, onShow, doCancel, showingTime } = notificationQueue [ 0 ] //we shift later because it is still shown
148
160
clearTimeout ( currentAnimationTimeout )
149
161
currentAnimationTimeout = null
162
+ let hovered = false
163
+
150
164
const closeFunction = displayOverlay (
151
165
( ) => getSnackBarPosition ( ) ,
152
166
{
153
167
view : ( ) =>
154
168
m ( SnackBar , {
155
169
message,
156
170
button,
171
+ onHoverChange : ( isHovered ) => {
172
+ hovered = isHovered
173
+ } ,
157
174
} ) ,
158
175
} ,
159
176
"slide-bottom" ,
@@ -164,6 +181,11 @@ function showNextNotification() {
164
181
let closed = false
165
182
166
183
const closeAndOpenNext = ( timedOut : boolean ) => {
184
+ if ( timedOut && hovered ) {
185
+ debounce ( 1000 , closeAndOpenNext ) ( true )
186
+ return
187
+ }
188
+
167
189
closed = true
168
190
cancelCurrentSnackbar = null
169
191
0 commit comments