3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 <link rel=
"import" href=
"../polymer/polymer.html">
12 <link rel=
"import" href=
"../paper-styles/color.html">
13 <link rel=
"import" href=
"../iron-flex-layout/iron-flex-layout.html">
16 Element providing material design circular spinner.
18 <paper-spinner active></paper-spinner>
20 The default spinner cycles between four layers of colors; by default they are
21 blue, red, yellow and green. It can be customized so that it uses one color only
22 by setting all the layer colors to the same value.
26 Alt attribute should be set to provide adequate context for accessibility. If not provided,
27 it defaults to 'loading'.
28 Empty alt can be provided to mark the element as decorative if alternative content is provided
29 in another form (e.g. a text block following the spinner).
31 <paper-spinner alt="Loading contacts list" active></paper-spinner>
35 The following custom properties and mixins are available for styling:
37 Custom property | Description | Default
38 ----------------|-------------|----------
39 `--paper-spinner-layer-1-color` | Color of the first spinner rotation | `--google-blue-500`
40 `--paper-spinner-layer-2-color` | Color of the second spinner rotation | `--google-red-500`
41 `--paper-spinner-layer-3-color` | Color of the third spinner rotation | `--google-yellow-500`
42 `--paper-spinner-layer-4-color` | Color of the fourth spinner rotation | `--google-green-500`
45 @element paper-spinner
50 <dom-module id=
"paper-spinner">
52 <link rel=
"import" type=
"css" href=
"paper-spinner.css">
56 <div id=
"spinnerContainer" class-name=
"[[_spinnerContainerClassName]]">
57 <div class=
"spinner-layer layer-1">
58 <div class=
"circle-clipper left">
59 <div class=
"circle"></div>
60 </div><div class=
"gap-patch">
61 <div class=
"circle"></div>
62 </div><div class=
"circle-clipper right">
63 <div class=
"circle"></div>
67 <div class=
"spinner-layer layer-2">
68 <div class=
"circle-clipper left">
69 <div class=
"circle"></div>
70 </div><div class=
"gap-patch">
71 <div class=
"circle"></div>
72 </div><div class=
"circle-clipper right">
73 <div class=
"circle"></div>
77 <div class=
"spinner-layer layer-3">
78 <div class=
"circle-clipper left">
79 <div class=
"circle"></div>
80 </div><div class=
"gap-patch">
81 <div class=
"circle"></div>
82 </div><div class=
"circle-clipper right">
83 <div class=
"circle"></div>
87 <div class=
"spinner-layer layer-4">
88 <div class=
"circle-clipper left">
89 <div class=
"circle"></div>
90 </div><div class=
"gap-patch">
91 <div class=
"circle"></div>
92 </div><div class=
"circle-clipper right">
93 <div class=
"circle"></div>
107 'animationend': 'reset',
108 'webkitAnimationEnd': 'reset'
114 * Displays the spinner.
123 reflectToAttribute
: true,
124 observer
: '_activeChanged'
128 * Alternative text content for accessibility support.
129 * If alt is present, it will add an aria-label whose content matches alt when active.
130 * If alt is not present, it will default to 'loading' as the alt value.
139 observer
: '_altChanged'
143 * True when the spinner is going from active to inactive. This is represented by a fade
144 * to 0% opacity to the user.
151 _spinnerContainerClassName
: {
153 computed
: '_computeSpinnerContainerClassName(active, _coolingDown)'
158 _computeSpinnerContainerClassName: function(active
, coolingDown
) {
160 active
|| coolingDown
? 'active' : '',
161 coolingDown
? 'cooldown' : ''
165 _activeChanged: function(active
, old
) {
166 this._setAriaHidden(!active
);
167 if (!active
&& old
) {
168 this._coolingDown
= true;
172 _altChanged: function(alt
) {
173 // user-provided `aria-label` takes precedence over prototype default
174 if (alt
=== this.getPropertyInfo('alt').value
) {
175 this.alt
= this.getAttribute('aria-label') || alt
;
177 this._setAriaHidden(alt
==='');
178 this.setAttribute('aria-label', alt
);
182 _setAriaHidden: function(hidden
) {
183 var attr
= 'aria-hidden';
185 this.setAttribute(attr
, 'true');
187 this.removeAttribute(attr
);
193 this._coolingDown
= false;