-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathinput-fieldset.js
76 lines (70 loc) · 2.03 KB
/
input-fieldset.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
import { css, html, LitElement } from 'lit';
import { classMap } from 'lit/directives/class-map.js';
import { getUniqueId } from '../../helpers/uniqueId.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { InputInlineHelpMixin } from './input-inline-help.js';
import { inputLabelStyles } from './input-label-styles.js';
import { offscreenStyles } from '../offscreen/offscreen.js';
import { RtlMixin } from '../../mixins/rtl/rtl-mixin.js';
import { SkeletonMixin } from '../skeleton/skeleton-mixin.js';
/**
* A component wrapper to be used when a page contains multiple inputs which are related (for example to form an address) to wrap those related inputs.
* @slot - Related input components
*/
class InputFieldset extends InputInlineHelpMixin(SkeletonMixin(RtlMixin(LitElement))) {
static get properties() {
return {
/**
* REQUIRED: Label for the fieldset
* @type {string}
*/
label: { type: String },
/**
* Hides the label visually
* @type {boolean}
*/
labelHidden: { type: Boolean, attribute: 'label-hidden', reflect: true },
/**
* Indicates that a value is required for inputs in the fieldset
* @type {boolean}
*/
required: { type: Boolean, reflect: true }
};
}
static get styles() {
return [ super.styles, inputLabelStyles, offscreenStyles,
css`
:host {
display: block;
}
:host([hidden]) {
display: none;
}
`
];
}
constructor() {
super();
this.labelHidden = false;
this.required = false;
this._inlineHelpId = getUniqueId();
}
render() {
const legendClasses = {
'd2l-input-label': true,
'd2l-offscreen': this.labelHidden,
'd2l-skeletize': true
};
return html`
<fieldset
class="d2l-input-label-fieldset"
aria-describedby="${ifDefined(this._hasInlineHelp ? this._inlineHelpId : undefined)}"
>
<legend class="${classMap(legendClasses)}">${this.label}</legend>
<slot></slot>
${this._renderInlineHelp(this._inlineHelpId)}
</fieldset>
`;
}
}
customElements.define('d2l-input-fieldset', InputFieldset);