Skip to content

Commit

Permalink
fix tooltip in overlay block
Browse files Browse the repository at this point in the history
+ alignment
  • Loading branch information
GoodDayForSurf committed Dec 7, 2023
1 parent 1685914 commit 7f95425
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
8 changes: 8 additions & 0 deletions src/app/preview/overlays/overlays.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
width: 250px;
}

#tooltip-block {
position: relative;
}

#tooltip-block::ng-deep .dx-tooltip-wrapper {
position: initial !important;
}

#loadpanel-block {
width: 240px;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/preview/overlays/overlays.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div id="toast-block">
<div id="toast-target"></div>
</div>
<div id="tooltip-block" #tooltipPreviewBlock>
<div id="tooltip-block">
<div id="tooltip-preview-target">&nbsp;</div>
</div>
</div>
Expand Down
31 changes: 0 additions & 31 deletions src/app/preview/overlays/overlays.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ import { Component, OnDestroy, OnInit, ViewChild, ElementRef } from '@angular/co
import { DxLoadPanelComponent, DxToastComponent, DxTooltipComponent } from 'devextreme-angular';
import { BehaviorSubject, Subscription } from 'rxjs';

const UPDATE_TOOLTIP_VISIBILITY_INTERVAL = 50;

@Component({
selector: 'app-overlays',
templateUrl: './overlays.component.html',
styleUrls: ['./overlays.component.css']
})
export class OverlaysComponent implements OnInit, OnDestroy {
subscription: Subscription;
updateTooltipVisibilityIntervalHandler: number;

@ViewChild('tooltipPreview') tooltipPreview: DxTooltipComponent;
@ViewChild('tooltipPreviewBlock') tooltipPreviewBlock: ElementRef;
@ViewChild('tooltip') tooltip: DxTooltipComponent;
@ViewChild('toast') toast: DxToastComponent;
@ViewChild('loadPanel') loadPanel: DxLoadPanelComponent;
Expand All @@ -39,35 +34,10 @@ export class OverlaysComponent implements OnInit, OnDestroy {
e.cancel = true;
}

isElementInViewport(el) {
const rect = el.getBoundingClientRect();

return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}

updateVisibilityPreviewTooltip(): void {
const isElementInViewport = this.isElementInViewport(this.tooltipPreviewBlock?.nativeElement);
this.tooltipPreview.visible = isElementInViewport;

if(isElementInViewport) {
this.tooltipPreview.instance.repaint();
}
}

ngOnInit(): void {
this.updateTooltipVisibilityIntervalHandler = setInterval(() => {
this.updateVisibilityPreviewTooltip();
}, UPDATE_TOOLTIP_VISIBILITY_INTERVAL);

this.subscription = this.isExpanded.subscribe((value) => {
const flexContainer = document.getElementsByTagName('app-overlays')[0].parentElement.parentElement;
flexContainer.addEventListener('transitionend', () => {
if(this.tooltipPreview) this.tooltipPreview.instance.repaint();
if(this.tooltip) this.tooltip.instance.repaint();
if(this.toast) this.toast.instance.repaint();
if(this.loadPanel) this.loadPanel.instance.repaint();
Expand All @@ -78,6 +48,5 @@ export class OverlaysComponent implements OnInit, OnDestroy {

ngOnDestroy(): void {
this.subscription.unsubscribe();
clearInterval(this.updateTooltipVisibilityIntervalHandler);
}
}

0 comments on commit 7f95425

Please sign in to comment.