-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-carousel.html
More file actions
283 lines (238 loc) · 7.82 KB
/
basic-carousel.html
File metadata and controls
283 lines (238 loc) · 7.82 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
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
<!--
Lets the user navigate laterally through a sequence of child elements.
basic-carousel is an implementation of the carousel user interface pattern,
commonly used for navigating between images, pages, and other elements.
This pattern presents the user with a linear sequence of elements, only one of
which is shown at a time. The user can navigate to the next/previous element
with a variety of input methods.
basic-carousel uses its children as the elements the user will navigate through.
In a typical use, a basic-carousel can be used to navigate between a sequence of
images:
<basic-carousel>
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
</basic-carousel>
The child elements can be of any type — they are not restricted to images.
This component attempts to meet the [Gold Standard for web components]
(https://github.com/webcomponents/gold-standard/wiki) so that it is generally
as flexible and robust as standard HTML elements. For example, it meets the
"Content Changes" criteria: the carousel will adapt to new child elements added
or removed at runtime.
Currently, this component does not meet the Gold Standard criteria "Size to
Content". As a result, for the time being, **you must manually set a size on
this component**. Two approaches are to: 1) stretch the component across
whatever surface it is contained within, or 2) set it to be larger than the
largest child element you want to display. The former approach is more common,
and can be achieved with CSS styling such as:
html {
height: 100%;
}
body {
display: -webkit-flex;
display: flex;
height: 100%;
margin: 0;
}
basic-carousel {
-webkit-flex: 1;
flex: 1;
}
Alternatively, you can use a separate component,
[basic-carousel-fit](http://github.com/basic-web-components/basic-carousel-fit),
which is designed to automatically size itself to its largest child elements.
The standard basic-carousel component supports navigation via the following
input methods:
* Keyboard. When the carousel has focus, the user can press Left, Right, Home,
or End. These navigate to the expected element.
* Touch. On mobile and other touch-enabled devices, the user can drag left or
right.
* Trackpad. The user can swipe left or right on a trackpad to navigate.
basic-carousel supports a variety of optional user interface accessories:
* [basic-arrow-direction](http://github.com/basic-web-components/basic-arrow-direction).
This adds prominent left and right arrow buttons on the side of the carousel.
* [basic-page-dots](http://github.com/basic-web-components/basic-page-dots).
This adds a series of small dots below the carousel to indicate the user's
current position in the sequence.
See those components for more details, but in general you can construct a common
carousel with both arrow buttons and dots like so:
<basic-arrow-direction target="child">
<basic-page-dots target="child">
<basic-carousel>
<img src="image1.jpg">
<img src="image2.jpg">
<img src="image3.jpg">
<img src="image4.jpg">
<img src="image5.jpg">
</basic-carousel>
</basic-page-dots>
</basic-arrow-direction>
For universal access, basic-carousel automatically adds a variety of
[ARIA](http://www.w3.org/WAI/intro/aria) properties to itself and to child
elements. This helps users navigate the sequence of elements in the carousel
using assistive technologies.
@element basic-carousel
@demo http://basic-web-components.github.io/basic-web-components/src/basic-carousel/?dom=shadow
-->
<link rel="import" href="../basic-aspect/basic-aspect.html">
<link rel="import" href="../basic-keyboard/basic-keyboard.html">
<link rel="import" href="../basic-keyboard-direction/basic-keyboard-direction.html">
<link rel="import" href="../basic-trackpad-direction/basic-trackpad-direction.html">
<link rel="import" href="../basic-swipe-direction/basic-swipe-direction.html">
<link rel="import" href="../basic-direction-selection/basic-direction-selection.html">
<link rel="import" href="../basic-item-selection/basic-item-selection.html">
<link rel="import" href="../basic-accessible-list/basic-accessible-list.html">
<link rel="import" href="../basic-content-items/basic-content-items.html">
<link rel="import" href="../basic-children-content/basic-children-content.html">
<link rel="import" href="../basic-sliding-viewport/basic-sliding-viewport.html">
<link rel="import" href="../basic-spread-items/basic-spread-items.html">
<dom-module id="basic-carousel">
<template>
<style>
:host {
display: -webkit-flex;
display: flex;
}
[target="child"] {
display: -webkit-flex;
display: flex;
-webkit-flex: 1;
flex: 1;
}
basic-spread-items {
height: 100%;
}
</style>
<basic-item-selection selection-required="true"></basic-item-selection>
<basic-trackpad-direction target="child">
<basic-swipe-direction target="child">
<basic-sliding-viewport target="child">
<basic-spread-items>
<content id="content"></content>
</basic-spread-items>
</basic-sliding-viewport>
</basic-swipe-direction>
</basic-trackpad-direction>
</template>
</dom-module>
<script>
Polymer({
aspects: [
Basic.AccessibleList,
Basic.ChildrenContent,
Basic.ContentItems,
Basic.DirectionSelection,
Basic.Keyboard,
Basic.KeyboardDirection
],
behaviors: [Basic.Aspect],
/**
* Returns the positional index for the indicated item.
*
* @method indexOfItem
* @param {Object} item The item whose index is requested.
* @returns {Number} The index of the item, or -1 if not found.
*/
indexOfItem: function(item) {
return this.collective.indexOfItem(item);
},
is: 'basic-carousel',
/**
* The current set of items in the list.
*
* @property items
* @type [Object]
*/
get items() {
return this.collective.items;
},
properties: {
selectedIndex: {
type: Number
},
selectedItem: {
type: Object
},
target: {
value: 'shadow'
}
},
/**
* The index of the item which is currently selected, or -1 if there is no
* selection.
*
* @property selectedIndex
* @type Number
*/
get selectedIndex() {
// See note at basic-item-selection's selectedIndex getter.
if (this._readied) {
return this.collective.selectedIndex;
}
},
set selectedIndex(index) {
this.collective.selectedIndex = index;
},
/**
* The currently selected item, or null if there is no selection.
*
* @property selectedItem
* @type Object
*/
get selectedItem() {
return this.collective.selectedItem;
},
set selectedItem(item) {
this.collective.selectedItem = item;
},
/**
* Select the first item in the list.
*
* @method selectFirst
*/
selectFirst: function() {
return this.collective.selectFirst();
},
/**
* Select the last item in the list.
*
* @method selectLast
*/
selectLast: function() {
return this.collective.selectLast();
},
/**
* Select the next item in the list.
*
* @method selectNext
*/
selectNext: function() {
return this.collective.selectNext();
},
/**
* Select the previous item in the list.
*
* @method selectPrevious
*/
selectPrevious: function() {
return this.collective.selectPrevious();
}
});
/*
* The following comments document API members provided by mixins. Ideally these
* docs will eventually be pulled from the mixin source files, but for now are
* copied here by hand.
*/
/**
* Fires when the items in the list change.
*
* @event items-changed
*/
/**
* Fires when a new item has been selected.
*
* @event selected-item-changed
* @param detail.selectedItem The new selected item.
* @param detail.previousItem The previously selected item.
*/
</script>