-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.js
50 lines (42 loc) · 1.26 KB
/
list.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 {PolymerElement, html} from '@polymer/polymer/polymer-element.js';
import '@polymer/paper-radio-button/paper-radio-button.js';
import '@polymer/paper-radio-group/paper-radio-group.js';
import './shared-styles.js';
class List extends PolymerElement {
static get template() {
return html`
<style include="shared-styles">
:host { display: block; padding: 10px; }
</style>
<div class="db-list">
<paper-radio-group selected="{{selectedId}}">
<template is="dom-repeat" items="[[db]]">
<paper-radio-button name="[[item.id]]" >
<span>[[item.name]]</span>
<img src="[[item.imageUrl]]" />
</paper-radio-button>
</template>
</paper-radio-group>
</div>
`;
}
static get properties() {
return {
selectedId: { type:String, observer: '_idChanged', notify: true },
selected: { type:Object , notify: true },
db: { type: Array },
};
}
ready() {
if( !this.selected ) {
this.selected = this.db[this.db.length - 1];
}
super.ready();
}
_idChanged(id) {
const obj = this.db.find(el=> el.id === id);
Object.assign(this, obj);
this.set('selected', obj);
}
}
window.customElements.define('nc-list', List);