73bcce88
luigser
COMPONENTS
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
|
73bcce88
luigser
COMPONENTS
|
13
|
<link rel="import" href="../iron-icon/iron-icon.html">
|
a1a3bc73
Luigi Serra
graphs updates
|
14
15
|
<link rel="import" href="../iron-menu-behavior/iron-menubar-behavior.html">
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
|
73bcce88
luigser
COMPONENTS
|
16
17
18
19
20
21
|
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-styles/color.html">
<link rel="import" href="paper-tabs-icons.html">
<link rel="import" href="paper-tab.html">
<!--
|
eb240478
Luigi Serra
public room cards...
|
22
23
|
Material design: [Tabs](https://www.google.com/design/spec/components/tabs.html)
|
73bcce88
luigser
COMPONENTS
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
`paper-tabs` makes it easy to explore and switch between different views or functional aspects of
an app, or to browse categorized data sets.
Use `selected` property to get or set the selected tab.
Example:
<paper-tabs selected="0">
<paper-tab>TAB 1</paper-tab>
<paper-tab>TAB 2</paper-tab>
<paper-tab>TAB 3</paper-tab>
</paper-tabs>
See <a href="#paper-tab">paper-tab</a> for more information about
`paper-tab`.
A common usage for `paper-tabs` is to use it along with `iron-pages` to switch
between different views.
<paper-tabs selected="{{selected}}">
<paper-tab>Tab 1</paper-tab>
<paper-tab>Tab 2</paper-tab>
<paper-tab>Tab 3</paper-tab>
</paper-tabs>
<iron-pages selected="{{selected}}">
<div>Page 1</div>
<div>Page 2</div>
<div>Page 3</div>
</iron-pages>
To use links in tabs, add `link` attribute to `paper-tab` and put an `<a>`
element in `paper-tab`.
Example:
|
a1a3bc73
Luigi Serra
graphs updates
|
61
62
63
64
65
66
67
|
<style is="custom-style">
.link {
@apply(--layout-horizontal);
@apply(--layout-center-center);
}
</style>
|
73bcce88
luigser
COMPONENTS
|
68
69
|
<paper-tabs selected="0">
<paper-tab link>
|
a1a3bc73
Luigi Serra
graphs updates
|
70
|
<a href="#link1" class="link">TAB ONE</a>
|
73bcce88
luigser
COMPONENTS
|
71
72
|
</paper-tab>
<paper-tab link>
|
a1a3bc73
Luigi Serra
graphs updates
|
73
|
<a href="#link2" class="link">TAB TWO</a>
|
73bcce88
luigser
COMPONENTS
|
74
75
|
</paper-tab>
<paper-tab link>
|
a1a3bc73
Luigi Serra
graphs updates
|
76
|
<a href="#link3" class="link">TAB THREE</a>
|
73bcce88
luigser
COMPONENTS
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
</paper-tab>
</paper-tabs>
### Styling
The following custom properties and mixins are available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--paper-tabs-selection-bar-color` | Color for the selection bar | `--paper-yellow-a100`
`--paper-tabs` | Mixin applied to the tabs | `{}`
@hero hero.svg
@demo demo/index.html
-->
<dom-module id="paper-tabs">
|
a1a3bc73
Luigi Serra
graphs updates
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<template>
<style>
:host {
@apply(--layout);
@apply(--layout-center);
height: 48px;
font-size: 14px;
font-weight: 500;
overflow: hidden;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
@apply(--paper-tabs);
}
|
73bcce88
luigser
COMPONENTS
|
112
|
|
a1a3bc73
Luigi Serra
graphs updates
|
113
114
115
|
:host-context([dir=rtl]) {
@apply(--layout-horizontal-reverse);
}
|
73bcce88
luigser
COMPONENTS
|
116
|
|
a1a3bc73
Luigi Serra
graphs updates
|
117
118
119
120
121
122
123
|
#tabsContainer {
position: relative;
height: 100%;
white-space: nowrap;
overflow: hidden;
@apply(--layout-flex);
}
|
73bcce88
luigser
COMPONENTS
|
124
|
|
a1a3bc73
Luigi Serra
graphs updates
|
125
126
127
|
#tabsContent {
height: 100%;
}
|
73bcce88
luigser
COMPONENTS
|
128
|
|
a1a3bc73
Luigi Serra
graphs updates
|
129
130
131
132
|
#tabsContent.scrollable {
position: absolute;
white-space: nowrap;
}
|
73bcce88
luigser
COMPONENTS
|
133
|
|
a1a3bc73
Luigi Serra
graphs updates
|
134
135
136
|
#tabsContent.horizontal {
@apply(--layout-horizontal);
}
|
73bcce88
luigser
COMPONENTS
|
137
|
|
a1a3bc73
Luigi Serra
graphs updates
|
138
139
140
|
.hidden {
display: none;
}
|
73bcce88
luigser
COMPONENTS
|
141
|
|
a1a3bc73
Luigi Serra
graphs updates
|
142
143
144
145
|
.not-visible {
opacity: 0;
cursor: default;
}
|
73bcce88
luigser
COMPONENTS
|
146
|
|
a1a3bc73
Luigi Serra
graphs updates
|
147
148
149
150
151
152
|
paper-icon-button {
width: 48px;
height: 48px;
padding: 12px;
margin: 0 4px;
}
|
73bcce88
luigser
COMPONENTS
|
153
|
|
a1a3bc73
Luigi Serra
graphs updates
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#selectionBar {
position: absolute;
height: 2px;
bottom: 0;
left: 0;
right: 0;
background-color: var(--paper-tabs-selection-bar-color, --paper-yellow-a100);
-webkit-transform: scale(0);
transform: scale(0);
-webkit-transform-origin: left center;
transform-origin: left center;
transition: -webkit-transform;
transition: transform;
@apply(--paper-tabs-selection-bar);
}
|
73bcce88
luigser
COMPONENTS
|
170
|
|
a1a3bc73
Luigi Serra
graphs updates
|
171
172
173
174
|
#selectionBar.align-bottom {
top: 0;
bottom: auto;
}
|
73bcce88
luigser
COMPONENTS
|
175
|
|
a1a3bc73
Luigi Serra
graphs updates
|
176
177
178
179
|
#selectionBar.expand {
transition-duration: 0.15s;
transition-timing-function: cubic-bezier(0.4, 0.0, 1, 1);
}
|
73bcce88
luigser
COMPONENTS
|
180
|
|
a1a3bc73
Luigi Serra
graphs updates
|
181
182
183
184
|
#selectionBar.contract {
transition-duration: 0.18s;
transition-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1);
}
|
73bcce88
luigser
COMPONENTS
|
185
|
|
a1a3bc73
Luigi Serra
graphs updates
|
186
187
188
189
|
#tabsContent > ::content > *:not(#selectionBar) {
height: 100%;
}
</style>
|
73bcce88
luigser
COMPONENTS
|
190
|
|
a1a3bc73
Luigi Serra
graphs updates
|
191
|
<paper-icon-button icon="paper-tabs:chevron-left" class$="[[_computeScrollButtonClass(_leftHidden, scrollable, hideScrollButtons)]]" on-up="_onScrollButtonUp" on-down="_onLeftScrollButtonDown" tabindex="-1"></paper-icon-button>
|
73bcce88
luigser
COMPONENTS
|
192
|
|
a1a3bc73
Luigi Serra
graphs updates
|
193
194
195
196
197
198
199
|
<div id="tabsContainer" on-track="_scroll" on-down="_down">
<div id="tabsContent" class$="[[_computeTabsContentClass(scrollable)]]">
<content select="*"></content>
<div id="selectionBar" class$="[[_computeSelectionBarClass(noBar, alignBottom)]]"
on-transitionend="_onBarTransitionEnd"></div>
</div>
</div>
|
73bcce88
luigser
COMPONENTS
|
200
|
|
a1a3bc73
Luigi Serra
graphs updates
|
201
|
<paper-icon-button icon="paper-tabs:chevron-right" class$="[[_computeScrollButtonClass(_rightHidden, scrollable, hideScrollButtons)]]" on-up="_onScrollButtonUp" on-down="_onRightScrollButtonDown" tabindex="-1"></paper-icon-button>
|
73bcce88
luigser
COMPONENTS
|
202
|
|
a1a3bc73
Luigi Serra
graphs updates
|
203
|
</template>
|
73bcce88
luigser
COMPONENTS
|
204
|
|
a1a3bc73
Luigi Serra
graphs updates
|
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
<script>
Polymer({
is: 'paper-tabs',
behaviors: [
Polymer.IronResizableBehavior,
Polymer.IronMenubarBehavior
],
properties: {
/**
* If true, ink ripple effect is disabled. When this property is changed,
* all descendant `<paper-tab>` elements have their `noink` property
* changed to the new value as well.
*/
noink: {
type: Boolean,
value: false,
observer: '_noinkChanged'
},
/**
* If true, the bottom bar to indicate the selected tab will not be shown.
*/
noBar: {
type: Boolean,
value: false
},
/**
* If true, the slide effect for the bottom bar is disabled.
*/
noSlide: {
type: Boolean,
value: false
},
/**
* If true, tabs are scrollable and the tab width is based on the label width.
*/
scrollable: {
type: Boolean,
value: false
},
/**
* If true, dragging on the tabs to scroll is disabled.
*/
disableDrag: {
type: Boolean,
value: false
},
/**
* If true, scroll buttons (left/right arrow) will be hidden for scrollable tabs.
*/
hideScrollButtons: {
type: Boolean,
value: false
},
/**
* If true, the tabs are aligned to bottom (the selection bar appears at the top).
*/
alignBottom: {
type: Boolean,
value: false
},
/**
* Gets or sets the selected element. The default is to use the index of the item.
*/
selected: {
type: String,
notify: true
},
selectable: {
type: String,
value: 'paper-tab'
},
_step: {
type: Number,
value: 10
},
_holdDelay: {
type: Number,
value: 1
},
_leftHidden: {
type: Boolean,
value: false
},
_rightHidden: {
type: Boolean,
value: false
},
_previousTab: {
type: Object
}
|
73bcce88
luigser
COMPONENTS
|
310
311
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
312
313
|
hostAttributes: {
role: 'tablist'
|
73bcce88
luigser
COMPONENTS
|
314
315
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
316
317
318
319
|
listeners: {
'iron-resize': '_onResize',
'iron-select': '_onIronSelect',
'iron-deselect': '_onIronDeselect'
|
73bcce88
luigser
COMPONENTS
|
320
321
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
322
323
|
created: function() {
this._holdJob = null;
|
73bcce88
luigser
COMPONENTS
|
324
325
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
326
327
|
ready: function() {
this.setScrollDirection('y', this.$.tabsContainer);
|
73bcce88
luigser
COMPONENTS
|
328
329
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
330
331
332
|
_noinkChanged: function(noink) {
var childTabs = Polymer.dom(this).querySelectorAll('paper-tab');
childTabs.forEach(noink ? this._setNoinkAttribute : this._removeNoinkAttribute);
|
73bcce88
luigser
COMPONENTS
|
333
334
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
335
336
|
_setNoinkAttribute: function(element) {
element.setAttribute('noink', '');
|
73bcce88
luigser
COMPONENTS
|
337
338
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
339
340
|
_removeNoinkAttribute: function(element) {
element.removeAttribute('noink');
|
73bcce88
luigser
COMPONENTS
|
341
342
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
343
344
345
346
|
_computeScrollButtonClass: function(hideThisButton, scrollable, hideScrollButtons) {
if (!scrollable || hideScrollButtons) {
return 'hidden';
}
|
73bcce88
luigser
COMPONENTS
|
347
|
|
a1a3bc73
Luigi Serra
graphs updates
|
348
349
350
|
if (hideThisButton) {
return 'not-visible';
}
|
73bcce88
luigser
COMPONENTS
|
351
|
|
a1a3bc73
Luigi Serra
graphs updates
|
352
|
return '';
|
73bcce88
luigser
COMPONENTS
|
353
354
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
355
356
|
_computeTabsContentClass: function(scrollable) {
return scrollable ? 'scrollable' : 'horizontal';
|
73bcce88
luigser
COMPONENTS
|
357
358
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
359
360
361
362
363
364
365
366
|
_computeSelectionBarClass: function(noBar, alignBottom) {
if (noBar) {
return 'hidden';
} else if (alignBottom) {
return 'align-bottom';
}
return '';
|
73bcce88
luigser
COMPONENTS
|
367
368
|
},
|
a1a3bc73
Luigi Serra
graphs updates
|
369
|
// TODO(cdata): Add `track` response back in when gesture lands.
|
73bcce88
luigser
COMPONENTS
|
370
|
|
a1a3bc73
Luigi Serra
graphs updates
|
371
372
373
374
375
376
|
_onResize: function() {
this.debounce('_onResize', function() {
this._scroll();
this._tabChanged(this.selectedItem);
}, 10);
},
|
73bcce88
luigser
COMPONENTS
|
377
|
|
a1a3bc73
Luigi Serra
graphs updates
|
378
379
380
381
382
|
_onIronSelect: function(event) {
this._tabChanged(event.detail.item, this._previousTab);
this._previousTab = event.detail.item;
this.cancelDebouncer('tab-changed');
},
|
73bcce88
luigser
COMPONENTS
|
383
|
|
a1a3bc73
Luigi Serra
graphs updates
|
384
385
386
387
388
389
|
_onIronDeselect: function(event) {
this.debounce('tab-changed', function() {
this._tabChanged(null, this._previousTab);
// See polymer/polymer#1305
}, 1);
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
390
|
|
a1a3bc73
Luigi Serra
graphs updates
|
391
392
393
394
395
396
397
|
get _tabContainerScrollSize () {
return Math.max(
0,
this.$.tabsContainer.scrollWidth -
this.$.tabsContainer.offsetWidth
);
},
|
73bcce88
luigser
COMPONENTS
|
398
|
|
73bcce88
luigser
COMPONENTS
|
399
|
|
a1a3bc73
Luigi Serra
graphs updates
|
400
401
402
403
|
_scroll: function(e, detail) {
if (!this.scrollable) {
return;
}
|
73bcce88
luigser
COMPONENTS
|
404
|
|
a1a3bc73
Luigi Serra
graphs updates
|
405
406
407
|
var ddx = (detail && -detail.ddx) || 0;
this._affectScroll(ddx);
},
|
73bcce88
luigser
COMPONENTS
|
408
|
|
a1a3bc73
Luigi Serra
graphs updates
|
409
410
411
412
413
414
415
416
417
418
|
_down: function(e) {
// go one beat async to defeat IronMenuBehavior
// autorefocus-on-no-selection timeout
this.async(function() {
if (this._defaultFocusAsync) {
this.cancelAsync(this._defaultFocusAsync);
this._defaultFocusAsync = null;
}
}, 1);
},
|
73bcce88
luigser
COMPONENTS
|
419
|
|
a1a3bc73
Luigi Serra
graphs updates
|
420
421
|
_affectScroll: function(dx) {
this.$.tabsContainer.scrollLeft += dx;
|
e619a3b0
Luigi Serra
Controllet cross ...
|
422
|
|
a1a3bc73
Luigi Serra
graphs updates
|
423
|
var scrollLeft = this.$.tabsContainer.scrollLeft;
|
e619a3b0
Luigi Serra
Controllet cross ...
|
424
|
|
a1a3bc73
Luigi Serra
graphs updates
|
425
426
427
|
this._leftHidden = scrollLeft === 0;
this._rightHidden = scrollLeft === this._tabContainerScrollSize;
},
|
73bcce88
luigser
COMPONENTS
|
428
|
|
a1a3bc73
Luigi Serra
graphs updates
|
429
430
431
432
|
_onLeftScrollButtonDown: function() {
this._scrollToLeft();
this._holdJob = setInterval(this._scrollToLeft.bind(this), this._holdDelay);
},
|
73bcce88
luigser
COMPONENTS
|
433
|
|
a1a3bc73
Luigi Serra
graphs updates
|
434
435
436
437
|
_onRightScrollButtonDown: function() {
this._scrollToRight();
this._holdJob = setInterval(this._scrollToRight.bind(this), this._holdDelay);
},
|
73bcce88
luigser
COMPONENTS
|
438
|
|
a1a3bc73
Luigi Serra
graphs updates
|
439
440
441
442
|
_onScrollButtonUp: function() {
clearInterval(this._holdJob);
this._holdJob = null;
},
|
73bcce88
luigser
COMPONENTS
|
443
|
|
a1a3bc73
Luigi Serra
graphs updates
|
444
445
446
|
_scrollToLeft: function() {
this._affectScroll(-this._step);
},
|
73bcce88
luigser
COMPONENTS
|
447
|
|
a1a3bc73
Luigi Serra
graphs updates
|
448
449
450
|
_scrollToRight: function() {
this._affectScroll(this._step);
},
|
73bcce88
luigser
COMPONENTS
|
451
|
|
a1a3bc73
Luigi Serra
graphs updates
|
452
453
454
455
456
|
_tabChanged: function(tab, old) {
if (!tab) {
this._positionBar(0, 0);
return;
}
|
73bcce88
luigser
COMPONENTS
|
457
|
|
a1a3bc73
Luigi Serra
graphs updates
|
458
459
460
461
|
var r = this.$.tabsContent.getBoundingClientRect();
var w = r.width;
var tabRect = tab.getBoundingClientRect();
var tabOffsetLeft = tabRect.left - r.left;
|
73bcce88
luigser
COMPONENTS
|
462
|
|
a1a3bc73
Luigi Serra
graphs updates
|
463
464
465
466
|
this._pos = {
width: this._calcPercent(tabRect.width, w),
left: this._calcPercent(tabOffsetLeft, w)
};
|
73bcce88
luigser
COMPONENTS
|
467
|
|
a1a3bc73
Luigi Serra
graphs updates
|
468
469
470
471
472
|
if (this.noSlide || old == null) {
// position bar directly without animation
this._positionBar(this._pos.width, this._pos.left);
return;
}
|
73bcce88
luigser
COMPONENTS
|
473
|
|
a1a3bc73
Luigi Serra
graphs updates
|
474
475
476
477
|
var oldRect = old.getBoundingClientRect();
var oldIndex = this.items.indexOf(old);
var index = this.items.indexOf(tab);
var m = 5;
|
73bcce88
luigser
COMPONENTS
|
478
|
|
a1a3bc73
Luigi Serra
graphs updates
|
479
480
|
// bar animation: expand
this.$.selectionBar.classList.add('expand');
|
73bcce88
luigser
COMPONENTS
|
481
|
|
a1a3bc73
Luigi Serra
graphs updates
|
482
483
484
485
486
487
488
|
if (oldIndex < index) {
this._positionBar(this._calcPercent(tabRect.left + tabRect.width - oldRect.left, w) - m,
this._left);
} else {
this._positionBar(this._calcPercent(oldRect.left + oldRect.width - tabRect.left, w) - m,
this._calcPercent(tabOffsetLeft, w) + m);
}
|
73bcce88
luigser
COMPONENTS
|
489
|
|
a1a3bc73
Luigi Serra
graphs updates
|
490
491
492
493
|
if (this.scrollable) {
this._scrollToSelectedIfNeeded(tabRect.width, tabOffsetLeft);
}
},
|
73bcce88
luigser
COMPONENTS
|
494
|
|
a1a3bc73
Luigi Serra
graphs updates
|
495
496
497
|
_scrollToSelectedIfNeeded: function(tabWidth, tabOffsetLeft) {
var l = tabOffsetLeft - this.$.tabsContainer.scrollLeft;
if (l < 0) {
|
73bcce88
luigser
COMPONENTS
|
498
|
this.$.tabsContainer.scrollLeft += l;
|
a1a3bc73
Luigi Serra
graphs updates
|
499
500
501
502
503
|
} else {
l += (tabWidth - this.$.tabsContainer.offsetWidth);
if (l > 0) {
this.$.tabsContainer.scrollLeft += l;
}
|
73bcce88
luigser
COMPONENTS
|
504
|
}
|
a1a3bc73
Luigi Serra
graphs updates
|
505
506
507
508
509
|
},
_calcPercent: function(w, w0) {
return 100 * w / w0;
},
|
73bcce88
luigser
COMPONENTS
|
510
|
|
a1a3bc73
Luigi Serra
graphs updates
|
511
512
513
|
_positionBar: function(width, left) {
width = width || 0;
left = left || 0;
|
73bcce88
luigser
COMPONENTS
|
514
|
|
a1a3bc73
Luigi Serra
graphs updates
|
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
this._width = width;
this._left = left;
this.transform(
'translate3d(' + left + '%, 0, 0) scaleX(' + (width / 100) + ')',
this.$.selectionBar);
},
_onBarTransitionEnd: function(e) {
var cl = this.$.selectionBar.classList;
// bar animation: expand -> contract
if (cl.contains('expand')) {
cl.remove('expand');
cl.add('contract');
this._positionBar(this._pos.width, this._pos.left);
// bar animation done
} else if (cl.contains('contract')) {
cl.remove('contract');
}
}
});
</script>
</dom-module>
|