1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update buttons

This commit is contained in:
Luke Pulverenti 2015-06-25 21:10:56 -04:00
parent 939e545723
commit c4dadd58bd
46 changed files with 2132 additions and 110 deletions

View file

@ -0,0 +1,48 @@
{
"name": "paper-tabs",
"version": "1.0.0",
"license": "http://polymer.github.io/LICENSE.txt",
"description": "Material design tabs",
"private": true,
"main": "paper-tabs.html",
"authors": [
"The Polymer Authors"
],
"keywords": [
"web-components",
"polymer",
"tabs",
"control"
],
"repository": "https://github.com/PolymerElements/paper-tabs.git",
"dependencies": {
"iron-behaviors": "polymerelements/iron-behaviors#^1.0.0",
"iron-flex-layout": "polymerelements/iron-flex-layout#^1.0.0",
"iron-icon": "polymerelements/iron-icon#^1.0.0",
"iron-iconset-svg": "polymerelements/iron-iconset-svg#^1.0.0",
"iron-menu-behavior": "polymerelements/iron-menu-behavior#^1.0.0",
"iron-resizable-behavior": "polymerelements/iron-resizable-behavior#^1.0.0",
"paper-ripple": "polymerelements/paper-ripple#^1.0.0",
"paper-styles": "polymerelements/paper-styles#^1.0.0",
"polymer": "Polymer/polymer#^1.0.0",
"paper-icon-button": "polymerelements/paper-icon-button#^1.0.0"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
"paper-toolbar": "polymerelements/paper-toolbar#^1.0.0",
"test-fixture": "polymerelements/test-fixture#^1.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
"web-component-tester": "*"
},
"homepage": "https://github.com/PolymerElements/paper-tabs",
"_release": "1.0.0",
"_resolution": {
"type": "version",
"tag": "v1.0.0",
"commit": "af6820e55f73fc5aa8c8e4d5294085e46374c7ca"
},
"_source": "git://github.com/PolymerElements/paper-tabs.git",
"_target": "~1.0.0",
"_originalSource": "PolymerElements/paper-tabs",
"_direct": true
}

View file

@ -0,0 +1 @@
bower_components/

View file

@ -0,0 +1,37 @@
{
"name": "paper-tabs",
"version": "1.0.0",
"license": "http://polymer.github.io/LICENSE.txt",
"description": "Material design tabs",
"private": true,
"main": "paper-tabs.html",
"authors": [
"The Polymer Authors"
],
"keywords": [
"web-components",
"polymer",
"tabs",
"control"
],
"repository": "https://github.com/PolymerElements/paper-tabs.git",
"dependencies": {
"iron-behaviors": "polymerelements/iron-behaviors#^1.0.0",
"iron-flex-layout": "polymerelements/iron-flex-layout#^1.0.0",
"iron-icon": "polymerelements/iron-icon#^1.0.0",
"iron-iconset-svg": "polymerelements/iron-iconset-svg#^1.0.0",
"iron-menu-behavior": "polymerelements/iron-menu-behavior#^1.0.0",
"iron-resizable-behavior": "polymerelements/iron-resizable-behavior#^1.0.0",
"paper-ripple": "polymerelements/paper-ripple#^1.0.0",
"paper-styles": "polymerelements/paper-styles#^1.0.0",
"polymer": "Polymer/polymer#^1.0.0",
"paper-icon-button": "polymerelements/paper-icon-button#^1.0.0"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
"paper-toolbar": "polymerelements/paper-toolbar#^1.0.0",
"test-fixture": "polymerelements/test-fixture#^1.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
"web-component-tester": "*"
}
}

View file

@ -0,0 +1,177 @@
<!doctype html>
<!--
@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
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
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
-->
<html>
<head>
<title>paper-tabs</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../iron-flex-layout/classes/iron-flex-layout.html">
<link rel="import" href="../../paper-toolbar/paper-toolbar.html">
<link rel="import" href="../paper-tabs.html">
<link rel="import" href="../paper-tab.html">
<style is="custom-style">
:root {
--paper-toolbar-background: #00bcd4;
}
body {
font-family: sans-serif;
margin: 0;
padding: 24px;
color: #333;
}
paper-tabs, paper-toolbar {
background-color: #00bcd4;
color: #fff;
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.2);
}
paper-toolbar paper-tabs {
box-shadow: none;
}
paper-tabs[noink][no-bar] paper-tab.iron-selected {
color: #ffff8d;
}
paper-tabs[alignBottom] {
box-shadow: 0px -2px 6px rgba(0, 0, 0, 0.15);
}
h3 {
font-size: 16px;
font-weight: 400;
padding-top: 20px;
}
</style>
</head>
<body>
<h3>A. No ink effect and no sliding bar</h3>
<paper-tabs selected="0" noink no-bar>
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
<h3>B. The bottom bar appears to indicate the selected tab, but without sliding effect.</h3>
<paper-tabs selected="0" noink no-slide>
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
<h3>C. The bar slides to the selected tab</h3>
<paper-tabs selected="0" noink>
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
<h3>D. Inky Tabs</h3>
<paper-tabs selected="0">
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
<h3>E. Scrollable Tabs</h3>
<paper-tabs id="scrollableTabs" selected="0" scrollable>
<paper-tab>NUMBER ONE ITEM</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>THE THIRD ITEM</paper-tab>
<paper-tab>THE ITEM FOUR</paper-tab>
<paper-tab>FIFTH</paper-tab>
<paper-tab>THE SIXTH TAB</paper-tab>
<paper-tab>NUMBER SEVEN</paper-tab>
<paper-tab>EIGHT</paper-tab>
<paper-tab>NUMBER NINE</paper-tab>
<paper-tab>THE TENTH</paper-tab>
<paper-tab>THE ITEM ELEVEN</paper-tab>
<paper-tab>TWELFTH ITEM</paper-tab>
</paper-tabs>
<h3>F. Link Tabs</h3>
<paper-tabs selected="0">
<paper-tab link><a href="#item1" class="horizontal center-center layout">ITEM ONE</a></paper-tab>
<paper-tab link><a href="#item2" class="horizontal center-center layout">ITEM TWO</a></paper-tab>
<paper-tab link><a href="#item3" class="horizontal center-center layout">ITEM THREE</a></paper-tab>
</paper-tabs>
<h3>G. Tabs in Toolbar</h3>
<paper-toolbar class="tall">
<paper-tabs selected="0" class="bottom self-end" style="width: 300px;">
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
</paper-tabs>
<div class="bottom flex"></div>
</paper-toolbar>
<h3>H. Tabs aligned to bottom</h3>
<paper-tabs selected="0" alignBottom>
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
<h3>I. Bound Selection</h3>
<template is="dom-bind">
<h2>Current Tab: <span>[[selected]]</span></h2>
<paper-tabs selected="{{selected}}">
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
</template>
</body>
</html>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 225 126" enable-background="new 0 0 225 126" xml:space="preserve">
<g id="background" display="none">
<rect display="inline" fill="#B0BEC5" width="225" height="126"/>
</g>
<g id="label">
</g>
<g id="art">
<path d="M188,78H37V44h151V78z M39,76h147V46H39V76z"/>
<polygon points="66,64.8 60.6,56.8 55.3,64.8 49.2,55.6 50.8,54.4 55.3,61.2 60.6,53.2 66,61.2 71.3,53.2 77.4,62.4 75.8,63.6
71.3,56.8 "/>
<rect x="149" y="58" width="26" height="2"/>
<rect x="99" y="58" width="26" height="2"/>
<rect x="38" y="72" width="50" height="4"/>
<g id="ic_x5F_add_x0D_">
</g>
</g>
<g id="Guides">
</g>
</svg>

After

Width:  |  Height:  |  Size: 966 B

View file

@ -0,0 +1,25 @@
<!doctype html>
<!--
@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
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
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
-->
<html>
<head>
<title>paper-tabs</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../iron-component-page/iron-component-page.html">
</head>
<body>
<iron-component-page sources='["paper-tabs.html", "paper-tab.html"]'></iron-component-page>
</body>
</html>

View file

@ -0,0 +1,158 @@
<!--
@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/classes/iron-flex-layout.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-behaviors/iron-control-state.html">
<link rel="import" href="../paper-ripple/paper-ripple.html">
<!--
`paper-tab` is styled to look like a tab. It should be used in conjunction with
`paper-tabs`.
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>
### Styling
The following custom properties and mixins are available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--paper-tab-ink` | Ink color | `--paper-yellow-a100`
`--paper-tab` | Mixin applied to the tab | `{}`
`--paper-tab-content` | Mixin applied to the tab content | `{}`
-->
<dom-module id="paper-tab">
<style>
:host {
@apply(--layout-inline);
@apply(--layout-center);
@apply(--layout-center-justified);
@apply(--layout-flex);
position: relative;
padding: 0 12px;
overflow: hidden;
cursor: pointer;
@apply(--paper-tab);
}
:host(:focus) {
outline: none;
}
:host([link]) {
padding: 0;
}
.tab-content {
height: 100%;
-webkit-transform: translateZ(0);
transform: translateZ(0);
transition: opacity 0.1s cubic-bezier(0.4, 0.0, 1, 1);
@apply(--paper-tab-content);
}
:host(:not(.iron-selected)) > .tab-content {
opacity: 0.8;
}
:host(:focus) .tab-content {
opacity: 1;
font-weight: 700;
}
#ink {
color: var(--paper-tab-ink, --paper-yellow-a100);
pointer-events: none;
}
.tab-content > ::content > a {
height: 100%;
/* flex */
-ms-flex: 1 1 0.000000001px;
-webkit-flex: 1;
flex: 1;
-webkit-flex-basis: 0.000000001px;
flex-basis: 0.000000001px;
}
</style>
<template>
<div class="tab-content flex-auto center-center horizontal layout">
<content></content>
</div>
<template is="dom-if" if="[[!noink]]">
<paper-ripple id="ink" initial-opacity="0.95" opacity-decay-velocity="0.98"></paper-ripple>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'paper-tab',
behaviors: [
Polymer.IronControlState
],
properties: {
/**
* If true, ink ripple effect is disabled.
*
* @attribute noink
*/
noink: {
type: Boolean,
value: false
}
},
hostAttributes: {
role: 'tab'
},
listeners: {
down: '_onDown'
},
get _parentNoink () {
var parent = Polymer.dom(this).parentNode;
return !!parent && !!parent.noink;
},
_onDown: function(e) {
this.noink = !!this.noink || !!this._parentNoink;
}
});
</script>

View file

@ -0,0 +1,18 @@
<!--
@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="../iron-iconset-svg/iron-iconset-svg.html">
<iron-iconset-svg name="paper-tabs" size="24">
<svg><defs>
<g id="chevron-left"><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/></g>
<g id="chevron-right"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></g>
</defs></svg>
</iron-iconset-svg>

View file

@ -0,0 +1,483 @@
<!--
@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">
<link rel="import" href="../iron-flex-layout/classes/iron-flex-layout.html">
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<link rel="import" href="../iron-menu-behavior/iron-menubar-behavior.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<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">
<!--
`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:
<paper-tabs selected="0">
<paper-tab link>
<a href="#link1" class="horizontal center-center layout">TAB ONE</a>
</paper-tab>
<paper-tab link>
<a href="#link2" class="horizontal center-center layout">TAB TWO</a>
</paper-tab>
<paper-tab link>
<a href="#link3" class="horizontal center-center layout">TAB THREE</a>
</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">
<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;
}
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>
<template>
<paper-icon-button icon="paper-tabs:chevron-left" class$="[[_computeScrollButtonClass(_leftHidden, scrollable, hideScrollButtons)]]" on-up="_onScrollButtonUp" on-down="_onLeftScrollButtonDown"></paper-icon-button>
<div id="tabsContainer" class="flex" on-scroll="_scroll">
<div id="tabsContent" class$="[[_computeTabsContentClass(scrollable)]]">
<content select="*"></content>
<div id="selectionBar" class$="[[_computeSelectionBarClass(noBar, alignBottom)]]"
on-transitionend="_onBarTransitionEnd"></div>
</div>
</div>
<paper-icon-button icon="paper-tabs:chevron-right" class$="[[_computeScrollButtonClass(_rightHidden, scrollable, hideScrollButtons)]]" on-up="_onScrollButtonUp" on-down="_onRightScrollButtonDown"></paper-icon-button>
</template>
</dom-module>
<script>
Polymer({
is: 'paper-tabs',
behaviors: [
Polymer.IronResizableBehavior,
Polymer.IronMenubarBehavior
],
properties: {
/**
* If true, ink ripple effect is disabled.
*/
noink: {
type: Boolean,
value: false
},
/**
* 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
}
},
hostAttributes: {
role: 'tablist'
},
listeners: {
'iron-resize': '_onResize',
'iron-select': '_onIronSelect',
'iron-deselect': '_onIronDeselect'
},
_computeScrollButtonClass: function(hideThisButton, scrollable, hideScrollButtons) {
if (!scrollable || hideScrollButtons) {
return 'hidden';
}
if (hideThisButton) {
return 'not-visible';
}
return '';
},
_computeTabsContentClass: function(scrollable) {
return scrollable ? 'scrollable' : 'horizontal layout';
},
_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() {
var scrollLeft;
if (!this.scrollable) {
return;
}
scrollLeft = this.$.tabsContainer.scrollLeft;
this._leftHidden = scrollLeft === 0;
this._rightHidden = scrollLeft === this._tabContainerScrollSize;
},
_onLeftScrollButtonDown: function() {
this._holdJob = setInterval(this._scrollToLeft.bind(this), this._holdDelay);
},
_onRightScrollButtonDown: function() {
this._holdJob = setInterval(this._scrollToRight.bind(this), this._holdDelay);
},
_onScrollButtonUp: function() {
clearInterval(this._holdJob);
this._holdJob = null;
},
_scrollToLeft: function() {
this.$.tabsContainer.scrollLeft -= this._step;
},
_scrollToRight: function() {
this.$.tabsContainer.scrollLeft += this._step;
},
_tabChanged: function(tab, old) {
if (!tab) {
this._positionBar(0, 0);
return;
}
var r = this.$.tabsContent.getBoundingClientRect();
var w = r.width;
var tabRect = tab.getBoundingClientRect();
var tabOffsetLeft = tabRect.left - r.left;
this._pos = {
width: this._calcPercent(tabRect.width, w),
left: this._calcPercent(tabOffsetLeft, w)
};
if (this.noSlide || old == null) {
// position bar directly without animation
this._positionBar(this._pos.width, this._pos.left);
return;
}
var oldRect = old.getBoundingClientRect();
var oldIndex = this.items.indexOf(old);
var index = this.items.indexOf(tab);
var m = 5;
// bar animation: expand
this.$.selectionBar.classList.add('expand');
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);
}
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;
}
}
},
_calcPercent: function(w, w0) {
return 100 * w / w0;
},
_positionBar: function(width, left) {
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>

View file

@ -0,0 +1,82 @@
<!doctype html>
<!--
@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
-->
<html>
<head>
<title>paper-tabs-attr-for-selected</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<link rel="import" href="../paper-tabs.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
</head>
<body>
<test-fixture id="basic">
<template>
<paper-tabs attr-for-selected="name" selected="bar">
<paper-tab name="foo">ITEM FOO</paper-tab>
<paper-tab name="bar">ITEM BAR</paper-tab>
<paper-tab name="zot">ITEM ZOT</paper-tab>
</paper-tabs>
</template>
</test-fixture>
<script>
suite('set the selected attribute', function() {
var tabs;
setup(function () {
tabs = fixture('basic');
});
test('selected value', function() {
assert.equal(tabs.selected, 'bar');
});
test('selected tab has iron-selected class', function() {
assert.isTrue(tabs.querySelector('[name=bar]').classList.contains('iron-selected'));
});
});
suite('select tab via click', function() {
var tabs, tab;
setup(function () {
tabs = fixture('basic');
tab = tabs.querySelector('[name=zot]');
tab.dispatchEvent(new CustomEvent('click', {bubbles: true}));
});
test('selected value', function() {
assert.equal(tabs.selected, 'zot');
});
test('selected tab has iron-selected class', function() {
assert.isTrue(tab.classList.contains('iron-selected'));
});
});
</script>
</body>
</html>

View file

@ -0,0 +1,157 @@
<!doctype html>
<!--
@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
-->
<html>
<head>
<title>paper-tabs-basic</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<link rel="import" href="../paper-tabs.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
</head>
<body>
<test-fixture id="basic">
<template>
<paper-tabs>
<paper-tab>ITEM ONE</paper-tab>
<paper-tab>ITEM TWO</paper-tab>
<paper-tab>ITEM THREE</paper-tab>
</paper-tabs>
</template>
</test-fixture>
<script>
function checkSelectionBar(tabs, tab) {
var tabRect = tab.getBoundingClientRect();
var rect = Polymer.dom(tabs.root).querySelector('#selectionBar').getBoundingClientRect();
assert.equal(Math.round(tabRect.left), Math.round(rect.left));
}
suite('defaults', function() {
var tabs;
setup(function () {
tabs = fixture('basic');
});
test('to nothing selected', function() {
assert.equal(tabs.selected, undefined);
});
test('no tabs have iron-selected class', function() {
Array.prototype.forEach.call(tabs.querySelectorAll('paper-tab'), function(tab) {
assert.isFalse(tab.classList.contains('iron-selected'));
});
});
test('to false as noink', function() {
assert.equal(tabs.noink, false);
});
test('to false as noBar', function() {
assert.equal(tabs.noBar, false);
});
test('to false as noSlide', function() {
assert.equal(tabs.noSlide, false);
});
test('to false as scrollable', function() {
assert.equal(tabs.scrollable, false);
});
test('to false as disableDrag', function() {
assert.equal(tabs.disableDrag, false);
});
test('to false as hideScrollButtons', function() {
assert.equal(tabs.hideScrollButtons, false);
});
test('to false as alignBottom', function() {
assert.equal(tabs.alignBottom, false);
});
test('has role tablist', function() {
assert.equal(tabs.getAttribute('role'), 'tablist');
});
});
suite('set the selected attribute', function() {
var tabs, index = 0;
setup(function () {
tabs = fixture('basic');
tabs.selected = index;
});
test('selected value', function() {
assert.equal(tabs.selected, index);
});
test('selected tab has iron-selected class', function() {
var tab = tabs.querySelectorAll('paper-tab')[index];
assert.isTrue(tab.classList.contains('iron-selected'));
});
test('selected tab has selection bar position at the bottom of the tab', function(done) {
setTimeout(function() {
checkSelectionBar(tabs, tabs.querySelectorAll('paper-tab')[index]);
done();
}, 1000);
});
});
suite('select tab via click', function() {
var tabs, index = 1;
setup(function () {
tabs = fixture('basic');
var tab = tabs.querySelectorAll('paper-tab')[index];
tab.dispatchEvent(new CustomEvent('click', {bubbles: true}));
});
test('selected value', function() {
assert.equal(tabs.selected, index);
});
test('selected tab has iron-selected class', function() {
var tab = tabs.querySelectorAll('paper-tab')[index];
assert.isTrue(tab.classList.contains('iron-selected'));
});
test('selected tab has selection bar position at the bottom of the tab', function(done) {
setTimeout(function() {
checkSelectionBar(tabs, tabs.querySelectorAll('paper-tab')[index]);
done();
}, 1000);
});
});
</script>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!doctype html>
<!--
@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
-->
<html>
<head>
<meta charset="utf-8">
<title>Tests</title>
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
<script>
WCT.loadSuites([
'basic.html',
'attr-for-selected.html'
]);
</script>
</body>
</html>