forked from google/material-design-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement progress bar component (closes google#88)
commit b8cb14a Author: Alexander Surma <surma@surmair.de> Date: Wed Apr 1 12:16:57 2015 +0100 Invert CSS hack logic commit f58bf29 Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 15:43:28 2015 +0100 Use feature detection commit 095789e Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 15:34:31 2015 +0100 Revert "Add browser detection" This reverts commit 82f6c28. commit 71d3f14 Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 14:37:17 2015 +0100 Colorize aux bar on IE and FF commit 82f6c28 Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 14:15:43 2015 +0100 Add browser detection commit 06f347b Author: Alexander Surma <surma@surmair.de> Date: Tue Mar 31 14:01:51 2015 +0100 Externalize SVG again commit cfdc4f2 Author: Alexander Surma <surma@surmair.de> Date: Mon Mar 30 15:47:13 2015 +0100 Adhere to styleguide commit cf4c72a Author: Alexander Surma <surma@surmair.de> Date: Mon Mar 30 12:50:38 2015 +0100 Inline SVG for progress bar commit bc9e77d Author: Alexander Surma <surma@surmair.de> Date: Mon Mar 30 12:46:44 2015 +0100 Add unit tests for progress bar commit 9e70b49 Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 17:48:11 2015 +0000 Speed up buffering animation commit 45e7dd3 Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 16:15:03 2015 +0000 Add circle svg for buffer bar commit ade9276 Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 15:24:17 2015 +0000 Fix colors commit ba10830 Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 14:54:27 2015 +0000 Implement indeterminate progress bar commit 71bac12 Author: Alexander Surma <surma@surmair.de> Date: Fri Mar 27 14:23:24 2015 +0000 Add support for buffer bar commit 9933563 Author: Alexander Surma <surma@surmair.de> Date: Thu Mar 26 22:26:52 2015 +0000 Implement basic progress bar
- Loading branch information
Showing
14 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
@import "../colors"; | ||
@import "../animation/animation"; | ||
|
||
$bar-height: 4px !default; | ||
|
||
|
||
.wsk-js-progress { | ||
display: block; | ||
position: relative; | ||
height: $bar-height; | ||
} | ||
|
||
.wsk-js-progress > .bar { | ||
display: block; | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
width: 0%; | ||
transition: width 0.2s $animation-curve-default; | ||
} | ||
|
||
.wsk-js-progress > .progressbar { | ||
background-color: $progress-main-color; | ||
z-index: 1; | ||
left: 0; | ||
} | ||
|
||
.wsk-js-progress > .bufferbar { | ||
background-image: linear-gradient(to right, $progress-secondary-color, $progress-secondary-color), | ||
linear-gradient(to right, $progress-main-color, $progress-main-color); | ||
z-index: 0; | ||
left: 0; | ||
} | ||
|
||
.wsk-js-progress > .auxbar { | ||
right: 0; | ||
} | ||
|
||
// Webkit only | ||
@supports (-webkit-appearance:none) { | ||
.wsk-js-progress:not(.wsk-progress__indeterminate) > .auxbar { | ||
background-image: linear-gradient(to right, $progress-secondary-color, $progress-secondary-color), | ||
linear-gradient(to right, $progress-main-color, $progress-main-color); | ||
mask: url('../images/buffer.svg'); | ||
} | ||
} | ||
|
||
.wsk-js-progress:not(.wsk-progress__indeterminate) > .auxbar { | ||
background-color: $progress-fallback-buffer-color; | ||
} | ||
|
||
.wsk-js-progress.wsk-progress__indeterminate > .bar1 { | ||
background-color: $progress-main-color; | ||
animation-name: indeterminate1; | ||
animation-duration: 2s; | ||
animation-iteration-count: infinite; | ||
animation-timing-function: linear; | ||
} | ||
|
||
.wsk-js-progress.wsk-progress__indeterminate > .bar3 { | ||
background-image: none; | ||
background-color: $progress-main-color; | ||
animation-name: indeterminate2; | ||
animation-duration: 2s; | ||
animation-iteration-count: infinite; | ||
animation-timing-function: linear; | ||
} | ||
|
||
@keyframes indeterminate1 { | ||
0% { | ||
left: 0%; | ||
width: 0%; | ||
} | ||
50% { | ||
left: 25%; | ||
width: 75%; | ||
} | ||
75% { | ||
left: 100%; | ||
width: 0%; | ||
} | ||
} | ||
|
||
@keyframes indeterminate2 { | ||
0% { | ||
left: 0%; | ||
width: 0%; | ||
} | ||
50% { | ||
left: 0%; | ||
width: 0%; | ||
} | ||
75% { | ||
left: 0%; | ||
width: 25%; | ||
} | ||
100% { | ||
left: 100%; | ||
width: 0%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!doctype html> | ||
<html lang=""> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Progress Bar</title> | ||
|
||
<link href='//fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en' rel='stylesheet' type='text/css'> | ||
|
||
<link rel="stylesheet" href="demo.css"> | ||
</head> | ||
<body class="demo-page demo-page--progress"> | ||
|
||
<div class="demo-preview-block"> | ||
|
||
<p> | ||
Default: | ||
<div id="p1" class="wsk-js-progress"></div> | ||
</p> | ||
|
||
<p> | ||
Indeterminate: | ||
<div id="p2" class="wsk-js-progress wsk-progress__indeterminate"></div> | ||
</p> | ||
|
||
<p> | ||
Buffering: | ||
<div id="p3" class="wsk-js-progress"></div> | ||
</p> | ||
</div> | ||
<!-- build:js(app/styleguide/progress/) ../../scripts/main.min.js --> | ||
<script src="../wskComponentHandler.js"></script> | ||
<script src="progress.js"></script> | ||
<script> | ||
// FIXME: What IS the recommended way to wait for the upgrade to be done? | ||
window.setTimeout(function() { | ||
document.querySelector('#p1').widget.setProgress(44); | ||
document.querySelector('#p3').widget.setProgress(33); | ||
document.querySelector('#p3').widget.setBuffer(87); | ||
}, 1000); | ||
</script> | ||
<!-- endbuild --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import "../styleguide_demo_bp"; | ||
@import "_progress"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Class constructor for Progress WSK component. | ||
* Implements WSK component design pattern defined at: | ||
* https://github.com/jasonmayes/wsk-component-design-pattern | ||
* @param {HTMLElement} element The element that will be upgraded. | ||
*/ | ||
function MaterialProgress(element) { | ||
'use strict'; | ||
|
||
this.element_ = element; | ||
|
||
// Initialize instance. | ||
this.init(); | ||
} | ||
|
||
/** | ||
* Store constants in one place so they can be updated easily. | ||
* @enum {string | number} | ||
* @private | ||
*/ | ||
MaterialProgress.prototype.Constant_ = { | ||
}; | ||
|
||
/** | ||
* Store strings for class names defined by this component that are used in | ||
* JavaScript. This allows us to simply change it in one place should we | ||
* decide to modify at a later date. | ||
* @enum {string} | ||
* @private | ||
*/ | ||
MaterialProgress.prototype.CssClasses_ = { | ||
INDETERMINATE_CLASS: 'wsk-progress__indeterminate' | ||
}; | ||
|
||
MaterialProgress.prototype.setProgress = function(p) { | ||
'use strict'; | ||
|
||
if (this.element_.classList.contains(this.CssClasses_.INDETERMINATE_CLASS)) { | ||
return; | ||
} | ||
|
||
this.progressbar_.style.width = p + '%'; | ||
}; | ||
|
||
MaterialProgress.prototype.setBuffer = function(p) { | ||
'use strict'; | ||
|
||
this.bufferbar_.style.width = p + '%'; | ||
this.auxbar_.style.width = (100-p) + '%'; | ||
}; | ||
|
||
/** | ||
* Initialize element. | ||
*/ | ||
MaterialProgress.prototype.init = function() { | ||
'use strict'; | ||
|
||
if (this.element_) { | ||
var el = document.createElement('div'); | ||
el.className = 'progressbar bar bar1'; | ||
this.element_.appendChild(el); | ||
this.progressbar_ = el; | ||
|
||
el = document.createElement('div'); | ||
el.className = 'bufferbar bar bar2'; | ||
this.element_.appendChild(el); | ||
this.bufferbar_ = el; | ||
|
||
el = document.createElement('div'); | ||
el.className = 'auxbar bar bar3'; | ||
this.element_.appendChild(el); | ||
this.auxbar_ = el; | ||
|
||
this.progressbar_.style.width = '0%'; | ||
this.bufferbar_.style.width = '100%'; | ||
this.auxbar_.style.width = '0%'; | ||
|
||
this.element_.classList.add('is-upgraded'); | ||
} | ||
}; | ||
|
||
// The component registers itself. It can assume componentHandler is available | ||
// in the global scope. | ||
componentHandler.register({ | ||
constructor: MaterialProgress, | ||
classAsString: 'MaterialProgress', | ||
cssClass: 'wsk-js-progress' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
describe('progress tests', function () { | ||
|
||
it('Should have MaterialProgress globally available', function () { | ||
expect(MaterialProgress).to.be.a('function'); | ||
}); | ||
|
||
it('Should be upgraded to a MaterialProgress successfully', function () { | ||
var el = document.createElement('div'); | ||
componentHandler.upgradeElement(el, 'MaterialProgress'); | ||
expect($(el)).to.have.data('upgraded', ',MaterialProgress'); | ||
}); | ||
|
||
it('Should have a setProgress method', function () { | ||
var el = document.createElement('div'); | ||
componentHandler.upgradeElement(el, 'MaterialProgress'); | ||
expect(el.widget.setProgress).to.be.a('function'); | ||
}); | ||
|
||
it('Should have a setBuffer method', function () { | ||
var el = document.createElement('div'); | ||
componentHandler.upgradeElement(el, 'MaterialProgress'); | ||
expect(el.widget.setBuffer).to.be.a('function'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!doctype html> | ||
<html lang=""> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Spinner</title> | ||
|
||
<link href='//fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en' rel='stylesheet' type='text/css'> | ||
|
||
<link rel="stylesheet" href="../../css/material.css"> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="demo-preview-block"> | ||
|
||
<p> | ||
Default: | ||
<div id="p1" class="wsk-js-progress"></div> | ||
</p> | ||
|
||
<p> | ||
Indeterminate: | ||
<div id="p2" class="wsk-js-progress wsk-progress__indeterminate"></div> | ||
</p> | ||
|
||
<p> | ||
Buffering: | ||
<div id="p3" class="wsk-js-progress"></div> | ||
</p> | ||
</div> | ||
<script> | ||
window.setTimeout(function() { | ||
document.querySelector('#p1').widget.setProgress(44); | ||
document.querySelector('#p3').widget.setProgress(33); | ||
document.querySelector('#p3').widget.setBuffer(87); | ||
}, 1000); | ||
</script> | ||
<script src="../../js/material.js"></script> | ||
|
||
</body> | ||
</html> |