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