-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper-people-list.html
139 lines (134 loc) · 3.23 KB
/
paper-people-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
133
134
135
136
137
138
139
<link rel="import" href="../paper-input/paper-input-container.html">
<link rel="import" href="../paper-chip/paper-chip.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../iron-dropdown/iron-dropdown.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../paper-item/paper-item-body.html">
<link rel="import" href="../paper-item/paper-icon-item.html">
<link rel="import" href="../paper-material/paper-material.html">
<dom-module id="paper-people-list">
<style>
paper-chip {
display: inline-block;
margin: 10px 10px 0px 0;
}
paper-chip[opened] {
z-index: 999;
}
iron-dropdown {
position: relative;
top: 0 !important;
left: 0 !important;
}
iron-dropdown /deep/ .dropdown-content {
position: absolute;
margin-top: 20px;
padding: 2px;
background: white;
z-index: 999;
}
iron-icon {
border-radius: 50%;
height: 40px;
width: 40px;
}
iron-icon /deep/ img {
border-radius: 50%;
}
</style>
<template>
<template is="dom-repeat" items="{{people}}">
<paper-chip removable on-remove="_handleChipRemoval">
<iron-icon class='icon' src="{{item.avatar}}"></iron-icon>
<h1>{{item.name}}</h1>
<h2>{{item.identifier}}</h2>
</paper-chip>
</template>
<paper-input-container class="dropdown-trigger">
<input id="searchbar" is="iron-input" on-keyup="_searchChanged">
</paper-input-container>
<iron-dropdown id="dropdown">
<div class="dropdown-content">
<paper-material elevation="1">
<template is="dom-repeat" items="{{data}}">
<paper-icon-item on-tap="_addItemToList">
<div class="avatar" item-icon>
<iron-icon src="{{item.avatar}}"></iron-icon>
</div>
<paper-item-body two-line>
<div>{{item.name}}</div>
<div secondary>{{item.identifier}}</div>
</paper-item-body>
</paper-icon-item>
</template>
</paper-material>
</div>
</iron-dropdown>
</template>
</dom-module>
<script>
( function () {
Polymer({
is: 'paper-people-list',
properties: {
/*
* {
avatar: 'someurl.png'
name: 'Prateek',
identifier: '[email protected]'
}
*/
/*
* Total number of people selected
*/
people: {
type: Array,
value: [],
notify: true
},
/*
* data obtained from the server
*/
data: {
type: Object,
value: [],
notify: true,
observer: '_handleDataChange'
},
/*
* the search parameter of the input field
*/
search: {
type: String,
value: "",
notify: true
}
},
_searchChanged: function (e, detail) {
if(e.target.value) {
this.fire('search-changed', {
search: e.target.value
});
}
},
_handleDataChange: function () {
this.$.dropdown.open();
},
_addItemToList: function (e, detail) {
this.push('people',e.model.item);
this.$.searchbar.value = "";
this.$.dropdown.close();
},
_handleChipRemoval: function (e, detail) {
var current = e.model.item.identifier,
index = null;
this.people.forEach( function (val, i) {
if(val.identifier === current) {
index = i;
}
});
this.splice('people', index, 1);
}
});
})();
</script>