2
2
// SPDX-License-Identifier: MIT
3
3
// Copyright (c) vis.gl contributors
4
4
5
- import type { Widget } from './widget' ;
5
+ import { Widget , WidgetProps } from './widget' ;
6
6
import type { WidgetPlacement } from './widget-manager' ;
7
7
import type { PickingInfo } from './picking/pick-info' ;
8
8
import type Viewport from '../viewports/viewport' ;
9
- import type Deck from './deck' ;
10
9
11
10
/* global document */
12
11
const defaultStyle : Partial < CSSStyleDeclaration > = {
@@ -31,32 +30,34 @@ export type TooltipContent =
31
30
style ?: Partial < CSSStyleDeclaration > ;
32
31
} ;
33
32
34
- export default class Tooltip implements Widget {
33
+ export type TooltipWidgetProps = WidgetProps ;
34
+
35
+ export class TooltipWidget extends Widget < TooltipWidgetProps > {
36
+ static defaultProps : Required < TooltipWidgetProps > = {
37
+ ...Widget . defaultProps
38
+ } ;
39
+
35
40
id = 'default-tooltip' ;
36
41
placement : WidgetPlacement = 'fill' ;
37
- props = { } ;
42
+ className = 'deck-tooltip' ;
43
+
38
44
isVisible : boolean = false ;
39
- deck ?: Deck < any > ;
40
- element ?: HTMLDivElement ;
41
45
lastViewport ?: Viewport ;
42
46
43
- onAdd ( { deck} : { deck : Deck < any > } ) : HTMLDivElement {
47
+ constructor ( props : TooltipWidgetProps = { } ) {
48
+ super ( props , TooltipWidget . defaultProps ) ;
49
+ this . setProps ( props ) ;
50
+ }
51
+
52
+ // TODO(ib) - does this really need to be overridden?
53
+ onCreateRootElement ( ) {
44
54
const el = document . createElement ( 'div' ) ;
45
- el . className = 'deck-tooltip' ;
55
+ el . className = this . className ;
46
56
Object . assign ( el . style , defaultStyle ) ;
47
-
48
- this . deck = deck ;
49
- this . element = el ;
50
-
51
57
return el ;
52
58
}
53
59
54
- onRemove ( ) {
55
- this . deck = undefined ;
56
- this . element = undefined ;
57
- }
58
-
59
- setProps ( ) { }
60
+ onRenderHTML ( rootElement : HTMLElement ) : void { }
60
61
61
62
onViewportChange ( viewport : Viewport ) {
62
63
if ( this . isVisible && viewport . id === this . lastViewport ?. id && viewport !== this . lastViewport ) {
@@ -77,7 +78,7 @@ export default class Tooltip implements Widget {
77
78
}
78
79
79
80
setTooltip ( displayInfo : TooltipContent , x ?: number , y ?: number ) : void {
80
- const el = this . element ;
81
+ const el = this . rootElement ;
81
82
if ( ! el ) {
82
83
return ;
83
84
}
0 commit comments