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.github.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/CONTRIBUTORS.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/PATENTS.txt
10
<link rel="import" href="../polymer/polymer.html">
11
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
14
`paper-header-panel` contains a header section and a content panel section.
16
__Important:__ The `paper-header-panel` will not display if its parent does not have a height.
18
Using layout classes, you can make the `paper-header-panel` fill the screen
20
<body class="fullbleed layout vertical">
21
<paper-header-panel class="flex">
23
<div>Hello World!</div>
28
Special support is provided for scrolling modes when one uses a paper-toolbar or equivalent for the
34
<paper-toolbar>Header</paper-toolbar>
35
<div>Content goes here...</div>
38
If you want to use other than `paper-toolbar` for the header, add `paper-header` class to that
44
<div class="paper-header">Header</div>
45
<div>Content goes here...</div>
48
To have the content fit to the main area, use the `fit` class.
51
<div class="paper-header">standard</div>
52
<div class="fit">content fits 100% below the header</div>
57
Controls header and scrolling behavior. Options are `standard`, `seamed`, `waterfall`, `waterfall-tall`, `scroll` and
58
`cover`. Default is `standard`.
61
----------------|-------------
62
`standard` | The header is a step above the panel. The header will consume the panel at the point of entry, preventing it from passing through to the opposite side.
63
`seamed` | The header is presented as seamed with the panel.
64
`waterfall` | Similar to standard mode, but header is initially presented as seamed 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 condensing (`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 covering the header.
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>
79
To change the shadow that shows up underneath the header:
82
--paper-header-panel-shadow: {
85
box-shadow: inset 0px 5px 6px -3px rgba(0, 0, 0, 0.4);
89
To change the panel container in different modes:
92
--paper-header-panel-standard-container: {
93
border: 1px solid gray;
96
--paper-header-panel-seamed-container: {
97
border: 1px solid gray;
100
--paper-header-panel-waterfall-container: {
101
border: 1px solid gray;
104
--paper-header-panel-waterfall-tall-container: {
105
border: 1px solid gray;
108
--paper-header-panel-scroll-container: {
109
border: 1px solid gray;
112
--paper-header-panel-cover-container: {
113
border: 1px solid gray;
117
The following custom properties and mixins are available for styling:
119
Custom property | Description | Default
120
----------------|-------------|----------
121
`--paper-header-panel` | Mixin applied to the element | `{}`
122
`--paper-header-panel-body` | Mixin applied to the element's body (i.e. everything below the toolbar) | `{}`
123
`--paper-header-panel-scroll-container` | Mixin applied to the container when in scroll mode | `{}`
124
`--paper-header-panel-cover-container` | Mixin applied to the container when in cover mode | `{}`
125
`--paper-header-panel-standard-container` | Mixin applied to the container when in standard mode | `{}`
126
`--paper-header-panel-seamed-container` | Mixin applied to the container when in seamed mode | `{}`
127
`--paper-header-panel-waterfall-container` | Mixin applied to the container when in waterfall mode | `{}`
128
`--paper-header-panel-waterfall-tall-container` | Mixin applied to the container when in tall waterfall mode | `{}`
129
`--paper-header-panel-shadow` | Mixin applied to the waterfall shadow | `{}`
131
@group Paper Elements
132
@element paper-header-panel
133
@demo demo/index.html
137
<dom-module id="paper-header-panel">
141
@apply(--layout-vertical);
146
@apply(--paper-header-panel);
150
@apply(--layout-flex);
155
-webkit-overflow-scrolling: touch;
159
@apply(--layout-vertical);
160
@apply(--layout-flex);
165
@apply(--paper-header-panel-body);
171
:host([mode=scroll]) #mainContainer {
172
@apply(--paper-header-panel-scroll-container);
177
:host([mode=scroll]) {
180
-webkit-overflow-scrolling: touch;
186
:host([mode=cover]) #mainContainer {
187
@apply(--paper-header-panel-cover-container);
196
:host([mode=cover]) #mainPanel {
203
:host([mode=standard]) #mainContainer {
204
@apply(--paper-header-panel-standard-container);
210
:host([mode=seamed]) #mainContainer {
211
@apply(--paper-header-panel-seamed-container);
218
:host([mode=waterfall]) #mainContainer {
219
@apply(--paper-header-panel-waterfall-container);
223
* mode: waterfall-tall
225
:host([mode=waterfall-tall]) #mainContainer {
226
@apply(--paper-header-panel-waterfall-tall-container);
230
transition: opacity 0.5s;
232
box-shadow: inset 0px 5px 6px -3px rgba(0, 0, 0, 0.4);
234
@apply(--paper-header-panel-shadow);
241
pointer-events: none;
244
#dropShadow.has-shadow {
249
<content id="headerContent" select="paper-toolbar, .paper-header"></content>
252
<div id="mainContainer" class$="[[_computeMainContainerClass(mode)]]">
253
<content id="mainContent" select="*"></content>
255
<div id="dropShadow"></div>
263
var SHADOW_WHEN_SCROLLING = 1;
264
var SHADOW_ALWAYS = 2;
271
'standard': SHADOW_ALWAYS,
272
'waterfall': SHADOW_WHEN_SCROLLING,
273
'waterfall-tall': SHADOW_WHEN_SCROLLING
277
'waterfall-tall': true
282
is: 'paper-header-panel',
285
* Fired when the content has been scrolled. `event.detail.target` returns
286
* the scrollable element which you can use to access scroll info such as
289
* <paper-header-panel on-content-scroll="scrollHandler">
291
* </paper-header-panel>
294
* scrollHandler: function(event) {
295
* var scroller = event.detail.target;
296
* console.log(scroller.scrollTop);
299
* @event content-scroll
304
* Controls header and scrolling behavior. Options are
305
* `standard`, `seamed`, `waterfall`, `waterfall-tall`, `scroll` and
306
* `cover`. Default is `standard`.
308
* `standard`: The header is a step above the panel. The header will consume the
309
* panel at the point of entry, preventing it from passing through to the
312
* `seamed`: The header is presented as seamed with the panel.
314
* `waterfall`: Similar to standard mode, but header is initially presented as
315
* seamed with panel, but then separates to form the step.
317
* `waterfall-tall`: The header is initially taller (`tall` class is added to
318
* the header). As the user scrolls, the header separates (forming an edge)
319
* while condensing (`tall` class is removed from the header).
321
* `scroll`: The header keeps its seam with the panel, and is pushed off screen.
323
* `cover`: The panel covers the whole `paper-header-panel` including the
324
* header. This allows user to style the panel in such a way that the panel is
325
* partially covering the header.
327
* <paper-header-panel mode="cover">
328
* <paper-toolbar class="tall">
329
* <paper-icon-button icon="menu"></paper-icon-button>
331
* <div class="content"></div>
332
* </paper-header-panel>
337
observer: '_modeChanged',
338
reflectToAttribute: true
342
* If true, the drop-shadow is always shown no matter what mode is set to.
350
* The class used in waterfall-tall mode. Change this if the header
351
* accepts a different class for toggling height, e.g. "medium-tall"
359
* If true, the scroller is at the top
366
reflectToAttribute: true
371
'_computeDropShadowHidden(atTop, mode, shadow)'
375
this.scrollHandler = this._scroll.bind(this);
378
attached: function() {
380
// Run `scroll` logic once to initialize class names, etc.
381
this._keepScrollingState();
384
detached: function() {
385
this._removeListener();
389
* Returns the header element
395
return Polymer.dom(this.$.headerContent).getDistributedNodes()[0];
399
* Returns the scrollable element.
405
return this._getScrollerForMode(this.mode);
409
* Returns true if the scroller has a visible shadow.
411
* @property visibleShadow
414
get visibleShadow() {
415
return this.$.dropShadow.classList.contains('has-shadow');
418
_computeDropShadowHidden: function(atTop, mode, shadow) {
419
var shadowMode = MODE_CONFIGS.shadowMode[mode];
422
this.toggleClass('has-shadow', true, this.$.dropShadow);
423
} else if (shadowMode === SHADOW_ALWAYS) {
424
this.toggleClass('has-shadow', true, this.$.dropShadow);
425
} else if (shadowMode === SHADOW_WHEN_SCROLLING && !atTop) {
426
this.toggleClass('has-shadow', true, this.$.dropShadow);
428
this.toggleClass('has-shadow', false, this.$.dropShadow);
432
_computeMainContainerClass: function(mode) {
433
// TODO: It will be useful to have a utility for classes
434
// e.g. Polymer.Utils.classes({ foo: true });
438
classes['flex'] = mode !== 'cover';
440
return Object.keys(classes).filter(
441
function(className) {
442
return classes[className];
446
_addListener: function() {
447
this.scroller.addEventListener('scroll', this.scrollHandler, false);
450
_removeListener: function() {
451
this.scroller.removeEventListener('scroll', this.scrollHandler);
454
_modeChanged: function(newMode, oldMode) {
455
var configs = MODE_CONFIGS;
456
var header = this.header;
457
var animateDuration = 200;
460
// in tallMode it may add tallClass to the header; so do the cleanup
461
// when mode is changed from tallMode to not tallMode
462
if (configs.tallMode[oldMode] && !configs.tallMode[newMode]) {
463
header.classList.remove(this.tallClass);
464
this.async(function() {
465
header.classList.remove('animate');
468
header.classList.toggle('animate', configs.tallMode[newMode]);
471
this._keepScrollingState();
474
_keepScrollingState: function() {
475
var main = this.scroller;
476
var header = this.header;
478
this._setAtTop(main.scrollTop === 0);
480
if (header && this.tallClass && MODE_CONFIGS.tallMode[this.mode]) {
481
this.toggleClass(this.tallClass, this.atTop ||
482
header.classList.contains(this.tallClass) &&
483
main.scrollHeight < this.offsetHeight, header);
487
_scroll: function() {
488
this._keepScrollingState();
489
this.fire('content-scroll', {target: this.scroller}, {bubbles: false});
492
_getScrollerForMode: function(mode) {
493
return MODE_CONFIGS.outerScroll[mode] ?
494
this : this.$.mainContainer;