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="../paper-styles/paper-styles.html"> |
| 12 |
| 13 <!-- |
| 14 `paper-toolbar` is a horizontal bar containing items that can be used for |
| 15 label, navigation, search and actions. The items place inside the |
| 16 `paper-toolbar` are projected into a `class="horizontal center layout"` containe
r inside of |
| 17 `paper-toolbar`'s Shadow DOM. You can use flex attributes to control the items' |
| 18 sizing. |
| 19 |
| 20 Example: |
| 21 |
| 22 <paper-toolbar> |
| 23 <paper-icon-button icon="menu" on-tap="menuAction"></paper-icon-button> |
| 24 <div class="title">Title</div> |
| 25 <paper-icon-button icon="more-vert" on-tap="moreAction"></paper-icon-butto
n> |
| 26 </paper-toolbar> |
| 27 |
| 28 `paper-toolbar` has a standard height, but can made be taller by setting `tall` |
| 29 class on the `paper-toolbar`. This will make the toolbar 3x the normal height. |
| 30 |
| 31 <paper-toolbar class="tall"> |
| 32 <paper-icon-button icon="menu"></paper-icon-button> |
| 33 </paper-toolbar> |
| 34 |
| 35 Apply `medium-tall` class to make the toolbar medium tall. This will make the |
| 36 toolbar 2x the normal height. |
| 37 |
| 38 <paper-toolbar class="medium-tall"> |
| 39 <paper-icon-button icon="menu"></paper-icon-button> |
| 40 </paper-toolbar> |
| 41 |
| 42 When `tall`, items can pin to either the top (default), middle or bottom. Use |
| 43 `middle` class for middle content and `bottom` class for bottom content. |
| 44 |
| 45 <paper-toolbar class="tall"> |
| 46 <paper-icon-button icon="menu"></paper-icon-button> |
| 47 <div class="middle title">Middle Title</div> |
| 48 <div class="bottom title">Bottom Title</div> |
| 49 </paper-toolbar> |
| 50 |
| 51 For `medium-tall` toolbar, the middle and bottom contents overlap and are |
| 52 pinned to the bottom. But `middleJustify` and `bottomJustify` attributes are |
| 53 still honored separately. |
| 54 |
| 55 ### Styling |
| 56 |
| 57 The following custom properties and mixins are available for styling: |
| 58 |
| 59 Custom property | Description | Default |
| 60 ----------------|-------------|---------- |
| 61 `--paper-toolbar-background` | Toolbar background color | `--default-primary
-color` |
| 62 `--paper-toolbar-color` | Toolbar foreground color | `--text-primary-co
lor` |
| 63 `--paper-toolbar` | Mixin applied to the toolbar | `{}` |
| 64 |
| 65 ### Accessibility |
| 66 |
| 67 `<paper-toolbar>` has `role="toolbar"` by default. Any elements with the class `
title` will |
| 68 be used as the label of the toolbar via `aria-labelledby`. |
| 69 |
| 70 @demo demo/index.html |
| 71 --> |
| 72 |
| 73 <dom-module id="paper-toolbar"> |
| 74 |
| 75 <style> |
| 76 :host { |
| 77 /* technical */ |
| 78 display: block; |
| 79 position: relative; |
| 80 box-sizing: border-box; |
| 81 -moz-box-sizing: border-box; |
| 82 |
| 83 /* size */ |
| 84 height: 64px; |
| 85 |
| 86 background: var(--paper-toolbar-background, --default-primary-color); |
| 87 color: var(--paper-toolbar-color, --text-primary-color); |
| 88 |
| 89 @apply(--paper-toolbar); |
| 90 } |
| 91 |
| 92 :host(.animate) { |
| 93 /* transition */ |
| 94 transition: height 0.18s ease-in; |
| 95 } |
| 96 |
| 97 :host(.medium-tall) { |
| 98 height: 128px; |
| 99 } |
| 100 |
| 101 :host(.tall) { |
| 102 height: 192px; |
| 103 } |
| 104 |
| 105 .toolbar-tools { |
| 106 position: relative; |
| 107 height: 64px; |
| 108 padding: 0 16px; |
| 109 pointer-events: none; |
| 110 } |
| 111 |
| 112 /* |
| 113 * TODO: Where should media query breakpoints live so they can be shared bet
ween elements? |
| 114 */ |
| 115 |
| 116 @media (max-width: 639px) { |
| 117 :host { |
| 118 height: 56px; |
| 119 } |
| 120 |
| 121 :host(.medium-tall) { |
| 122 height: 112px; |
| 123 } |
| 124 |
| 125 :host(.tall) { |
| 126 height: 168px; |
| 127 } |
| 128 |
| 129 .toolbar-tools { |
| 130 height: 56px; |
| 131 } |
| 132 } |
| 133 |
| 134 #topBar { |
| 135 position: relative; |
| 136 } |
| 137 |
| 138 /* middle bar */ |
| 139 #middleBar { |
| 140 position: absolute; |
| 141 top: 0; |
| 142 right: 0; |
| 143 left: 0; |
| 144 } |
| 145 |
| 146 :host(.tall) #middleBar, |
| 147 :host(.medium-tall) #middleBar { |
| 148 -webkit-transform: translateY(100%); |
| 149 transform: translateY(100%); |
| 150 } |
| 151 |
| 152 /* bottom bar */ |
| 153 #bottomBar { |
| 154 position: absolute; |
| 155 right: 0; |
| 156 bottom: 0; |
| 157 left: 0; |
| 158 } |
| 159 |
| 160 /* |
| 161 * make elements (e.g. buttons) respond to mouse/touch events |
| 162 * |
| 163 * `.toolbar-tools` disables touch events so multiple toolbars can stack and
not |
| 164 * absorb events. All children must have pointer events re-enabled to work a
s |
| 165 * expected. |
| 166 */ |
| 167 .toolbar-tools > ::content > *:not([disabled]) { |
| 168 pointer-events: auto; |
| 169 } |
| 170 |
| 171 .toolbar-tools > ::content .title { |
| 172 @apply(--paper-font-title); |
| 173 @apply(--layout-flex); |
| 174 |
| 175 pointer-events: none; |
| 176 text-overflow: ellipsis; |
| 177 white-space: nowrap; |
| 178 overflow: hidden; |
| 179 |
| 180 /* |
| 181 * Polymer/polymer/issues/1525 |
| 182 * --paper-font-title defines a `font-weight` |
| 183 * let's override its value, but we need `important!` |
| 184 * because all mixins are resolved in rule's selector that has higher prec
edence |
| 185 * than the current selector. |
| 186 */ |
| 187 font-weight: 400 !important; |
| 188 } |
| 189 |
| 190 /** |
| 191 * TODO: Refactor these selectors |
| 192 * Work in progress. |
| 193 */ |
| 194 .toolbar-tools > ::content paper-icon-button[icon=menu] { |
| 195 margin-right: 24px; |
| 196 } |
| 197 |
| 198 .toolbar-tools > ::content > .title, |
| 199 .toolbar-tools > ::content[select=".middle"] > .title, |
| 200 .toolbar-tools > ::content[select=".bottom"] > .title { |
| 201 margin-left: 56px; |
| 202 } |
| 203 |
| 204 .toolbar-tools > ::content > paper-icon-button + .title, |
| 205 .toolbar-tools > ::content[select=".middle"] paper-icon-button + .title, |
| 206 .toolbar-tools > ::content[select=".bottom"] paper-icon-button + .title { |
| 207 margin-left: 0; |
| 208 } |
| 209 </style> |
| 210 |
| 211 <template> |
| 212 |
| 213 <div id="topBar" class$="[[_computeBarClassName(justify)]]"> |
| 214 <content select=":not(.middle):not(.bottom)"></content> |
| 215 </div> |
| 216 |
| 217 <div id="middleBar" class$="[[_computeBarClassName(middleJustify)]]"> |
| 218 <content select=".middle"></content> |
| 219 </div> |
| 220 |
| 221 <div id="bottomBar" class$="[[_computeBarClassName(bottomJustify)]]"> |
| 222 <content select=".bottom"></content> |
| 223 </div> |
| 224 |
| 225 </template> |
| 226 |
| 227 </dom-module> |
| 228 |
| 229 <script> |
| 230 |
| 231 (function() { |
| 232 |
| 233 'use strict'; |
| 234 |
| 235 function classNames(obj) { |
| 236 var classNames = []; |
| 237 for (var key in obj) { |
| 238 if (obj.hasOwnProperty(key) && obj[key]) { |
| 239 classNames.push(key); |
| 240 } |
| 241 } |
| 242 |
| 243 return classNames.join(' '); |
| 244 } |
| 245 |
| 246 Polymer({ |
| 247 |
| 248 is: 'paper-toolbar', |
| 249 |
| 250 hostAttributes: { |
| 251 'role': 'toolbar' |
| 252 }, |
| 253 |
| 254 properties: { |
| 255 |
| 256 /** |
| 257 * Controls how the items are aligned horizontally when they are placed |
| 258 * at the bottom. |
| 259 * Options are `start`, `center`, `end`, `justified` and `around`. |
| 260 * |
| 261 * @attribute bottomJustify |
| 262 * @type string |
| 263 * @default '' |
| 264 */ |
| 265 bottomJustify: { |
| 266 type: String, |
| 267 value: '' |
| 268 }, |
| 269 |
| 270 /** |
| 271 * Controls how the items are aligned horizontally. |
| 272 * Options are `start`, `center`, `end`, `justified` and `around`. |
| 273 * |
| 274 * @attribute justify |
| 275 * @type string |
| 276 * @default '' |
| 277 */ |
| 278 justify: { |
| 279 type: String, |
| 280 value: '' |
| 281 }, |
| 282 |
| 283 /** |
| 284 * Controls how the items are aligned horizontally when they are placed |
| 285 * in the middle. |
| 286 * Options are `start`, `center`, `end`, `justified` and `around`. |
| 287 * |
| 288 * @attribute middleJustify |
| 289 * @type string |
| 290 * @default '' |
| 291 */ |
| 292 middleJustify: { |
| 293 type: String, |
| 294 value: '' |
| 295 } |
| 296 |
| 297 }, |
| 298 |
| 299 attached: function() { |
| 300 this._observer = this._observe(this); |
| 301 this._updateAriaLabelledBy(); |
| 302 }, |
| 303 |
| 304 detached: function() { |
| 305 if (this._observer) { |
| 306 this._observer.disconnect(); |
| 307 } |
| 308 }, |
| 309 |
| 310 _observe: function(node) { |
| 311 var observer = new MutationObserver(function() { |
| 312 this._updateAriaLabelledBy(); |
| 313 }.bind(this)); |
| 314 observer.observe(node, { |
| 315 childList: true, |
| 316 subtree: true |
| 317 }); |
| 318 return observer; |
| 319 }, |
| 320 |
| 321 _updateAriaLabelledBy: function() { |
| 322 var labelledBy = []; |
| 323 var contents = Polymer.dom(this.root).querySelectorAll('content'); |
| 324 for (var content, index = 0; content = contents[index]; index++) { |
| 325 var nodes = Polymer.dom(content).getDistributedNodes(); |
| 326 for (var node, jndex = 0; node = nodes[jndex]; jndex++) { |
| 327 if (node.classList && node.classList.contains('title')) { |
| 328 if (node.id) { |
| 329 labelledBy.push(node.id); |
| 330 } else { |
| 331 var id = 'paper-toolbar-label-' + Math.floor(Math.random() * 100
00); |
| 332 node.id = id; |
| 333 labelledBy.push(id); |
| 334 } |
| 335 } |
| 336 } |
| 337 } |
| 338 if (labelledBy.length > 0) { |
| 339 this.setAttribute('aria-labelledby', labelledBy.join(' ')); |
| 340 } |
| 341 }, |
| 342 |
| 343 _computeBarClassName: function(barJustify) { |
| 344 var classObj = { |
| 345 center: true, |
| 346 horizontal: true, |
| 347 layout: true, |
| 348 'toolbar-tools': true |
| 349 }; |
| 350 |
| 351 // If a blank string or any falsy value is given, no other class name is |
| 352 // added. |
| 353 if (barJustify) { |
| 354 var justifyClassName = (barJustify === 'justified') ? |
| 355 barJustify : |
| 356 barJustify + '-justified'; |
| 357 |
| 358 classObj[justifyClassName] = true; |
| 359 } |
| 360 |
| 361 return classNames(classObj); |
| 362 } |
| 363 |
| 364 }); |
| 365 |
| 366 }()); |
| 367 |
| 368 </script> |
OLD | NEW |