-
Notifications
You must be signed in to change notification settings - Fork 6
/
Tooltip.js
84 lines (68 loc) · 1.95 KB
/
Tooltip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import CustomElement from '../core/CustomElement.js';
import AriaReflectorMixin from '../mixins/AriaReflectorMixin.js';
import ShapeMixin from '../mixins/ShapeMixin.js';
import ThemableMixin from '../mixins/ThemableMixin.js';
/* https://m3.material.io/components/tooltips/specs */
export default CustomElement
.extend()
.mixin(ThemableMixin)
.mixin(ShapeMixin)
.mixin(AriaReflectorMixin)
.set({
_ariaRole: 'tooltip',
})
.observe({
open: {
type: 'boolean',
changedCallback(oldValue, newValue) {
this.updateAriaProperty('ariaHidden', newValue ? 'true' : 'false');
},
},
})
.html`
<div id=hover-target></div>
<slot id=slot></slot>
`
.css`
:host {
--mdw-shape__size: var(--mdw-shape__extra-small);
--mdw-ink: var(--mdw-color__inverse-on-surface);
--mdw-bg: var(--mdw-color__inverse-surface);
display: block;
box-sizing: border-box;
/* Ensure 24px min-height while keeping display:block */
padding-block: calc(12px - var(--mdw-typescale__body-small__line-height) / 2);
padding-inline: 8px;
pointer-events: none;
opacity: 0;
transform: scale(0);
z-index: 28;
background-color: rgb(var(--mdw-bg));
color: rgb(var(--mdw-ink));
font: var(--mdw-typescale__body-small__font);
letter-spacing: var(--mdw-typescale__body-small__letter-spacing);
transition: transform 200ms, opacity 200ms;
}
@supports(width: 1lh) {
:host {
padding-block: calc(12px - 0.5lh);
}
}
:host([open]) {
pointer-events: auto;
opacity: 1;
transform: scale(1);
}
#hover-target {
position: absolute;
inset-block-start: 50%;
inset-inline-start: 50%;
box-sizing: content-box;
block-size: 100%;
inline-size: 100%;
padding: 8px;
transform: translateX(-50%) translateY(-50%);
z-index: -1;
}
`
.autoRegister('mdw-tooltip');