-
Notifications
You must be signed in to change notification settings - Fork 25
/
tooltip-help.js
123 lines (113 loc) · 3.3 KB
/
tooltip-help.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import '../colors/colors.js';
import '../tooltip/tooltip.js';
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
import { bodySmallStyles } from '../typography/styles.js';
import { classMap } from 'lit/directives/class-map.js';
import { FocusMixin } from '../../mixins/focus/focus-mixin.js';
import { getFocusPseudoClass } from '../../helpers/focus.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { SkeletonMixin } from '../skeleton/skeleton-mixin.js';
/**
* A component used to display additional information when users focus or hover over some text.
* @slot - Default content placed inside of the tooltip
*/
class TooltipHelp extends SkeletonMixin(FocusMixin(LitElement)) {
static get properties() {
return {
/**
* Allows this component to inherit certain font properties
* @type {boolean}
*/
inheritFontStyle: { type: Boolean, attribute: 'inherit-font-style' },
/**
* ADVANCED: Force the internal tooltip to open in a certain direction. If no position is provided, the tooltip will open in the first position that has enough space for it in the order: bottom, top, right, left.
* @type {'top'|'bottom'|'left'|'right'}
*/
position: { type: String },
/**
* @ignore
*/
showing: { type: Boolean, reflect: true },
/**
* REQUIRED: Text that will render as the Help Tooltip opener
* @type {string}
*/
text: { type: String }
};
}
static get styles() {
return [super.styles, bodySmallStyles, css`
:host {
display: inline-block;
}
:host([hidden]) {
display: none;
}
#d2l-tooltip-help-text {
background: none;
border: none;
cursor: inherit;
font-family: inherit;
padding: 0;
text-decoration-line: underline;
text-decoration-style: dashed;
text-decoration-thickness: 1px;
text-underline-offset: 0.1rem;
}
#d2l-tooltip-help-text:focus {
outline-style: none;
}
#d2l-tooltip-help-text:${unsafeCSS(getFocusPseudoClass())} {
border-radius: 0.05rem;
outline: 2px solid var(--d2l-color-celestine);
outline-offset: 0.05rem;
text-underline-offset: 0.1rem;
}
:host([inherit-font-style]) #d2l-tooltip-help-text {
color: inherit;
font-size: inherit;
font-weight: inherit;
letter-spacing: inherit;
line-height: inherit;
margin: inherit;
}
d2l-tooltip {
cursor: text;
}
:host([skeleton]) #d2l-tooltip-help-text.d2l-skeletize {
text-decoration: none;
}
`];
}
constructor() {
super();
this.inheritFontStyle = false;
this.showing = false;
}
static get focusElementSelector() {
return 'button';
}
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties);
if (!this.text || this.text.length === 0) {
console.warn('Help Tooltip component requires text.');
}
}
render() {
const classes = {
'd2l-body-small': !this.inheritFontStyle,
'd2l-skeletize': true
};
return html`
<button id="d2l-tooltip-help-text" class="${classMap(classes)}" type="button">
${this.text}
</button>
${!this.skeleton ? html`
<d2l-tooltip class="vdiff-target" for="d2l-tooltip-help-text" delay="0" offset="13" position="${ifDefined(this.position)}" ?showing="${this.showing}">
<slot></slot>
</d2l-tooltip>
` : nothing }
`;
}
}
customElements.define('d2l-tooltip-help', TooltipHelp);