-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent-list.html
132 lines (117 loc) · 4.51 KB
/
component-list.html
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
124
125
126
127
128
129
130
131
132
<link rel="import" href="../polymer/polymer.html" />
<link rel="import" href="../component-info/component-info.html">
<link rel="import" href="../component-item/component-item.html">
<link rel="import" href="../paper-item/paper-item.html" >
<link rel="import" href="../paper-listbox/paper-listbox.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<dom-module id="component-list">
<template>
<style>
:host {
height: var(--component-list--height, 500px);
display: block;
@apply(--layout-horizontal);
}
paper-item {
--paper-item: {
padding: 0;
border-bottom: 1px solid rgba(0,0,0,0.1);
margin-top: 1px;
}
}
paper-listbox {
@apply(--layout-flex);
background: none;
}
.expand{
overflow-y: scroll;
@apply(--layout-flex-8);
padding: 20px;
}
.withComponentInfo {
@apply(--layout-flex-2);
}
</style>
<paper-listbox
selected="{{selectedComponent}}"
class$="[[_componentInfoDivClass(showcomponentinfo)]]">
<template is="dom-repeat" items="{{components}}">
<paper-item on-iron-selected="something()" draggable="true">
<component-item
name$="[[item.name]]"
homepage$="[[item.homepage]]"
version$="[[item.version]]"
data$="[[item]]">
</component-item>
</paper-item>
</template>
</paper-listbox>
<template is="dom-if" if="[[showcomponentinfo]]">
<div class="expand">
<component-info
homepage$="[[arrayItem(components.*, selectedComponent, 'homepage')]]">
</component-info>
</div>
</template>
</template>
<script>
Polymer({
is: 'component-list',
properties: {
selectedComponent: {
type: Number,
value: 0,
notify: true
},
components: {
type: Array,
reflectToAttribute: false,
notify: true
},
showcomponentinfo: {
type: Boolean,
reflectToAttribute: true,
notify: true,
value: false
}
},
attached: function() {
this.async(() => {
if(!this.components) {
console.warn('component-list : No components added to attribute. Please refer the documentation.');
}
this.handleDOMChanged();
});
},
handleDOMChanged: function() {
this.$$('paper-listbox').addEventListener('dom-change', () => {
this.attachListeners();
});
},
attachListeners: function() {
var draggableEl = this.$$('paper-listbox').queryAllEffectiveChildren('paper-item');
for(i = 0; i < draggableEl.length; i++) {
draggableEl[i].addEventListener('dragstart', (e)=>{
var data = JSON.stringify(e.srcElement.querySelector('component-item').getAttribute('data'));
e.dataTransfer.setData('text', data);
});
}
},
// first argument is the change record for the array change,
// change.base is the array specified in the binding
arrayItem: function(change, index, path) {
// this.get(path, root) returns a value for a path
// relative to a root object.
return this.get(path, change.base[index]);
},
/*
* computes whether a section needs to be divided into two or not
* @param showcomponentinfo The value of showcomponentinfo
* @returns String classname of the divider class
*/
_componentInfoDivClass: function(showcomponentinfo) {
return showcomponentinfo ? 'withComponentInfo' : '';
}
});
</script>
</dom-module>