Skip to content

Commit 04b0de2

Browse files
authored
fix: popover positioning (#1378)
* fix: reset css * fix: popover positioning when the window of the Agent small * fix: optimise split mode offset
1 parent cf00e36 commit 04b0de2

7 files changed

+119
-123
lines changed

packages/uhk-web/src/app/components/popover/popover.component.html

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<div class="popover"
2-
#popover
3-
[@popover]="{ value: animationState, params: { animationTime: animationTime } }"
42
[ngClass]="{'leftArrow': leftArrow, 'rightArrow': rightArrow}"
5-
[style.top.px]="topPosition"
6-
[style.left.px]="leftPosition"
73
>
84
<div class="arrowCustom"></div>
95
<div class="popover-title menu-tabs">
@@ -13,7 +9,7 @@
139
[class.active]="activeTab === tab.tabName"
1410
[class.disabled]="tab.disabled"
1511
(click)="selectTab(tab)">
16-
<a class="nav-link menu-tabs--item"
12+
<a class="nav-link menu-tabs--item"
1713
[class.active]="activeTab === tab.tabName"
1814
[class.disabled]="tab.disabled">
1915
<fa-icon [icon]="tab.icon"></fa-icon>
@@ -64,7 +60,7 @@
6460
<div class="form-check mr-2">
6561
<input type="checkbox" class="form-check-input"
6662
id="remapOnAllKeymap"
67-
name="remapOnAllKeymap"
63+
name="remapOnAllKeymap"
6864
[(ngModel)]="remapInfo.remapOnAllKeymap">
6965
<label class="form-check-label" for="remapOnAllKeymap">Remap on all keymaps</label>
7066
</div>
@@ -105,4 +101,3 @@
105101
</div>
106102
</div>
107103
</div>
108-
<div class="popover-overlay" [class.display]="visible" (click)="onOverlay()"></div>

packages/uhk-web/src/app/components/popover/popover.component.scss

-17
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,6 @@
128128
padding-right: 10px;
129129
}
130130

131-
.popover-overlay {
132-
position: fixed;
133-
width: 100%;
134-
height: 0;
135-
top: 0;
136-
left: 0;
137-
z-index: 1050;
138-
background: rgba(0, 0, 0, 0);
139-
transition: background 200ms ease-out, height 0ms 200ms linear;
140-
141-
&.display {
142-
height: 100%;
143-
background: rgba(0, 0, 0, 0.2);
144-
transition: background 200ms ease-out;
145-
}
146-
}
147-
148131
.popover-action-form {
149132
margin-top: 4px;
150133

packages/uhk-web/src/app/components/popover/popover.component.ts

+3-79
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
ChangeDetectionStrategy,
33
ChangeDetectorRef,
44
Component,
5-
ElementRef,
65
EventEmitter,
76
HostListener,
87
Input,
@@ -11,7 +10,6 @@ import {
1110
SimpleChanges,
1211
ViewChild
1312
} from '@angular/core';
14-
import { animate, keyframes, state, style, transition, trigger } from '@angular/animations';
1513
import { IconDefinition } from '@fortawesome/fontawesome-common-types';
1614
import { faBan, faClone, faKeyboard, faMousePointer, faPlay } from '@fortawesome/free-solid-svg-icons';
1715

@@ -57,64 +55,28 @@ export interface TabHeader {
5755
selector: 'popover',
5856
templateUrl: './popover.component.html',
5957
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
9059
})
9160
export class PopoverComponent implements OnChanges {
92-
@Input() animationEnabled: boolean;
9361
@Input() defaultKeyAction: KeyAction;
9462
@Input() currentKeymap: Keymap;
9563
@Input() currentLayer: number;
96-
@Input() keyPosition: any;
97-
@Input() wrapPosition: any;
9864
@Input() visible: boolean;
9965
@Input() allowLayerDoubleTap: boolean;
10066
@Input() remapInfo: RemapInfo;
67+
@Input() leftArrow: boolean = false;
68+
@Input() rightArrow: boolean = false;
10169

10270
@Output() cancel = new EventEmitter<any>();
10371
@Output() remap = new EventEmitter<KeyActionRemap>();
10472

10573
@ViewChild('tab', { static: false }) selectedTab: Tab;
106-
@ViewChild('popover', { static: false }) popoverHost: ElementRef;
10774

10875
tabName = TabName;
10976
keyActionValid: boolean;
11077
activeTab: TabName;
11178
keymaps$: Observable<Keymap[]>;
11279
keymapOptions$: Observable<SelectOptionData[]>;
113-
leftArrow: boolean = false;
114-
rightArrow: boolean = false;
115-
topPosition: number = 0;
116-
leftPosition: number = 0;
117-
animationState: string;
11880
shadowKeyAction: KeyAction;
11981
disableRemapOnAllLayer = false;
12082
tabHeaders: TabHeader[] = [
@@ -154,7 +116,6 @@ export class PopoverComponent implements OnChanges {
154116

155117
constructor(private store: Store<AppState>,
156118
private cdRef: ChangeDetectorRef) {
157-
this.animationState = 'closed';
158119
this.keymaps$ = store.select(getKeymaps);
159120
this.keymapOptions$ = store.select(getKeymapOptions);
160121
this.macroPlaybackSupported$ = store.select(macroPlaybackSupported);
@@ -164,10 +125,6 @@ export class PopoverComponent implements OnChanges {
164125
ngOnChanges(change: SimpleChanges) {
165126
let tab: TabHeader = this.tabHeaders[5];
166127

167-
if (this.keyPosition && this.wrapPosition && (change['keyPosition'] || change['wrapPosition'])) {
168-
this.calculatePosition();
169-
}
170-
171128
if (change['defaultKeyAction']) {
172129
this.disableRemapOnAllLayer = false;
173130

@@ -195,19 +152,11 @@ export class PopoverComponent implements OnChanges {
195152

196153
if (change['visible']) {
197154
if (change['visible'].currentValue) {
198-
this.animationState = 'opened';
199-
200155
this.selectTab(tab);
201-
} else {
202-
this.animationState = 'closed';
203156
}
204157
}
205158
}
206159

207-
get animationTime(): string {
208-
return this.animationEnabled ? '200ms' : '0ms';
209-
}
210-
211160
onCancelClick(): void {
212161
this.cancel.emit(undefined);
213162
}
@@ -251,10 +200,6 @@ export class PopoverComponent implements OnChanges {
251200
}
252201
}
253202

254-
onOverlay() {
255-
this.cancel.emit(undefined);
256-
}
257-
258203
remapInfoChange(): void {
259204
this.selectedTab.remapInfoChanged(this.remapInfo);
260205
}
@@ -287,25 +232,4 @@ export class PopoverComponent implements OnChanges {
287232
trackTabHeader(index: number, tabItem: TabHeader): string {
288233
return tabItem.tabName.toString();
289234
}
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-
}
311235
}

packages/uhk-web/src/app/components/svg/keyboard/svg-keyboard.component.scss

-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ editable-text {
1313
padding-left: 2em;
1414
padding-right: 2em;
1515
display: block;
16-
position: relative;
1716
z-index: 51;
1817
}

packages/uhk-web/src/app/components/svg/wrap/svg-keyboard-wrap.component.html

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ng-template [ngIf]="layers">
2-
<layers [class.disabled]="popoverShown" (select)="selectLayer($event.index)" [current]="currentLayer"></layers>
2+
<layers [class.disabled]="animationState === 'opened'" (select)="selectLayer($event.index)" [current]="currentLayer"></layers>
33
<keyboard-slider id="keyboard-slider"
44
[animationEnabled]="animationEnabled"
55
[layers]="layers"
@@ -17,10 +17,12 @@
1717
></keyboard-slider>
1818

1919
<popover tabindex="0"
20-
[animationEnabled]="animationEnabled"
21-
[visible]="popoverShown"
22-
[keyPosition]="keyPosition"
23-
[wrapPosition]="wrapPosition"
20+
[@popover]="{ value: animationState, params: { animationTime: animationTime } }"
21+
[visible]="animationState === 'opened'"
22+
[style.top.px]="topPosition"
23+
[style.left.px]="leftPosition"
24+
[leftArrow]="leftArrow"
25+
[rightArrow]="rightArrow"
2426
[defaultKeyAction]="popoverInitKeyAction"
2527
[currentKeymap]="keymap"
2628
[currentLayer]="currentLayer"
@@ -41,4 +43,5 @@
4143
</p>
4244
</div>
4345
</div>
46+
<div class="popover-overlay" [class.display]="animationState === 'opened'" (click)="hidePopover()"></div>
4447
</ng-template>

packages/uhk-web/src/app/components/svg/wrap/svg-keyboard-wrap.component.scss

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
:host {
22
width: 100%;
3+
height: 100%;
34
display: block;
4-
5-
&.space {
6-
margin-bottom: 405px;
7-
}
85
}
96

107
keyboard-slider {
@@ -14,6 +11,30 @@ keyboard-slider {
1411
margin-top: 30px;
1512
}
1613

14+
popover {
15+
display: inline-block;
16+
width: 600px;
17+
position: absolute;
18+
z-index: 1051;
19+
}
20+
21+
.popover-overlay {
22+
position: fixed;
23+
width: 100%;
24+
height: 0;
25+
top: 0;
26+
left: 0;
27+
z-index: 1050;
28+
background: rgba(0, 0, 0, 0);
29+
transition: background 200ms ease-out, height 0ms 200ms linear;
30+
31+
&.display {
32+
height: 100%;
33+
background: rgba(0, 0, 0, 0.2);
34+
transition: background 200ms ease-out;
35+
}
36+
}
37+
1738
.tooltip {
1839
position: fixed;
1940
transform: translate(-50%, -6px);

0 commit comments

Comments
 (0)