-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaadin-radio-group-2.js
50 lines (49 loc) · 1.24 KB
/
vaadin-radio-group-2.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
import { LitElement, html, css, property } from 'lit-element';
import { vaadinRadioGroupStyles } from './vaadin-radio-group-styles.js';
class VaadinRadioGroup2 extends LitElement {
static get properties() {
return {
legend: { type: String },
name: { type: String },
options: { type: Number },
optionIndexes: { type: Array }
};
}
constructor() {
super();
this.legend = '';
this.name = '';
this.options = 0;
this.optionIndexes = [];
}
static get styles() {
return [vaadinRadioGroupStyles, css``];
}
render() {
return html`
<fieldset>
<legend>${this.legend}</legend>
${this.optionIndexes.map(
(i) => html`
<label>
<input type="radio" name="${this.name}">
<span>
<slot name="option-${i + 1}"></slot>
</span>
</label>
`
)}
</fieldset>
`;
}
updated(props) {
props.forEach((_, name) => {
if (name === 'options') {
const optionIndexes = [];
for (let i = 0; i < this.options; i++) optionIndexes.push(i);
this.optionIndexes = optionIndexes;
}
});
}
}
customElements.define('vaadin-radio-group-2', VaadinRadioGroup2);