-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal-sheet.html
243 lines (204 loc) · 5.36 KB
/
modal-sheet.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-dialog-behavior/paper-dialog-behavior.html">
<link rel="import" href="../neon-animation/neon-animation-runner-behavior.html">
<link rel="import" href="../neon-animation/animations/slide-from-bottom-animation.html">
<link rel="import" href="../neon-animation/animations/slide-down-animation.html">
<!--
`modal-sheet`
Sheet that slide up from the bottom of the screen to reveal more content.
@demo demo/index.html
-->
<dom-module id="modal-sheet">
<template>
<style>
:host {
contain: layout;
display: block;
margin: 0 auto;
position: fixed;
right: 0;
bottom: 0;
left: 0;
will-change: transform;
background: var(--modal-sheet-background-color, --primary-background-color);
color: var(--modal-sheet-color, --primary-text-color);
}
.content {
width: 100%;
background-color: white;
margin: 0;
padding: 0;
}
.header {
width: 100%;
box-sizing: border-box;
display: block;
background-color: #fff;
border: 0;
font-size: 1.1em;
padding: 16px;
margin: 0;
border-bottom: 1px solid rgba(0,0,0,0.13);
}
#cancel-button {
font-size: 24px;
font-weight: bold;
padding: 6px;
color: rgba(0,0,0,0.65);
text-decoration: none;
position: absolute;
right: 10px;
top: 6px;
cursor: pointer;
}
@media (min-width: 600px) {
:host {
max-width: 384px;
}
}
@media (min-width: 900px) {
:host {
max-width: 512px;
}
}
@media (min-width: 1280px) {
:host {
max-width: 576px;
}
}
</style>
<template is="dom-if" if="[[title]]">
<div class="header">
[[title]]
<template is="dom-if" if="[[showClose]]">
<span id="cancel-button" on-tap="close">×</span>
</template>
</div>
</template>
<div class="content">
<content></content>
</div>
</template>
</dom-module>
<script>
(function() {
var footer = document.createElement('div');
footer.style.contain = 'layout';
document.body.appendChild(footer);
Polymer({
is: 'modal-sheet',
behaviors: [
Polymer.PaperDialogBehavior,
Polymer.NeonAnimationRunnerBehavior
],
properties: {
title: {
type: String,
},
showClose: {
type: Boolean,
value: false
},
/**
* True if the bottom sheet acts like a modal dialog (e.g. can't be closed by clicking outside).
* Note that the "cancel" option will disappear if the dialog is not modal, as the "cancel" option
* will be the user's only method of exit when the bottom sheet is modal.
*/
modal: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* True if the bottom sheet should slide in from the bottom on entry
*/
slide: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* True if the bottom sheet is opened with backdrop
* @default true
*/
withBackdrop: {
type: Boolean,
value: true,
reflectToAttribute: true
},
autoFitOnAttach: {
type: Boolean,
value: true
},
/**
* The animation config supplied to the included paper-dialog. Will be empty unless "slide"
* is set.
*/
animationConfig: {
type: Object,
computed: '_animationConfig(slide)'
},
},
listeners: {
'neon-animation-finish': '_onNeonAnimationFinish',
'on-iron-overlay-closed': '_attemptRemoval'
},
attached: function() {
footer.appendChild(this);
},
_renderOpened: function() {
this.cancelAnimation();
this.playAnimation('entry');
},
_renderClosed: function() {
this.cancelAnimation();
this.playAnimation('exit');
},
_onNeonAnimationFinish: function() {
if (this.opened) {
this._finishRenderOpened();
} else {
this._finishRenderClosed();
// this._attemptRemoval();
}
},
/**
* Computed property function- changes the animation config of the dialog based on presence of "slide" attr
* @param {Boolean} slide True if the bottom sheet should slide in
* @return {Object} Animation config
*/
_animationConfig: function(slide) {
if (!slide) {
return {};
}
return {
entry: {
name: 'slide-from-bottom-animation',
node: this,
timing: {
duration: 333,
easing: 'cubic-bezier(0.4, 0, 0.2, 1)'
}
},
exit: {
name: 'slide-down-animation',
node: this,
timing: {
duration: 333,
easing: 'cubic-bezier(0.4, 0, 0.2, 1)'
}
}
};
},
/**
* Runs when the dialog is closed. Will remove this from the DOM
*/
_attemptRemoval: function() {
if (this.parentNode) {
// Remove this element from DOM if there is an animation and the dialog just closed
this.parentNode.removeChild(this);
}
}
});
})();
</script>