OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 @license |
| 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.g
ithub.io/LICENSE |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS |
| 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/PATEN
TS |
| 9 --> |
| 10 |
| 11 <link rel="import" href="../paper-styles/paper-styles.html"> |
| 12 <link rel="import" href="../iron-range-behavior/iron-range-behavior.html"> |
| 13 <link rel="import" href="../iron-flex-layout/classes/iron-flex-layout.html"> |
| 14 |
| 15 <!-- |
| 16 The progress bars are for situations where the percentage completed can be |
| 17 determined. They give users a quick sense of how much longer an operation |
| 18 will take. |
| 19 |
| 20 Example: |
| 21 |
| 22 <paper-progress value="10"></paper-progress> |
| 23 |
| 24 There is also a secondary progress which is useful for displaying intermediate |
| 25 progress, such as the buffer level during a streaming playback progress bar. |
| 26 |
| 27 Example: |
| 28 |
| 29 <paper-progress value="10" secondary-progress="30"></paper-progress> |
| 30 |
| 31 Styling progress bar: |
| 32 |
| 33 To change the active progress bar color: |
| 34 |
| 35 paper-progress { |
| 36 --paper-progress-active-color: #e91e63; |
| 37 } |
| 38 |
| 39 To change the secondary progress bar color: |
| 40 |
| 41 paper-progress { |
| 42 --paper-progress-secondary-color: #f8bbd0; |
| 43 } |
| 44 |
| 45 To change the progress bar background color: |
| 46 |
| 47 paper-progress { |
| 48 --paper-progress-container-color: #64ffda; |
| 49 } |
| 50 |
| 51 @group Paper Elements |
| 52 @element paper-progress |
| 53 @hero hero.svg |
| 54 @demo demo/index.html |
| 55 --> |
| 56 |
| 57 <dom-module id="paper-progress"> |
| 58 <style> |
| 59 :host { |
| 60 display: inline-block; |
| 61 width: 200px; |
| 62 height: 4px; |
| 63 } |
| 64 |
| 65 #progressContainer { |
| 66 position: relative; |
| 67 height: 100%; |
| 68 background-color: var(--paper-progress-container-color, --google-grey-300)
; |
| 69 overflow: hidden; |
| 70 } |
| 71 |
| 72 #activeProgress, |
| 73 #secondaryProgress { |
| 74 -webkit-transform-origin: left center; |
| 75 transform-origin: left center; |
| 76 -webkit-transform: scaleX(0); |
| 77 transform: scaleX(0); |
| 78 } |
| 79 |
| 80 #activeProgress { |
| 81 background-color: var(--paper-progress-active-color, --google-green-500); |
| 82 } |
| 83 |
| 84 #secondaryProgress { |
| 85 background-color: var(--paper-progress-secondary-color, --google-green-100
); |
| 86 } |
| 87 |
| 88 #activeProgress.indeterminate { |
| 89 -webkit-transform-origin: center center; |
| 90 transform-origin: center center; |
| 91 -webkit-animation: indeterminate-bar 1s linear infinite; |
| 92 animation: indeterminate-bar 1s linear infinite; |
| 93 } |
| 94 |
| 95 @-webkit-keyframes indeterminate-bar { |
| 96 0% { |
| 97 -webkit-transform: translate(-50%) scaleX(0); |
| 98 } |
| 99 50% { |
| 100 -webkit-transform: translate(0%) scaleX(0.3); |
| 101 } |
| 102 100% { |
| 103 -webkit-transform: translate(50%) scaleX(0); |
| 104 } |
| 105 } |
| 106 |
| 107 @keyframes indeterminate-bar { |
| 108 0% { |
| 109 transform: translate(-50%) scaleX(0); |
| 110 } |
| 111 50% { |
| 112 transform: translate(0%) scaleX(0.3); |
| 113 } |
| 114 100% { |
| 115 transform: translate(50%) scaleX(0); |
| 116 } |
| 117 } |
| 118 </style> |
| 119 <template> |
| 120 <div id="progressContainer" role="progressbar" aria-valuenow$="{{value}}" ar
ia-valuemin$="{{min}}" aria-valuemax$="{{max}}"> |
| 121 <div id="secondaryProgress" class="fit"></div> |
| 122 <div id="activeProgress" class="fit"></div> |
| 123 </div> |
| 124 </template> |
| 125 </dom-module> |
| 126 |
| 127 <script> |
| 128 Polymer({ |
| 129 |
| 130 is: 'paper-progress', |
| 131 |
| 132 behaviors: [ |
| 133 Polymer.IronRangeBehavior |
| 134 ], |
| 135 |
| 136 properties: { |
| 137 |
| 138 /** |
| 139 * The number that represents the current secondary progress. |
| 140 */ |
| 141 secondaryProgress: { |
| 142 type: Number, |
| 143 value: 0, |
| 144 notify: true |
| 145 }, |
| 146 |
| 147 /** |
| 148 * The secondary ratio |
| 149 */ |
| 150 secondaryRatio: { |
| 151 type: Number, |
| 152 value: 0, |
| 153 readOnly: true, |
| 154 observer: '_secondaryRatioChanged' |
| 155 }, |
| 156 |
| 157 /** |
| 158 * Use an indeterminate progress indicator. |
| 159 */ |
| 160 indeterminate: { |
| 161 type: Boolean, |
| 162 value: false, |
| 163 notify: true, |
| 164 observer: '_toggleIndeterminate' |
| 165 } |
| 166 }, |
| 167 |
| 168 observers: [ |
| 169 '_ratioChanged(ratio)', |
| 170 '_secondaryProgressChanged(secondaryProgress, min, max)' |
| 171 ], |
| 172 |
| 173 _toggleIndeterminate: function() { |
| 174 // If we use attribute/class binding, the animation sometimes doesn't tran
slate properly |
| 175 // on Safari 7.1. So instead, we toggle the class here in the update metho
d. |
| 176 this.toggleClass('indeterminate', this.indeterminate, this.$.activeProgres
s); |
| 177 }, |
| 178 |
| 179 _transformProgress: function(progress, ratio) { |
| 180 var transform = 'scaleX(' + (ratio / 100) + ')'; |
| 181 progress.style.transform = progress.style.webkitTransform = transform; |
| 182 }, |
| 183 |
| 184 _ratioChanged: function(ratio) { |
| 185 this._transformProgress(this.$.activeProgress, ratio); |
| 186 }, |
| 187 |
| 188 _secondaryRatioChanged: function(secondaryRatio) { |
| 189 this._transformProgress(this.$.secondaryProgress, secondaryRatio); |
| 190 }, |
| 191 |
| 192 _secondaryProgressChanged: function() { |
| 193 this.secondaryProgress = this._clampValue(this.secondaryProgress); |
| 194 this._setSecondaryRatio(this._calcRatio(this.secondaryProgress) * 100); |
| 195 } |
| 196 |
| 197 }); |
| 198 |
| 199 </script> |
OLD | NEW |