2
2
ChangeDetectionStrategy ,
3
3
ChangeDetectorRef ,
4
4
Component ,
5
- ElementRef ,
6
5
EventEmitter ,
7
6
HostListener ,
8
7
Input ,
@@ -11,7 +10,6 @@ import {
11
10
SimpleChanges ,
12
11
ViewChild
13
12
} from '@angular/core' ;
14
- import { animate , keyframes , state , style , transition , trigger } from '@angular/animations' ;
15
13
import { IconDefinition } from '@fortawesome/fontawesome-common-types' ;
16
14
import { faBan , faClone , faKeyboard , faMousePointer , faPlay } from '@fortawesome/free-solid-svg-icons' ;
17
15
@@ -57,64 +55,28 @@ export interface TabHeader {
57
55
selector : 'popover' ,
58
56
templateUrl : './popover.component.html' ,
59
57
styleUrls : [ './popover.component.scss' ] ,
60
- changeDetection : ChangeDetectionStrategy . OnPush ,
61
- animations : [
62
- trigger ( 'popover' , [
63
- state ( 'closed' , style ( {
64
- transform : 'translateY(30px)' ,
65
- visibility : 'hidden' ,
66
- opacity : 0
67
- } ) ) ,
68
- state ( 'opened' , style ( {
69
- transform : 'translateY(0)' ,
70
- visibility : 'visible' ,
71
- opacity : 1
72
- } ) ) ,
73
- transition ( 'opened => closed' , [
74
- animate ( '{{animationTime}} ease-out' , keyframes ( [
75
- style ( { transform : 'translateY(0)' , visibility : 'visible' , opacity : 1 , offset : 0 } ) ,
76
- style ( { transform : 'translateY(30px)' , visibility : 'hidden' , opacity : 0 , offset : 1 } )
77
- ] ) )
78
- ] , { params : { animationTime : '200ms' } } ) ,
79
- transition ( 'closed => opened' , [
80
- style ( {
81
- visibility : 'visible'
82
- } ) ,
83
- animate ( '{{animationTime}} ease-out' , keyframes ( [
84
- style ( { transform : 'translateY(30px)' , opacity : 0 , offset : 0 } ) ,
85
- style ( { transform : 'translateY(0)' , opacity : 1 , offset : 1 } )
86
- ] ) )
87
- ] , { params : { animationTime : '200ms' } } )
88
- ] )
89
- ]
58
+ changeDetection : ChangeDetectionStrategy . OnPush
90
59
} )
91
60
export class PopoverComponent implements OnChanges {
92
- @Input ( ) animationEnabled : boolean ;
93
61
@Input ( ) defaultKeyAction : KeyAction ;
94
62
@Input ( ) currentKeymap : Keymap ;
95
63
@Input ( ) currentLayer : number ;
96
- @Input ( ) keyPosition : any ;
97
- @Input ( ) wrapPosition : any ;
98
64
@Input ( ) visible : boolean ;
99
65
@Input ( ) allowLayerDoubleTap : boolean ;
100
66
@Input ( ) remapInfo : RemapInfo ;
67
+ @Input ( ) leftArrow : boolean = false ;
68
+ @Input ( ) rightArrow : boolean = false ;
101
69
102
70
@Output ( ) cancel = new EventEmitter < any > ( ) ;
103
71
@Output ( ) remap = new EventEmitter < KeyActionRemap > ( ) ;
104
72
105
73
@ViewChild ( 'tab' , { static : false } ) selectedTab : Tab ;
106
- @ViewChild ( 'popover' , { static : false } ) popoverHost : ElementRef ;
107
74
108
75
tabName = TabName ;
109
76
keyActionValid : boolean ;
110
77
activeTab : TabName ;
111
78
keymaps$ : Observable < Keymap [ ] > ;
112
79
keymapOptions$ : Observable < SelectOptionData [ ] > ;
113
- leftArrow : boolean = false ;
114
- rightArrow : boolean = false ;
115
- topPosition : number = 0 ;
116
- leftPosition : number = 0 ;
117
- animationState : string ;
118
80
shadowKeyAction : KeyAction ;
119
81
disableRemapOnAllLayer = false ;
120
82
tabHeaders : TabHeader [ ] = [
@@ -154,7 +116,6 @@ export class PopoverComponent implements OnChanges {
154
116
155
117
constructor ( private store : Store < AppState > ,
156
118
private cdRef : ChangeDetectorRef ) {
157
- this . animationState = 'closed' ;
158
119
this . keymaps$ = store . select ( getKeymaps ) ;
159
120
this . keymapOptions$ = store . select ( getKeymapOptions ) ;
160
121
this . macroPlaybackSupported$ = store . select ( macroPlaybackSupported ) ;
@@ -164,10 +125,6 @@ export class PopoverComponent implements OnChanges {
164
125
ngOnChanges ( change : SimpleChanges ) {
165
126
let tab : TabHeader = this . tabHeaders [ 5 ] ;
166
127
167
- if ( this . keyPosition && this . wrapPosition && ( change [ 'keyPosition' ] || change [ 'wrapPosition' ] ) ) {
168
- this . calculatePosition ( ) ;
169
- }
170
-
171
128
if ( change [ 'defaultKeyAction' ] ) {
172
129
this . disableRemapOnAllLayer = false ;
173
130
@@ -195,19 +152,11 @@ export class PopoverComponent implements OnChanges {
195
152
196
153
if ( change [ 'visible' ] ) {
197
154
if ( change [ 'visible' ] . currentValue ) {
198
- this . animationState = 'opened' ;
199
-
200
155
this . selectTab ( tab ) ;
201
- } else {
202
- this . animationState = 'closed' ;
203
156
}
204
157
}
205
158
}
206
159
207
- get animationTime ( ) : string {
208
- return this . animationEnabled ? '200ms' : '0ms' ;
209
- }
210
-
211
160
onCancelClick ( ) : void {
212
161
this . cancel . emit ( undefined ) ;
213
162
}
@@ -251,10 +200,6 @@ export class PopoverComponent implements OnChanges {
251
200
}
252
201
}
253
202
254
- onOverlay ( ) {
255
- this . cancel . emit ( undefined ) ;
256
- }
257
-
258
203
remapInfoChange ( ) : void {
259
204
this . selectedTab . remapInfoChanged ( this . remapInfo ) ;
260
205
}
@@ -287,25 +232,4 @@ export class PopoverComponent implements OnChanges {
287
232
trackTabHeader ( index : number , tabItem : TabHeader ) : string {
288
233
return tabItem . tabName . toString ( ) ;
289
234
}
290
-
291
- private calculatePosition ( ) {
292
- const offsetLeft : number = this . wrapPosition . left + 265 ; // 265 is a width of the side menu with a margin
293
- const popover : HTMLElement = this . popoverHost . nativeElement ;
294
- let newLeft : number = this . keyPosition . left + ( this . keyPosition . width / 2 ) ;
295
-
296
- this . leftArrow = newLeft < offsetLeft ;
297
- this . rightArrow = ( newLeft + popover . offsetWidth ) > offsetLeft + this . wrapPosition . width ;
298
-
299
- if ( this . leftArrow ) {
300
- newLeft = this . keyPosition . left ;
301
- } else if ( this . rightArrow ) {
302
- newLeft = this . keyPosition . left - popover . offsetWidth + this . keyPosition . width ;
303
- } else {
304
- newLeft -= popover . offsetWidth / 2 ;
305
- }
306
-
307
- // 7 is a space between a bottom key position and a popover
308
- this . topPosition = this . keyPosition . top + this . keyPosition . height + 7 + window . scrollY ;
309
- this . leftPosition = newLeft ;
310
- }
311
235
}
0 commit comments