OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | |
3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
6 Code distributed by Google as part of the polymer project is also | |
7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
8 --> | |
9 | |
10 <link rel="import" href="../polymer/polymer.html"> | |
11 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> | |
12 | |
13 <!-- | |
14 `paper-header-panel` contains a header section and a content panel section. | |
15 | |
16 __Important:__ The `paper-header-panel` will not display if its parent does not
have a height. | |
17 | |
18 Using layout classes, you can make the `paper-header-panel` fill the screen | |
19 | |
20 <body class="fullbleed layout vertical"> | |
21 <paper-header-panel class="flex"> | |
22 <paper-toolbar> | |
23 <div>Hello World!</div> | |
24 </paper-toolbar> | |
25 </paper-header-panel> | |
26 </body> | |
27 | |
28 Special support is provided for scrolling modes when one uses a paper-toolbar or
equivalent for the | |
29 header section. | |
30 | |
31 Example: | |
32 | |
33 <paper-header-panel> | |
34 <paper-toolbar>Header</paper-toolbar> | |
35 <div>Content goes here...</div> | |
36 </paper-header-panel> | |
37 | |
38 If you want to use other than `paper-toolbar` for the header, add `paper-header`
class to that | |
39 element. | |
40 | |
41 Example: | |
42 | |
43 <paper-header-panel> | |
44 <div class="paper-header">Header</div> | |
45 <div>Content goes here...</div> | |
46 </paper-header-panel> | |
47 | |
48 To have the content fit to the main area, use the `fit` class. | |
49 | |
50 <paper-header-panel> | |
51 <div class="paper-header">standard</div> | |
52 <div class="fit">content fits 100% below the header</div> | |
53 </paper-header-panel> | |
54 | |
55 Modes | |
56 | |
57 Controls header and scrolling behavior. Options are `standard`, `seamed`, `water
fall`, `waterfall-tall`, `scroll` and | |
58 `cover`. Default is `standard`. | |
59 | |
60 Mode | Description | |
61 ----------------|------------- | |
62 `standard` | The header is a step above the panel. The header will consume the p
anel at the point of entry, preventing it from passing through to the opposite s
ide. | |
63 `seamed` | The header is presented as seamed with the panel. | |
64 `waterfall` | Similar to standard mode, but header is initially presented as sea
med with panel, but then separates to form the step. | |
65 `waterfall-tall` | The header is initially taller (`tall` class is added to the
header). As the user scrolls, the header separates (forming an edge) while conde
nsing (`tall` class is removed from the header). | |
66 `scroll` | The header keeps its seam with the panel, and is pushed off screen. | |
67 `cover` | The panel covers the whole `paper-header-panel` including the header.
This allows user to style the panel in such a way that the panel is partially co
vering the header. | |
68 | |
69 Example: | |
70 | |
71 <paper-header-panel mode="waterfall"> | |
72 <div class="paper-header">standard</div> | |
73 <div class="content fit">content fits 100% below the header</div> | |
74 </paper-header-panel> | |
75 | |
76 | |
77 Styling header panel: | |
78 | |
79 To change the shadow that shows up underneath the header: | |
80 | |
81 paper-header-panel { | |
82 --paper-header-panel-shadow: { | |
83 height: 6px; | |
84 bottom: -6px; | |
85 box-shadow: inset 0px 5px 6px -3px rgba(0, 0, 0, 0.4); | |
86 }; | |
87 } | |
88 | |
89 To change the panel container in different modes: | |
90 | |
91 paper-slider { | |
92 --paper-header-panel-standard-container: { | |
93 border: 1px solid gray; | |
94 }; | |
95 | |
96 --paper-header-panel-cover-container: { | |
97 border: 1px solid gray; | |
98 }; | |
99 | |
100 --paper-header-panel-waterfall-container: { | |
101 border: 1px solid gray; | |
102 }; | |
103 | |
104 --paper-header-panel-waterfall-tall-container: { | |
105 border: 1px solid gray; | |
106 }; | |
107 } | |
108 | |
109 @group Paper Elements | |
110 @element paper-header-panel | |
111 @demo demo/index.html | |
112 @hero hero.svg | |
113 --> | |
114 | |
115 <dom-module id="paper-header-panel"> | |
116 | |
117 <style> | |
118 :host { | |
119 @apply(--layout); | |
120 @apply(--layout-vertical); | |
121 | |
122 display: block; | |
123 position: relative; | |
124 height: 100%; | |
125 | |
126 /* Create a stack context, we will need it for the shadow*/ | |
127 z-index: 0; | |
128 } | |
129 | |
130 :root { | |
131 /** | |
132 * Default paper header panel shadow | |
133 */ | |
134 --paper-header-panel-shadow: { | |
135 height: 6px; | |
136 bottom: -6px; | |
137 box-shadow: inset 0px 5px 6px -3px rgba(0, 0, 0, 0.4); | |
138 }; | |
139 } | |
140 | |
141 #mainContainer { | |
142 @apply(--layout-flex); | |
143 | |
144 position: relative; | |
145 overflow-y: auto; | |
146 overflow-x: hidden; | |
147 -webkit-overflow-scrolling: touch; | |
148 flex-basis: 0.0001px; | |
149 } | |
150 | |
151 /* | |
152 * mode: scroll | |
153 */ | |
154 :host([mode=scroll]) #mainContainer { | |
155 @apply(--paper-header-panel-scroll-container); | |
156 overflow: visible; | |
157 } | |
158 | |
159 :host([mode=scroll]) { | |
160 overflow-y: auto; | |
161 overflow-x: hidden; | |
162 -webkit-overflow-scrolling: touch; | |
163 } | |
164 | |
165 /* | |
166 * mode: cover | |
167 */ | |
168 :host([mode=cover]) #mainContainer { | |
169 @apply(--paper-header-panel-cover-container); | |
170 position: absolute; | |
171 top: 0; | |
172 right: 0; | |
173 bottom: 0; | |
174 left: 0; | |
175 } | |
176 | |
177 /* | |
178 * mode: standard | |
179 */ | |
180 :host([mode=standard]) #mainContainer { | |
181 @apply(--paper-header-panel-standard-container); | |
182 } | |
183 | |
184 /* | |
185 * mode: waterfall | |
186 */ | |
187 :host([mode=waterfall]) #mainContainer { | |
188 @apply(--paper-header-panel-waterfall-container); | |
189 } | |
190 | |
191 /* | |
192 * mode: waterfall-tall | |
193 */ | |
194 :host([mode=waterfall-tall]) #mainContainer { | |
195 @apply(--paper-header-panel-waterfall-tall-container); | |
196 } | |
197 | |
198 :host ::content paper-toolbar, | |
199 :host ::content .paper-header { | |
200 position: relative; | |
201 overflow: visible !important; | |
202 } | |
203 | |
204 :host ::content paper-toolbar:after, | |
205 :host ::content .paper-header:after { | |
206 @apply(--paper-header-panel-shadow); | |
207 | |
208 -webkit-transition: opacity 0.5s, -webkit-transform 0.5s; | |
209 transition: opacity 0.5s, transform 0.5s; | |
210 | |
211 opacity: 0; | |
212 content: ""; | |
213 | |
214 width: 100%; | |
215 position: absolute; | |
216 left: 0px; | |
217 right: 0px; | |
218 z-index: 1; | |
219 | |
220 -webkit-transform: scale3d(1, 0, 1); | |
221 -webkit-transform-origin: 0% 0%; | |
222 | |
223 transform: scale3d(1, 0, 1); | |
224 transform-origin: 0% 0%; | |
225 } | |
226 | |
227 :host ::content paper-toolbar.has-shadow:after, | |
228 :host ::content .paper-header.has-shadow:after { | |
229 opacity: 1; | |
230 -webkit-transform: scale3d(1, 1, 1); | |
231 transform: scale3d(1, 1, 1); | |
232 } | |
233 </style> | |
234 | |
235 <template> | |
236 <content id="headerContent" select="paper-toolbar, .paper-header"></content> | |
237 <div id="mainContainer" class$="[[_computeMainContainerClass(mode)]]"> | |
238 <content id="mainContent" select="*"></content> | |
239 </div> | |
240 </template> | |
241 | |
242 </dom-module> | |
243 | |
244 <script> | |
245 | |
246 (function() { | |
247 | |
248 'use strict'; | |
249 | |
250 var SHADOW_WHEN_SCROLLING = 1; | |
251 var SHADOW_ALWAYS = 2; | |
252 | |
253 | |
254 var MODE_CONFIGS = { | |
255 | |
256 outerScroll: { | |
257 scroll: true | |
258 }, | |
259 | |
260 shadowMode: { | |
261 standard: SHADOW_ALWAYS, | |
262 waterfall: SHADOW_WHEN_SCROLLING, | |
263 'waterfall-tall': SHADOW_WHEN_SCROLLING | |
264 }, | |
265 | |
266 tallMode: { | |
267 'waterfall-tall': true | |
268 } | |
269 }; | |
270 | |
271 Polymer({ | |
272 | |
273 is: 'paper-header-panel', | |
274 | |
275 /** | |
276 * Fired when the content has been scrolled. `event.detail.target` return
s | |
277 * the scrollable element which you can use to access scroll info such as | |
278 * `scrollTop`. | |
279 * | |
280 * <paper-header-panel on-content-scroll="{{scrollHandler}}"> | |
281 * ... | |
282 * </paper-header-panel> | |
283 * | |
284 * | |
285 * scrollHandler: function(event) { | |
286 * var scroller = event.detail.target; | |
287 * console.log(scroller.scrollTop); | |
288 * } | |
289 * | |
290 * @event content-scroll | |
291 */ | |
292 | |
293 properties: { | |
294 | |
295 /** | |
296 * Controls header and scrolling behavior. Options are | |
297 * `standard`, `seamed`, `waterfall`, `waterfall-tall`, `scroll` and | |
298 * `cover`. Default is `standard`. | |
299 * | |
300 * `standard`: The header is a step above the panel. The header will con
sume the | |
301 * panel at the point of entry, preventing it from passing through to th
e | |
302 * opposite side. | |
303 * | |
304 * `seamed`: The header is presented as seamed with the panel. | |
305 * | |
306 * `waterfall`: Similar to standard mode, but header is initially presen
ted as | |
307 * seamed with panel, but then separates to form the step. | |
308 * | |
309 * `waterfall-tall`: The header is initially taller (`tall` class is add
ed to | |
310 * the header). As the user scrolls, the header separates (forming an e
dge) | |
311 * while condensing (`tall` class is removed from the header). | |
312 * | |
313 * `scroll`: The header keeps its seam with the panel, and is pushed off
screen. | |
314 * | |
315 * `cover`: The panel covers the whole `paper-header-panel` including th
e | |
316 * header. This allows user to style the panel in such a way that the pa
nel is | |
317 * partially covering the header. | |
318 * | |
319 * <paper-header-panel mode="cover"> | |
320 * <paper-toolbar class="tall"> | |
321 * <core-icon-button icon="menu"></core-icon-button> | |
322 * </paper-toolbar> | |
323 * <div class="content"></div> | |
324 * </paper-header-panel> | |
325 */ | |
326 mode: { | |
327 type: String, | |
328 value: 'standard', | |
329 observer: '_modeChanged', | |
330 reflectToAttribute: true | |
331 }, | |
332 | |
333 /** | |
334 * If true, the drop-shadow is always shown no matter what mode is set t
o. | |
335 */ | |
336 shadow: { | |
337 type: Boolean, | |
338 value: false | |
339 }, | |
340 | |
341 /** | |
342 * The class used in waterfall-tall mode. Change this if the header | |
343 * accepts a different class for toggling height, e.g. "medium-tall" | |
344 */ | |
345 tallClass: { | |
346 type: String, | |
347 value: 'tall' | |
348 }, | |
349 | |
350 /** | |
351 * If true, the scroller is at the top | |
352 */ | |
353 atTop: { | |
354 type: Boolean, | |
355 value: true, | |
356 readOnly: true | |
357 } | |
358 }, | |
359 | |
360 observers: [ | |
361 '_computeDropShadowHidden(atTop, mode, shadow)' | |
362 ], | |
363 | |
364 ready: function() { | |
365 this.scrollHandler = this._scroll.bind(this); | |
366 this._addListener(); | |
367 | |
368 // Run `scroll` logic once to initialze class names, etc. | |
369 this._keepScrollingState(); | |
370 }, | |
371 | |
372 detached: function() { | |
373 this._removeListener(); | |
374 }, | |
375 | |
376 /** | |
377 * Returns the header element | |
378 * | |
379 * @property header | |
380 * @type Object | |
381 */ | |
382 get header() { | |
383 return Polymer.dom(this.$.headerContent).getDistributedNodes()[0]; | |
384 }, | |
385 | |
386 /** | |
387 * Returns the scrollable element. | |
388 * | |
389 * @property scroller | |
390 * @type Object | |
391 */ | |
392 get scroller() { | |
393 return this._getScrollerForMode(this.mode); | |
394 }, | |
395 | |
396 /** | |
397 * Returns true if the scroller has a visible shadow. | |
398 * | |
399 * @property visibleShadow | |
400 * @type Boolean | |
401 */ | |
402 get visibleShadow() { | |
403 return this.header.classList.contains('has-shadow'); | |
404 }, | |
405 | |
406 _computeDropShadowHidden: function(atTop, mode, shadow) { | |
407 | |
408 var shadowMode = MODE_CONFIGS.shadowMode[mode]; | |
409 | |
410 if (this.shadow) { | |
411 this.toggleClass('has-shadow', true, this.header); | |
412 | |
413 } else if (shadowMode === SHADOW_ALWAYS) { | |
414 this.toggleClass('has-shadow', true, this.header); | |
415 | |
416 } else if (shadowMode === SHADOW_WHEN_SCROLLING && !atTop) { | |
417 this.toggleClass('has-shadow', true, this.header); | |
418 | |
419 } else { | |
420 this.toggleClass('has-shadow', false, this.header); | |
421 | |
422 } | |
423 }, | |
424 | |
425 _computeMainContainerClass: function(mode) { | |
426 // TODO: It will be useful to have a utility for classes | |
427 // e.g. Polymer.Utils.classes({ foo: true }); | |
428 | |
429 var classes = {}; | |
430 | |
431 classes['flex'] = mode !== 'cover'; | |
432 | |
433 return Object.keys(classes).filter( | |
434 function(className) { | |
435 return classes[className]; | |
436 }).join(' '); | |
437 }, | |
438 | |
439 _addListener: function() { | |
440 this.scroller.addEventListener('scroll', this.scrollHandler, false); | |
441 }, | |
442 | |
443 _removeListener: function() { | |
444 this.scroller.removeEventListener('scroll', this.scrollHandler); | |
445 }, | |
446 | |
447 _modeChanged: function(newMode, oldMode) { | |
448 var configs = MODE_CONFIGS; | |
449 var header = this.header; | |
450 var animateDuration = 200; | |
451 | |
452 if (header) { | |
453 // in tallMode it may add tallClass to the header; so do the cleanup | |
454 // when mode is changed from tallMode to not tallMode | |
455 if (configs.tallMode[oldMode] && !configs.tallMode[newMode]) { | |
456 header.classList.remove(this.tallClass); | |
457 this.async(function() { | |
458 header.classList.remove('animate'); | |
459 }, animateDuration); | |
460 } else { | |
461 header.classList.toggle('animate', configs.tallMode[newMode]); | |
462 } | |
463 } | |
464 this._keepScrollingState(); | |
465 }, | |
466 | |
467 _keepScrollingState: function () { | |
468 var main = this.scroller; | |
469 var header = this.header; | |
470 | |
471 this._setAtTop(main.scrollTop === 0); | |
472 | |
473 if (header && MODE_CONFIGS.tallMode[this.mode]) { | |
474 this.toggleClass(this.tallClass, this.atTop || | |
475 header.classList.contains(this.tallClass) && | |
476 main.scrollHeight < this.offsetHeight, header); | |
477 } | |
478 }, | |
479 | |
480 _scroll: function(e) { | |
481 this._keepScrollingState(); | |
482 this.fire('content-scroll', {target: this.scroller}, {bubbles: false}); | |
483 }, | |
484 | |
485 _getScrollerForMode: function(mode) { | |
486 return MODE_CONFIGS.outerScroll[mode] ? | |
487 this : this.$.mainContainer; | |
488 } | |
489 | |
490 }); | |
491 | |
492 })(); | |
493 | |
494 </script> | |
OLD | NEW |