-
Notifications
You must be signed in to change notification settings - Fork 0
/
paper-swipeable-pages.html
192 lines (171 loc) · 5.18 KB
/
paper-swipeable-pages.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../iron-swipeable-pages/iron-swipeable-pages.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../dom-repeat-n/dom-repeat-n.html">
<link rel="import" href="./paper-swipeable-pages-icons.html">
<!--
`<paper-swipeable-pages>` manages a set of pages and and provides the ability to switch
between them by swiping gesture. In addition to the basic `iron-*` counterpart, it
provides by default navigation arrows and dots position indicator.
Example:
<paper-swipeable-pages>
<div>One</div>
<div>Two</div>
<div>Three</div>
</paper-swipeable-pages>
Additionnally, you can specify the following properties regarding the sensitivity of the swipe,
the transition used, and the possibility of cycling. For more details, see below.
It could be a good idea to disable text selection on any of the children that you
want to be swiped:
.swipe {
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
cursor: default;
}
### Styling
The following custom properties / mixins are available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--paper-swipeable-pages-arrows` | Mixin applied to the arrow icon-button. | `{}`
`--paper-swipeable-pages-indicator` | Mixin applied to the indicator. | `{}`
`--paper-swipeable-pages-indicator-selected` | Mixin applied to the indicator when selected. | `{}`
@demo demo/index.html
@hero hero.svg
-->
<dom-module id="paper-swipeable-pages">
<style>
:host {
display: block;
}
#page_selector {
position: fixed;
width: 100%;
bottom: 5vh;
@apply --layout-horizontal;
@apply --layout-center-center;
}
.page-indicator {
opacity: 0.35;
fill: var(--light-primary-color);
margin: 5vw;
width: 30px;
height: 30px;
@apply --paper-swipeable-pages-indicator;
-webkit-transition: opacity 3s;
transition: opacity 3s;
}
.page-indicator[selected] {
opacity: 1;
@apply --paper-swipeable-pages-indicator-selected;
}
paper-icon-button {
width: 8vw;
max-width: 60px;
height: 8vw;
max-height: 60px;
margin: 0;
padding: 0;
position: absolute;
top: calc(50% - 4vw);
color: var(--light-primary-color);
opacity: 0.85;
@apply --paper-swipeable-pages-arrows;
}
.left {
left: 0;
}
.right {
right: 0;
}
</style>
<template>
<iron-swipeable-pages id="isp" selected="{{_selected}}" no-cycle>
<content></content>
</iron-swipeable-pages>
<template is="dom-if" if="[[!noIndicator]]">
<div id="page-selector">
<template is="dom-repeat-n" count="[[_pageCount]]">
<svg class="page-indicator" selected$="{{_computeSelected(_selected, index)}}">
<circle cx="15" cy="15" r="15"/>
</svg>
</template>
</div>
</template>
<template is="dom-if" if="[[!noArrow]]">
<paper-icon-button
class="left"
icon="paper-swipeable-pages-icons:arrow-back"
on-tap="_selectPreviousPage">
</paper-icon-button>
<paper-icon-button
class="right"
icon="paper-swipeable-pages-icons:arrow-forward"
on-tap="_selectNextPage">
</paper-icon-button>
</template>
</template>
<script>
(function() {
Polymer({
is: 'paper-swipeable-pages',
properties: {
_selected: {
type: Number,
value: 0,
},
_pageCount: {
type: Number,
value: 0,
},
/**
* Hides the arrows.
*/
noArrow: {
type: Boolean,
value: false
},
/**
* Hides the page indicators.
*/
noIndicator: {
type: Boolean,
value: false
},
},
listeners: {
'track': '_onTrack'
},
// Element Lifecycle
attached: function() {
this._pageCount = this.$.isp.items.length;
},
// Element behavior
_onTrack: function(event) {
var track = event.detail;
if (track.state === 'start') {
var pageSelections = Polymer.dom(this.$.page_selector).children;
pageSelections.forEach(function(pageSelection, index) {
if (this._selected == index) {
pageSelection.style.opacity = '1';
} else {
pageSelection.style.opacity = '0.35';
}
}, this);
}
},
_computeSelected: function(selected, index) {
this.debounce("selectionDone", function() {
var pageSelections = Polymer.dom(this.$.page_selector).children;
pageSelections.forEach(function(pageSelection) {
pageSelection.style.opacity = '0';
});
}, 2000);
return selected == index;
}
});
}());
</script>
</dom-module>