-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper-avatar-list.html
170 lines (138 loc) · 3.98 KB
/
paper-avatar-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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="./paper-avatar.html">
<!--
`paper-avatar-list`
Displays a list of avatars
@demo demo/paper-avatar-list.html
-->
<dom-module id="paper-avatar-list">
<template>
<style>
:host {
--paper-avatar-list-lag: 400ms;
--paper-avatar-list-delay: 30ms;
--paper-avatar-list-avatar-size: 50px;
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: wrap;
}
:host([hidden]) {
display: none !important;
}
[hidden] {
display: none !important;
}
.expand-button {
width: 40px;
height: 40px;
background-color: #607d8b;
color: white;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
margin-left: 14px;
cursor: pointer;
transform: scale(0);
animation: popup 233ms ease-in-out forwards;
}
paper-avatar {
width: var(--paper-avatar-list-avatar-size);
height: var(--paper-avatar-list-avatar-size);
margin-right: -10px;
margin-bottom: 4px;
transform: scale(0);
animation: popup 233ms ease-in-out forwards;
}
@keyframes popup {
to {
transform: scale(1);
}
};
</style>
<template is="dom-repeat" items="[[_filterByLimit(items, limit)]]" initial-count="1" target-framerate="32">
<paper-avatar
style$="animation-delay: [[_getDelay(index, expanded)]]"
badge="[[_getValueByName(item, badgeName)]]"
placeholder="[[_getValueByName(item, placeholderName)]]"
src="[[_getValueByName(item, avatarName)]]">
</paper-avatar>
</template>
<template is="dom-if" if="[[expanded]]">
<template is="dom-repeat" items="[[_restOfItems]]" initial-count="1" target-framerate="32">
<paper-avatar
style$="animation-delay: [[_getDelay(index, expanded)]]
badge="[[_getValueByName(item, badgeName)]]"
placeholder="[[_getValueByName(item, placeholderName)]]"
src="[[_getValueByName(item, avatarName)]]">
</paper-avatar>
</template>
</template>
<template is="dom-if" if="[[_restOfItems.length]]">
<span class="expand-button" on-tap="_onExpandClicked" hidden="[[expanded]]" style$="animation-delay: [[_getDelay(limit, expanded, 1)]]">+[[_restOfItems.length]]</span>
</template>
</template>
<script>
Polymer({
is: 'paper-avatar-list',
properties: {
items: {
type: Array
},
avatarName: {
type: String,
value: 'image'
},
placeholderName: {
type: String,
value: 'name'
},
badgeName: {
type: String
},
limit: {
type: Number,
value: 3
},
expanded: {
type: Boolean,
value: false
},
_restOfItems: {
type: Number,
computed: '_getRestOfItems(items, limit)'
}
},
expand: function() {
this.expanded = true;
},
collapse: function() {
this.expanded = false;
},
_onExpandClicked: function(e) {
e.preventDefault();
this.expand();
},
_getValueByName: function(item, name) {
return item ? item[name] : null;
},
_filterByLimit(items, limit) {
return items.slice(0, limit);
},
_getRestOfItems: function(items, limit) {
if (!items) {
return [];
}
return items.slice(limit);
},
_getDelay: function(index, inmediate, plus) {
var lag = inmediate ? 0 : 400;
var delay = parseInt(this.getComputedStyleValue('--paper-avatar-list-delay'));
var inc = plus ? plus : 0;
var time = lag + (delay * (index + inc)) + (inc * 32);
return time + 'ms'
},
});
</script>
</dom-module>