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 #mainContainer { |
| 131 @apply(--layout-flex); |
| 132 |
| 133 position: relative; |
| 134 overflow-y: auto; |
| 135 overflow-x: hidden; |
| 136 -webkit-overflow-scrolling: touch; |
| 137 flex-basis: 0.0001px; |
| 138 } |
| 139 |
| 140 /* |
| 141 * mode: scroll |
| 142 */ |
| 143 :host([mode=scroll]) #mainContainer { |
| 144 @apply(--paper-header-panel-scroll-container); |
| 145 overflow: visible; |
| 146 } |
| 147 |
| 148 :host([mode=scroll]) { |
| 149 overflow-y: auto; |
| 150 overflow-x: hidden; |
| 151 -webkit-overflow-scrolling: touch; |
| 152 } |
| 153 |
| 154 /* |
| 155 * mode: cover |
| 156 */ |
| 157 :host([mode=cover]) #mainContainer { |
| 158 @apply(--paper-header-panel-cover-container); |
| 159 position: absolute; |
| 160 top: 0; |
| 161 right: 0; |
| 162 bottom: 0; |
| 163 left: 0; |
| 164 } |
| 165 |
| 166 /* |
| 167 * mode: standard |
| 168 */ |
| 169 :host([mode=standard]) #mainContainer { |
| 170 @apply(--paper-header-panel-standard-container); |
| 171 } |
| 172 |
| 173 /* |
| 174 * mode: waterfall |
| 175 */ |
| 176 :host([mode=waterfall]) #mainContainer { |
| 177 @apply(--paper-header-panel-waterfall-container); |
| 178 } |
| 179 |
| 180 /* |
| 181 * mode: waterfall-tall |
| 182 */ |
| 183 :host([mode=waterfall-tall]) #mainContainer { |
| 184 @apply(--paper-header-panel-waterfall-tall-container); |
| 185 } |
| 186 |
| 187 :host ::content paper-toolbar, |
| 188 :host ::content .paper-header { |
| 189 position: relative; |
| 190 overflow: visible !important; |
| 191 } |
| 192 |
| 193 :host ::content paper-toolbar:after, |
| 194 :host ::content .paper-header:after { |
| 195 @apply(--paper-header-panel-shadow); |
| 196 |
| 197 -webkit-transition: opacity 0.5s, -webkit-transform 0.5s; |
| 198 transition: opacity 0.5s, transform 0.5s; |
| 199 |
| 200 opacity: 0; |
| 201 content: ""; |
| 202 |
| 203 width: 100%; |
| 204 position: absolute; |
| 205 left: 0px; |
| 206 right: 0px; |
| 207 z-index: 1; |
| 208 |
| 209 -webkit-transform: scale3d(1, 0, 1); |
| 210 -webkit-transform-origin: 0% 0%; |
| 211 |
| 212 transform: scale3d(1, 0, 1); |
| 213 transform-origin: 0% 0%; |
| 214 } |
| 215 |
| 216 :host ::content paper-toolbar.has-shadow:after, |
| 217 :host ::content .paper-header.has-shadow:after { |
| 218 opacity: 1; |
| 219 -webkit-transform: scale3d(1, 1, 1); |
| 220 transform: scale3d(1, 1, 1); |
| 221 } |
| 222 </style> |
| 223 |
| 224 <template> |
| 225 <content id="headerContent" select="paper-toolbar, .paper-header"></content> |
| 226 <div id="mainContainer" class$="[[_computeMainContainerClass(mode)]]"> |
| 227 <content id="mainContent" select="*"></content> |
| 228 </div> |
| 229 </template> |
| 230 |
| 231 </dom-module> |
| 232 |
| 233 <style is="custom-style"> |
| 234 :root { |
| 235 /** |
| 236 * Default paper header panel shadow |
| 237 */ |
| 238 --paper-header-panel-shadow: { |
| 239 height: 6px; |
| 240 bottom: -6px; |
| 241 box-shadow: inset 0px 5px 6px -3px rgba(0, 0, 0, 0.4); |
| 242 }; |
| 243 } |
| 244 </style> |
| 245 |
| 246 <script> |
| 247 |
| 248 (function() { |
| 249 |
| 250 'use strict'; |
| 251 |
| 252 var SHADOW_WHEN_SCROLLING = 1; |
| 253 var SHADOW_ALWAYS = 2; |
| 254 |
| 255 |
| 256 var MODE_CONFIGS = { |
| 257 |
| 258 outerScroll: { |
| 259 scroll: true |
| 260 }, |
| 261 |
| 262 shadowMode: { |
| 263 standard: SHADOW_ALWAYS, |
| 264 waterfall: SHADOW_WHEN_SCROLLING, |
| 265 'waterfall-tall': SHADOW_WHEN_SCROLLING |
| 266 }, |
| 267 |
| 268 tallMode: { |
| 269 'waterfall-tall': true |
| 270 } |
| 271 }; |
| 272 |
| 273 Polymer({ |
| 274 |
| 275 is: 'paper-header-panel', |
| 276 |
| 277 /** |
| 278 * Fired when the content has been scrolled. `event.detail.target` return
s |
| 279 * the scrollable element which you can use to access scroll info such as |
| 280 * `scrollTop`. |
| 281 * |
| 282 * <paper-header-panel on-content-scroll="{{scrollHandler}}"> |
| 283 * ... |
| 284 * </paper-header-panel> |
| 285 * |
| 286 * |
| 287 * scrollHandler: function(event) { |
| 288 * var scroller = event.detail.target; |
| 289 * console.log(scroller.scrollTop); |
| 290 * } |
| 291 * |
| 292 * @event content-scroll |
| 293 */ |
| 294 |
| 295 properties: { |
| 296 |
| 297 /** |
| 298 * Controls header and scrolling behavior. Options are |
| 299 * `standard`, `seamed`, `waterfall`, `waterfall-tall`, `scroll` and |
| 300 * `cover`. Default is `standard`. |
| 301 * |
| 302 * `standard`: The header is a step above the panel. The header will con
sume the |
| 303 * panel at the point of entry, preventing it from passing through to th
e |
| 304 * opposite side. |
| 305 * |
| 306 * `seamed`: The header is presented as seamed with the panel. |
| 307 * |
| 308 * `waterfall`: Similar to standard mode, but header is initially presen
ted as |
| 309 * seamed with panel, but then separates to form the step. |
| 310 * |
| 311 * `waterfall-tall`: The header is initially taller (`tall` class is add
ed to |
| 312 * the header). As the user scrolls, the header separates (forming an e
dge) |
| 313 * while condensing (`tall` class is removed from the header). |
| 314 * |
| 315 * `scroll`: The header keeps its seam with the panel, and is pushed off
screen. |
| 316 * |
| 317 * `cover`: The panel covers the whole `paper-header-panel` including th
e |
| 318 * header. This allows user to style the panel in such a way that the pa
nel is |
| 319 * partially covering the header. |
| 320 * |
| 321 * <paper-header-panel mode="cover"> |
| 322 * <paper-toolbar class="tall"> |
| 323 * <core-icon-button icon="menu"></core-icon-button> |
| 324 * </paper-toolbar> |
| 325 * <div class="content"></div> |
| 326 * </paper-header-panel> |
| 327 */ |
| 328 mode: { |
| 329 type: String, |
| 330 value: 'standard', |
| 331 observer: '_modeChanged', |
| 332 reflectToAttribute: true |
| 333 }, |
| 334 |
| 335 /** |
| 336 * If true, the drop-shadow is always shown no matter what mode is set t
o. |
| 337 */ |
| 338 shadow: { |
| 339 type: Boolean, |
| 340 value: false |
| 341 }, |
| 342 |
| 343 /** |
| 344 * The class used in waterfall-tall mode. Change this if the header |
| 345 * accepts a different class for toggling height, e.g. "medium-tall" |
| 346 */ |
| 347 tallClass: { |
| 348 type: String, |
| 349 value: 'tall' |
| 350 }, |
| 351 |
| 352 /** |
| 353 * If true, the scroller is at the top |
| 354 */ |
| 355 atTop: { |
| 356 type: Boolean, |
| 357 value: true, |
| 358 readOnly: true |
| 359 } |
| 360 }, |
| 361 |
| 362 observers: [ |
| 363 '_computeDropShadowHidden(atTop, mode, shadow)' |
| 364 ], |
| 365 |
| 366 ready: function() { |
| 367 this.scrollHandler = this._scroll.bind(this); |
| 368 this._addListener(); |
| 369 |
| 370 // Run `scroll` logic once to initialze class names, etc. |
| 371 this._keepScrollingState(); |
| 372 }, |
| 373 |
| 374 detached: function() { |
| 375 this._removeListener(); |
| 376 }, |
| 377 |
| 378 /** |
| 379 * Returns the header element |
| 380 * |
| 381 * @property header |
| 382 * @type Object |
| 383 */ |
| 384 get header() { |
| 385 return Polymer.dom(this.$.headerContent).getDistributedNodes()[0]; |
| 386 }, |
| 387 |
| 388 /** |
| 389 * Returns the scrollable element. |
| 390 * |
| 391 * @property scroller |
| 392 * @type Object |
| 393 */ |
| 394 get scroller() { |
| 395 return this._getScrollerForMode(this.mode); |
| 396 }, |
| 397 |
| 398 /** |
| 399 * Returns true if the scroller has a visible shadow. |
| 400 * |
| 401 * @property visibleShadow |
| 402 * @type Boolean |
| 403 */ |
| 404 get visibleShadow() { |
| 405 return this.header.classList.contains('has-shadow'); |
| 406 }, |
| 407 |
| 408 _computeDropShadowHidden: function(atTop, mode, shadow) { |
| 409 |
| 410 var shadowMode = MODE_CONFIGS.shadowMode[mode]; |
| 411 |
| 412 if (this.shadow) { |
| 413 this.toggleClass('has-shadow', true, this.header); |
| 414 |
| 415 } else if (shadowMode === SHADOW_ALWAYS) { |
| 416 this.toggleClass('has-shadow', true, this.header); |
| 417 |
| 418 } else if (shadowMode === SHADOW_WHEN_SCROLLING && !atTop) { |
| 419 this.toggleClass('has-shadow', true, this.header); |
| 420 |
| 421 } else { |
| 422 this.toggleClass('has-shadow', false, this.header); |
| 423 |
| 424 } |
| 425 }, |
| 426 |
| 427 _computeMainContainerClass: function(mode) { |
| 428 // TODO: It will be useful to have a utility for classes |
| 429 // e.g. Polymer.Utils.classes({ foo: true }); |
| 430 |
| 431 var classes = {}; |
| 432 |
| 433 classes['flex'] = mode !== 'cover'; |
| 434 |
| 435 return Object.keys(classes).filter( |
| 436 function(className) { |
| 437 return classes[className]; |
| 438 }).join(' '); |
| 439 }, |
| 440 |
| 441 _addListener: function() { |
| 442 this.scroller.addEventListener('scroll', this.scrollHandler, false); |
| 443 }, |
| 444 |
| 445 _removeListener: function() { |
| 446 this.scroller.removeEventListener('scroll', this.scrollHandler); |
| 447 }, |
| 448 |
| 449 _modeChanged: function(newMode, oldMode) { |
| 450 var configs = MODE_CONFIGS; |
| 451 var header = this.header; |
| 452 var animateDuration = 200; |
| 453 |
| 454 if (header) { |
| 455 // in tallMode it may add tallClass to the header; so do the cleanup |
| 456 // when mode is changed from tallMode to not tallMode |
| 457 if (configs.tallMode[oldMode] && !configs.tallMode[newMode]) { |
| 458 header.classList.remove(this.tallClass); |
| 459 this.async(function() { |
| 460 header.classList.remove('animate'); |
| 461 }, null, animateDuration); |
| 462 } else { |
| 463 header.classList.toggle('animate', configs.tallMode[newMode]); |
| 464 } |
| 465 } |
| 466 this._keepScrollingState(); |
| 467 }, |
| 468 |
| 469 _keepScrollingState: function () { |
| 470 var main = this.scroller; |
| 471 var header = this.header; |
| 472 |
| 473 this._setAtTop(main.scrollTop === 0); |
| 474 |
| 475 if (header && MODE_CONFIGS.tallMode[this.mode]) { |
| 476 this.toggleClass(this.tallClass, this.atTop || |
| 477 header.classList.contains(this.tallClass) && |
| 478 main.scrollHeight < this.offsetHeight, header); |
| 479 } |
| 480 }, |
| 481 |
| 482 _scroll: function(e) { |
| 483 this._keepScrollingState(); |
| 484 this.fire('content-scroll', {target: this.scroller}, this, false); |
| 485 }, |
| 486 |
| 487 _getScrollerForMode: function(mode) { |
| 488 return MODE_CONFIGS.outerScroll[mode] ? |
| 489 this : this.$.mainContainer; |
| 490 } |
| 491 |
| 492 }); |
| 493 |
| 494 })(); |
| 495 |
| 496 </script> |
OLD | NEW |