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">
|
c5169e0e
Renato De Donato
a new hope
|
13
|
<link rel="import" href="../iron-flex-layout/classes/iron-flex-layout.html">
|
a1a3bc73
Luigi Serra
graphs updates
|
14
|
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
|
c5169e0e
Renato De Donato
a new hope
|
15
16
|
<link rel="import" href="../iron-menu-behavior/iron-menubar-behavior.html">
<link rel="import" href="../iron-icon/iron-icon.html">
|
73bcce88
luigser
COMPONENTS
|
17
18
19
20
21
22
|
<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...
|
23
24
|
Material design: [Tabs](https://www.google.com/design/spec/components/tabs.html)
|
73bcce88
luigser
COMPONENTS
|
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
61
|
`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:
|
73bcce88
luigser
COMPONENTS
|
62
63
|
<paper-tabs selected="0">
<paper-tab link>
|
c5169e0e
Renato De Donato
a new hope
|
64
|
<a href="#link1" class="horizontal center-center layout">TAB ONE</a>
|
73bcce88
luigser
COMPONENTS
|
65
66
|
</paper-tab>
<paper-tab link>
|
c5169e0e
Renato De Donato
a new hope
|
67
|
<a href="#link2" class="horizontal center-center layout">TAB TWO</a>
|
73bcce88
luigser
COMPONENTS
|
68
69
|
</paper-tab>
<paper-tab link>
|
c5169e0e
Renato De Donato
a new hope
|
70
|
<a href="#link3" class="horizontal center-center layout">TAB THREE</a>
|
73bcce88
luigser
COMPONENTS
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
</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">
|
73bcce88
luigser
COMPONENTS
|
88
|
|
c5169e0e
Renato De Donato
a new hope
|
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
<style>
:host {
@apply(--layout);
@apply(--layout-center);
height: 48px;
font-size: 14px;
font-weight: 500;
overflow: hidden;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
@apply(--paper-tabs);
}
#tabsContainer {
position: relative;
height: 100%;
white-space: nowrap;
overflow: hidden;
}
#tabsContent {
height: 100%;
}
#tabsContent.scrollable {
position: absolute;
white-space: nowrap;
}
.hidden {
display: none;
}
.not-visible {
opacity: 0;
cursor: default;
}
paper-icon-button {
width: 24px;
padding: 16px;
}
#selectionBar {
position: absolute;
height: 2px;
bottom: 0;
left: 0;
right: 0;
background-color: var(--paper-tabs-selection-bar-color, --paper-yellow-a100);
-webkit-transform-origin: left center;
transform-origin: left center;
-webkit-transform: scale(0);
transform: scale(0);
transition: -webkit-transform;
transition: transform;
@apply(--paper-tabs-selection-bar);
}
#selectionBar.align-bottom {
top: 0;
bottom: auto;
}
#selectionBar.expand {
transition-duration: 0.15s;
transition-timing-function: cubic-bezier(0.4, 0.0, 1, 1);
}
#selectionBar.contract {
transition-duration: 0.18s;
transition-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1);
}
#tabsContent > ::content > *:not(#selectionBar) {
height: 100%;
}
</style>
|
73bcce88
luigser
COMPONENTS
|
175
|
|
c5169e0e
Renato De Donato
a new hope
|
176
|
<template>
|
73bcce88
luigser
COMPONENTS
|
177
|
|
c5169e0e
Renato De Donato
a new hope
|
178
|
<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
|
179
|
|
c5169e0e
Renato De Donato
a new hope
|
180
|
<div id="tabsContainer" class="flex" on-track="_scroll" on-down="_down">
|
73bcce88
luigser
COMPONENTS
|
181
|
|
c5169e0e
Renato De Donato
a new hope
|
182
|
<div id="tabsContent" class$="[[_computeTabsContentClass(scrollable)]]">
|
73bcce88
luigser
COMPONENTS
|
183
|
|
c5169e0e
Renato De Donato
a new hope
|
184
|
<content select="*"></content>
|
73bcce88
luigser
COMPONENTS
|
185
|
|
c5169e0e
Renato De Donato
a new hope
|
186
187
|
<div id="selectionBar" class$="[[_computeSelectionBarClass(noBar, alignBottom)]]"
on-transitionend="_onBarTransitionEnd"></div>
|
73bcce88
luigser
COMPONENTS
|
188
|
|
c5169e0e
Renato De Donato
a new hope
|
189
|
</div>
|
73bcce88
luigser
COMPONENTS
|
190
|
|
c5169e0e
Renato De Donato
a new hope
|
191
|
</div>
|
73bcce88
luigser
COMPONENTS
|
192
|
|
c5169e0e
Renato De Donato
a new hope
|
193
|
<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
|
194
|
|
c5169e0e
Renato De Donato
a new hope
|
195
|
</template>
|
73bcce88
luigser
COMPONENTS
|
196
|
|
c5169e0e
Renato De Donato
a new hope
|
197
|
</dom-module>
|
73bcce88
luigser
COMPONENTS
|
198
|
|
c5169e0e
Renato De Donato
a new hope
|
199
|
<script>
|
73bcce88
luigser
COMPONENTS
|
200
|
|
c5169e0e
Renato De Donato
a new hope
|
201
|
Polymer({
|
73bcce88
luigser
COMPONENTS
|
202
|
|
c5169e0e
Renato De Donato
a new hope
|
203
|
is: 'paper-tabs',
|
73bcce88
luigser
COMPONENTS
|
204
|
|
c5169e0e
Renato De Donato
a new hope
|
205
206
207
208
|
behaviors: [
Polymer.IronResizableBehavior,
Polymer.IronMenubarBehavior
],
|
73bcce88
luigser
COMPONENTS
|
209
|
|
c5169e0e
Renato De Donato
a new hope
|
210
|
properties: {
|
73bcce88
luigser
COMPONENTS
|
211
|
|
c5169e0e
Renato De Donato
a new hope
|
212
213
214
215
216
217
|
/**
* If true, ink ripple effect is disabled.
*/
noink: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
218
219
|
},
|
c5169e0e
Renato De Donato
a new hope
|
220
221
222
223
224
225
|
/**
* If true, the bottom bar to indicate the selected tab will not be shown.
*/
noBar: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
226
227
|
},
|
c5169e0e
Renato De Donato
a new hope
|
228
229
230
231
232
233
|
/**
* If true, the slide effect for the bottom bar is disabled.
*/
noSlide: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
234
235
|
},
|
c5169e0e
Renato De Donato
a new hope
|
236
237
238
239
240
241
|
/**
* If true, tabs are scrollable and the tab width is based on the label width.
*/
scrollable: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
242
243
|
},
|
c5169e0e
Renato De Donato
a new hope
|
244
245
246
247
248
249
|
/**
* If true, dragging on the tabs to scroll is disabled.
*/
disableDrag: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
250
251
|
},
|
c5169e0e
Renato De Donato
a new hope
|
252
253
254
255
256
257
|
/**
* If true, scroll buttons (left/right arrow) will be hidden for scrollable tabs.
*/
hideScrollButtons: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
258
259
|
},
|
c5169e0e
Renato De Donato
a new hope
|
260
261
262
263
264
265
|
/**
* If true, the tabs are aligned to bottom (the selection bar appears at the top).
*/
alignBottom: {
type: Boolean,
value: false
|
73bcce88
luigser
COMPONENTS
|
266
267
|
},
|
c5169e0e
Renato De Donato
a new hope
|
268
269
270
271
272
273
|
/**
* Gets or sets the selected element. The default is to use the index of the item.
*/
selected: {
type: String,
notify: true
|
73bcce88
luigser
COMPONENTS
|
274
275
|
},
|
c5169e0e
Renato De Donato
a new hope
|
276
277
278
|
selectable: {
type: String,
value: 'paper-tab'
|
73bcce88
luigser
COMPONENTS
|
279
280
|
},
|
c5169e0e
Renato De Donato
a new hope
|
281
282
283
|
_step: {
type: Number,
value: 10
|
73bcce88
luigser
COMPONENTS
|
284
285
|
},
|
c5169e0e
Renato De Donato
a new hope
|
286
287
288
|
_holdDelay: {
type: Number,
value: 1
|
a1a3bc73
Luigi Serra
graphs updates
|
289
|
},
|
73bcce88
luigser
COMPONENTS
|
290
|
|
c5169e0e
Renato De Donato
a new hope
|
291
292
293
|
_leftHidden: {
type: Boolean,
value: false
|
a1a3bc73
Luigi Serra
graphs updates
|
294
|
},
|
73bcce88
luigser
COMPONENTS
|
295
|
|
c5169e0e
Renato De Donato
a new hope
|
296
297
298
|
_rightHidden: {
type: Boolean,
value: false
|
a1a3bc73
Luigi Serra
graphs updates
|
299
|
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
300
|
|
c5169e0e
Renato De Donato
a new hope
|
301
302
303
304
|
_previousTab: {
type: Object
}
},
|
73bcce88
luigser
COMPONENTS
|
305
|
|
c5169e0e
Renato De Donato
a new hope
|
306
307
308
|
hostAttributes: {
role: 'tablist'
},
|
73bcce88
luigser
COMPONENTS
|
309
|
|
c5169e0e
Renato De Donato
a new hope
|
310
311
312
313
314
|
listeners: {
'iron-resize': '_onResize',
'iron-select': '_onIronSelect',
'iron-deselect': '_onIronDeselect'
},
|
73bcce88
luigser
COMPONENTS
|
315
|
|
c5169e0e
Renato De Donato
a new hope
|
316
317
318
|
ready: function() {
this.setScrollDirection('y', this.$.tabsContainer);
},
|
73bcce88
luigser
COMPONENTS
|
319
|
|
c5169e0e
Renato De Donato
a new hope
|
320
321
322
323
|
_computeScrollButtonClass: function(hideThisButton, scrollable, hideScrollButtons) {
if (!scrollable || hideScrollButtons) {
return 'hidden';
}
|
73bcce88
luigser
COMPONENTS
|
324
|
|
c5169e0e
Renato De Donato
a new hope
|
325
326
327
|
if (hideThisButton) {
return 'not-visible';
}
|
e619a3b0
Luigi Serra
Controllet cross ...
|
328
|
|
c5169e0e
Renato De Donato
a new hope
|
329
330
|
return '';
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
331
|
|
c5169e0e
Renato De Donato
a new hope
|
332
333
334
|
_computeTabsContentClass: function(scrollable) {
return scrollable ? 'scrollable' : 'horizontal layout';
},
|
73bcce88
luigser
COMPONENTS
|
335
|
|
c5169e0e
Renato De Donato
a new hope
|
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
_computeSelectionBarClass: function(noBar, alignBottom) {
if (noBar) {
return 'hidden';
} else if (alignBottom) {
return 'align-bottom';
}
},
// TODO(cdata): Add `track` response back in when gesture lands.
_onResize: function() {
this.debounce('_onResize', function() {
this._scroll();
this._tabChanged(this.selectedItem);
}, 10);
},
_onIronSelect: function(event) {
this._tabChanged(event.detail.item, this._previousTab);
this._previousTab = event.detail.item;
this.cancelDebouncer('tab-changed');
},
_onIronDeselect: function(event) {
this.debounce('tab-changed', function() {
this._tabChanged(null, this._previousTab);
// See polymer/polymer#1305
}, 1);
},
get _tabContainerScrollSize () {
return Math.max(
0,
this.$.tabsContainer.scrollWidth -
this.$.tabsContainer.offsetWidth
);
},
_scroll: function(e, detail) {
if (!this.scrollable) {
return;
}
|
73bcce88
luigser
COMPONENTS
|
379
|
|
c5169e0e
Renato De Donato
a new hope
|
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
var ddx = (detail && -detail.ddx) || 0;
this._affectScroll(ddx);
},
_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
|
394
|
|
c5169e0e
Renato De Donato
a new hope
|
395
396
|
_affectScroll: function(dx) {
this.$.tabsContainer.scrollLeft += dx;
|
73bcce88
luigser
COMPONENTS
|
397
|
|
c5169e0e
Renato De Donato
a new hope
|
398
|
var scrollLeft = this.$.tabsContainer.scrollLeft;
|
73bcce88
luigser
COMPONENTS
|
399
|
|
c5169e0e
Renato De Donato
a new hope
|
400
401
402
|
this._leftHidden = scrollLeft === 0;
this._rightHidden = scrollLeft === this._tabContainerScrollSize;
},
|
73bcce88
luigser
COMPONENTS
|
403
|
|
c5169e0e
Renato De Donato
a new hope
|
404
405
406
407
|
_onLeftScrollButtonDown: function() {
this._scrollToLeft();
this._holdJob = setInterval(this._scrollToLeft.bind(this), this._holdDelay);
},
|
73bcce88
luigser
COMPONENTS
|
408
|
|
c5169e0e
Renato De Donato
a new hope
|
409
410
411
412
|
_onRightScrollButtonDown: function() {
this._scrollToRight();
this._holdJob = setInterval(this._scrollToRight.bind(this), this._holdDelay);
},
|
73bcce88
luigser
COMPONENTS
|
413
|
|
c5169e0e
Renato De Donato
a new hope
|
414
415
416
417
|
_onScrollButtonUp: function() {
clearInterval(this._holdJob);
this._holdJob = null;
},
|
73bcce88
luigser
COMPONENTS
|
418
|
|
c5169e0e
Renato De Donato
a new hope
|
419
420
421
|
_scrollToLeft: function() {
this._affectScroll(-this._step);
},
|
73bcce88
luigser
COMPONENTS
|
422
|
|
c5169e0e
Renato De Donato
a new hope
|
423
424
425
|
_scrollToRight: function() {
this._affectScroll(this._step);
},
|
73bcce88
luigser
COMPONENTS
|
426
|
|
c5169e0e
Renato De Donato
a new hope
|
427
428
429
430
431
|
_tabChanged: function(tab, old) {
if (!tab) {
this._positionBar(0, 0);
return;
}
|
73bcce88
luigser
COMPONENTS
|
432
|
|
c5169e0e
Renato De Donato
a new hope
|
433
434
435
436
|
var r = this.$.tabsContent.getBoundingClientRect();
var w = r.width;
var tabRect = tab.getBoundingClientRect();
var tabOffsetLeft = tabRect.left - r.left;
|
73bcce88
luigser
COMPONENTS
|
437
|
|
c5169e0e
Renato De Donato
a new hope
|
438
439
440
441
|
this._pos = {
width: this._calcPercent(tabRect.width, w),
left: this._calcPercent(tabOffsetLeft, w)
};
|
73bcce88
luigser
COMPONENTS
|
442
|
|
c5169e0e
Renato De Donato
a new hope
|
443
444
445
446
447
|
if (this.noSlide || old == null) {
// position bar directly without animation
this._positionBar(this._pos.width, this._pos.left);
return;
}
|
a1a3bc73
Luigi Serra
graphs updates
|
448
|
|
c5169e0e
Renato De Donato
a new hope
|
449
450
451
452
|
var oldRect = old.getBoundingClientRect();
var oldIndex = this.items.indexOf(old);
var index = this.items.indexOf(tab);
var m = 5;
|
73bcce88
luigser
COMPONENTS
|
453
|
|
c5169e0e
Renato De Donato
a new hope
|
454
455
|
// bar animation: expand
this.$.selectionBar.classList.add('expand');
|
73bcce88
luigser
COMPONENTS
|
456
|
|
c5169e0e
Renato De Donato
a new hope
|
457
458
459
460
461
462
463
|
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);
}
|
a1a3bc73
Luigi Serra
graphs updates
|
464
|
|
c5169e0e
Renato De Donato
a new hope
|
465
466
467
468
469
470
471
472
473
474
475
476
477
|
if (this.scrollable) {
this._scrollToSelectedIfNeeded(tabRect.width, tabOffsetLeft);
}
},
_scrollToSelectedIfNeeded: function(tabWidth, tabOffsetLeft) {
var l = tabOffsetLeft - this.$.tabsContainer.scrollLeft;
if (l < 0) {
this.$.tabsContainer.scrollLeft += l;
} else {
l += (tabWidth - this.$.tabsContainer.offsetWidth);
if (l > 0) {
this.$.tabsContainer.scrollLeft += l;
|
a1a3bc73
Luigi Serra
graphs updates
|
478
479
|
}
}
|
c5169e0e
Renato De Donato
a new hope
|
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
},
_calcPercent: function(w, w0) {
return 100 * w / w0;
},
_positionBar: function(width, left) {
width = width || 0;
left = left || 0;
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>
|