11import { DOMObserver } from '@untemps/dom-observer'
22
33class Tooltip {
4- static get GAP ( ) {
5- return 10
6- }
7-
84 static #instances = [ ]
95
106 #observer = null
@@ -28,6 +24,7 @@ class Tooltip {
2824 #animated = false
2925 #animationEnterClassName = null
3026 #animationLeaveClassName = null
27+ #offset = 10
3128
3229 static destroy ( ) {
3330 Tooltip . #instances. forEach ( ( instance ) => {
@@ -49,6 +46,7 @@ class Tooltip {
4946 animationLeaveClassName ,
5047 enterDelay ,
5148 leaveDelay ,
49+ offset ,
5250 disabled
5351 ) {
5452 this . #target = target
@@ -63,6 +61,7 @@ class Tooltip {
6361 this . #animationLeaveClassName = animationLeaveClassName || '__tooltip-leave'
6462 this . #enterDelay = enterDelay || 0
6563 this . #leaveDelay = leaveDelay || 0
64+ this . #offset = Math . max ( offset || 10 , 5 )
6665
6766 this . #observer = new DOMObserver ( )
6867
@@ -89,6 +88,7 @@ class Tooltip {
8988 animationLeaveClassName ,
9089 enterDelay ,
9190 leaveDelay ,
91+ offset ,
9292 disabled
9393 ) {
9494 const hasContentChanged = contentSelector !== this . #contentSelector || content !== this . #content
@@ -108,6 +108,7 @@ class Tooltip {
108108 this . #animationLeaveClassName = animationLeaveClassName || '__tooltip-leave'
109109 this . #enterDelay = enterDelay || 0
110110 this . #leaveDelay = leaveDelay || 0
111+ this . #offset = Math . max ( offset || 10 , 5 )
111112
112113 if ( hasContentChanged ) {
113114 this . #removeTooltipFromTarget( )
@@ -174,28 +175,28 @@ class Tooltip {
174175 switch ( this . #position) {
175176 case 'left' : {
176177 this . #tooltip. style . top = `${ - ( tooltipHeight - targetHeight ) >> 1 } px`
177- this . #tooltip. style . left = `${ - tooltipWidth - Tooltip . GAP } px`
178+ this . #tooltip. style . left = `${ - tooltipWidth - this . #offset } px`
178179 this . #tooltip. style . bottom = null
179180 this . #tooltip. style . right = null
180181 break
181182 }
182183 case 'right' : {
183184 this . #tooltip. style . top = `${ - ( tooltipHeight - targetHeight ) >> 1 } px`
184- this . #tooltip. style . right = `${ - tooltipWidth - Tooltip . GAP } px`
185+ this . #tooltip. style . right = `${ - tooltipWidth - this . #offset } px`
185186 this . #tooltip. style . bottom = null
186187 this . #tooltip. style . left = null
187188 break
188189 }
189190 case 'bottom' : {
190191 this . #tooltip. style . left = `${ - ( tooltipWidth - targetWidth ) >> 1 } px`
191- this . #tooltip. style . bottom = `${ - tooltipHeight - Tooltip . GAP } px`
192+ this . #tooltip. style . bottom = `${ - tooltipHeight - this . #offset } px`
192193 this . #tooltip. style . right = null
193194 this . #tooltip. style . top = null
194195 break
195196 }
196197 default : {
197198 this . #tooltip. style . left = `${ - ( tooltipWidth - targetWidth ) >> 1 } px`
198- this . #tooltip. style . top = `${ - tooltipHeight - Tooltip . GAP } px`
199+ this . #tooltip. style . top = `${ - tooltipHeight - this . #offset } px`
199200 this . #tooltip. style . right = null
200201 this . #tooltip. style . bottom = null
201202 }
0 commit comments