-
Notifications
You must be signed in to change notification settings - Fork 4
/
paper-collapse.html
165 lines (147 loc) · 3.3 KB
/
paper-collapse.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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../iron-collapse/iron-collapse.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../iron-iconset-svg/iron-iconset-svg.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../font-roboto/roboto.html">
<iron-iconset-svg size="24" name="paper-collapse">
<svg>
<defs>
<g id="expand-less">
<path d="M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z"></path>
</g>
<g id="expand-more">
<path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"></path>
</g>
</defs>
</svg>
</iron-iconset-svg>
<dom-module id="paper-collapse">
<template>
<style>
:host {
display: block;
font-family: Roboto;
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
margin-top: -1px;
}
:host([opened]) {
border-top-color: #EBEBEB;
border-bottom-color: #EBEBEB;
}
:host([hidden]) {
display: none;
}
#toolbar {
padding: 12px 15px;
@apply --layout-horizontal;
}
#toolbar:hover {
cursor: pointer;
}
#labelIcon {
color: #757575;
margin-right: 30px;
}
:host([opened]) #labelIcon,
:host([opened]) #label {
color: #543828;
}
#label {
padding-right: 30px;
line-height: 24px;
@apply --layout-flex;
}
#closedIcon,
#openedIcon {
color: #B4B4B4;
}
#dropShadowContainer {
position: relative;
}
#dropShadow {
opacity: 0;
transition: opacity 0.5s;
height: 6px;
box-shadow: inset 0px 5px 6px -3px rgba(0, 0, 0, 0.4);
position: absolute;
top: 0;
left: 0;
right: 0;
pointer-events: none;
}
:host([opened]) #dropShadow {
opacity: 1;
}
</style>
<div id="container">
<div id="toolbar" on-click="toggle">
<template is="dom-if" if="{{labelIcon}}">
<iron-icon icon="{{labelIcon}}" id="labelIcon"></iron-icon>
</template>
<div id="label">{{label}}</div>
<iron-icon icon="{{closedIcon}}" id="closedIcon" hidden$="{{opened}}"></iron-icon>
<iron-icon icon="{{openedIcon}}" id="openedIcon" hidden$="{{!opened}}"></iron-icon>
</div>
<div id="dropShadowContainer">
<div id="dropShadow"></div>
</div>
<iron-collapse id="collapse" opened$="{{opened}}">
<slot></slot>
</iron-collapse>
</div>
</template>
<script>
class PaperCollapse extends Polymer.Element {
static get is() {
return 'paper-collapse';
}
static get properties() {
return {
closedIcon: {
type: String,
value: 'paper-collapse:expand-more'
},
label: {
type: String,
value: ''
},
labelIcon: {
type: String,
value: ''
},
opened: {
type: Boolean,
value: false,
reflectToAttribute: true,
notify: true
},
openedIcon: {
type: String,
value: 'paper-collapse:expand-less'
}
};
}
ready() {
super.ready();
this.$.collapse.addEventListener(
'tap',
function (event) {
event.stopPropagation();
}
);
}
close() {
this.opened = false;
}
open() {
this.opened = true;
}
toggle() {
this.opened = !this.opened;
}
}
customElements.define(PaperCollapse.is, PaperCollapse);
</script>
</dom-module>