collapse.html
5.38 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!doctype html>
<html>
<head>
<title>Collapsable items using iron-list</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../paper-styles/color.html">
<link rel="import" href="../../paper-styles/typography.html">
<link rel="import" href="../../iron-ajax/iron-ajax.html">
<link rel="import" href="../../iron-icons/iron-icons.html">
<link rel="import" href="../../iron-image/iron-image.html">
<link rel="import" href="../iron-list.html">
<style>
body {
background-color: #eee;
margin: 0;
padding: 0;
}
</style>
</head>
<body unresolved>
<dom-module id="x-collapse">
<template>
<style>
:host {
display: block;
@apply(--paper-font-common-base);
}
app-toolbar {
background-color: var(--google-green-700);
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.3);
font-weight: bold;
color: white;
z-index: 1;
position: fixed;
top: 0;
left: 0;
right: 0;
}
app-toolbar paper-icon-button {
--paper-icon-button-ink-color: white;
}
iron-list {
padding-top: 64px;
--iron-list-items-container: {
max-width: 800px;
margin: auto;
margin-top: 60px;
margin-bottom: 60px;
border-bottom: 1px solid #ddd;
};
}
.item {
@apply(--layout-horizontal);
padding: 20px;
background-color: white;
border: 1px solid #ddd;
cursor: pointer;
margin-bottom: 10px;
}
.avatar {
height: 40px;
width: 40px;
border-radius: 20px;
box-sizing: border-box;
background-color: #DDD;
}
.pad {
padding: 0 16px;
@apply(--layout-flex);
@apply(--layout-vertical);
}
.primary {
font-size: 16px;
font-weight: bold;
}
.shortText, .longText {
font-size: 14px;
}
.longText {
color: gray;
display: none;
}
.item:hover .shortText::after {
content: ' [+]';
color: gray;
}
.item.expanded:hover .shortText::after {
content: '';
}
.item.expanded .longText {
display: block;
}
.item.expanded:hover .longText::after {
content: ' [–]';
}
.spacer {
@apply(--layout-flex);
}
@media (max-width: 460px) {
paper-toolbar .bottom.title {
font-size: 14px;
}
}
</style>
<iron-ajax url="data/contacts.json" last-response="{{items}}" auto></iron-ajax>
<app-toolbar>
<div title>Collapsable items</div>
<paper-icon-button icon="search" alt="Search"></paper-icon-button>
<paper-icon-button icon="more-vert" alt="More options"></paper-icon-button>
</app-toolbar>
<iron-list id="list" items="[[items]]" as="item" selection-enabled multi-selection>
<template>
<div>
<div class$="[[getClassForItem(item, selected)]]" tabindex$="[[tabIndex]]">
<iron-image class="avatar" sizing="contain" src="[[item.image]]"></iron-image>
<div class="pad">
<div class="primary">[[item.name]]</div>
<div class="shortText">[[item.shortText]]</div>
<div class="longText">[[item.longText]]</div>
</div>
<iron-icon icon$="[[iconForItem(item)]]"></iron-icon>
</div>
</div>
</template>
</iron-list>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-collapse',
properties: {
items: {
type: Array
}
},
attached: function() {
// Use the document element
this.$.list.scrollTarget = this.ownerDocument.documentElement;
},
iconForItem: function(item) {
return item ? (item.integer < 50 ? 'star-border' : 'star') : '';
},
getClassForItem: function(item, selected) {
return selected ? 'item expanded' : 'item';
}
});
});
</script>
</dom-module>
<x-collapse></x-collapse>
</body>
</html>