From bb02b09e6eb0e0b3f70280fe47a3df3a4b69a8c7 Mon Sep 17 00:00:00 2001 From: Aliullov Vlad Date: Wed, 29 Nov 2023 01:15:33 +0400 Subject: [PATCH] fix tooltip in overlay block --- .../preview/overlays/overlays.component.css | 5 + .../preview/overlays/overlays.component.html | 93 ++++++++++--------- .../preview/overlays/overlays.component.ts | 31 ++++++- 3 files changed, 82 insertions(+), 47 deletions(-) diff --git a/src/app/preview/overlays/overlays.component.css b/src/app/preview/overlays/overlays.component.css index ac94bd40..8066aad1 100644 --- a/src/app/preview/overlays/overlays.component.css +++ b/src/app/preview/overlays/overlays.component.css @@ -29,7 +29,12 @@ width: 240px; } +:host-context(.dx-theme-fluent-typography) #loadpanel-block { + width: 140px; +} + #tooltip-block { + height: auto; width: 140px; } diff --git a/src/app/preview/overlays/overlays.component.html b/src/app/preview/overlays/overlays.component.html index 2e7658c9..d908182b 100644 --- a/src/app/preview/overlays/overlays.component.html +++ b/src/app/preview/overlays/overlays.component.html @@ -7,23 +7,24 @@
-
-
+
+
 
- - -

Tooltip

+ [animation]="null" + [visible]="true" + [hideOnParentScroll]="false" + [position]="{at: 'right', my: 'right'}" + [hideOnOutsideClick]="false"> +
Tooltip
- - - + + - +
Tooltip content
- - - - diff --git a/src/app/preview/overlays/overlays.component.ts b/src/app/preview/overlays/overlays.component.ts index c2bee0ff..119c1951 100644 --- a/src/app/preview/overlays/overlays.component.ts +++ b/src/app/preview/overlays/overlays.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { Component, OnDestroy, OnInit, ViewChild, ElementRef } from '@angular/core'; import { DxLoadPanelComponent, DxToastComponent, DxTooltipComponent } from 'devextreme-angular'; import { BehaviorSubject, Subscription } from 'rxjs'; @@ -9,7 +9,10 @@ import { BehaviorSubject, Subscription } from 'rxjs'; }) export class OverlaysComponent implements OnInit, OnDestroy { subscription: Subscription; + updateTooltipVisibilityInterval = -1; + @ViewChild('tooltipPreview') tooltipPreview: DxTooltipComponent; + @ViewChild('tooltipPreviewBlock') tooltipPreviewBlock: ElementRef; @ViewChild('tooltip') tooltip: DxTooltipComponent; @ViewChild('toast') toast: DxToastComponent; @ViewChild('loadPanel') loadPanel: DxLoadPanelComponent; @@ -36,10 +39,35 @@ export class OverlaysComponent implements OnInit, OnDestroy { e.cancel = true; } + isElementInViewport(el) { + var 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.updateTooltipVisibilityInterval = setInterval(() => { + this.updateVisibilityPreviewTooltip(); + }, 50); + 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(); @@ -50,5 +78,6 @@ export class OverlaysComponent implements OnInit, OnDestroy { ngOnDestroy(): void { this.subscription.unsubscribe(); + clearInterval(this.updateTooltipVisibilityInterval); } }