-
Notifications
You must be signed in to change notification settings - Fork 25
/
input-inline-help.js
54 lines (46 loc) · 1.24 KB
/
input-inline-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
import { css, html } from 'lit';
import { _generateBodySmallStyles } from '../typography/styles.js';
import { SkeletonMixin } from '../skeleton/skeleton-mixin.js';
export const inlineHelpStyles = [
_generateBodySmallStyles('.d2l-input-inline-help'),
css`
.d2l-input-inline-help {
margin-top: 0.3rem !important;
overflow-wrap: anywhere;
}
`
];
export const InputInlineHelpMixin = superclass => class extends SkeletonMixin(superclass) {
static get properties() {
return {
_hasInlineHelp: { type: Boolean, reflect: true, attribute: '_has-inline-help' }
};
}
static get styles() {
const styles = [ inlineHelpStyles, css`
:host([_has-inline-help]) .d2l-input-inline-help {
display: block;
}
.d2l-input-inline-help {
display: none;
}
`];
super.styles && styles.unshift(super.styles);
return styles;
}
constructor() {
super();
this._hasInlineHelp = false;
}
_handleInlineHelpSlotChange(e) {
const content = e.target.assignedNodes({ flatten: true });
this._hasInlineHelp = content?.length > 0;
}
_renderInlineHelp(id) {
return html`
<div id="${id}" class="d2l-input-inline-help d2l-skeletize">
<slot name="inline-help" @slotchange="${this._handleInlineHelpSlotChange}"></slot>
</div>
`;
}
};