Skip to content

Commit ab8acaa

Browse files
committed
Update to v1 and add gracefully disable option
1 parent 51585c9 commit ab8acaa

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@
3939
<progress-bar class="fast"></progress-bar>
4040
```
4141

42-
# API reference
42+
## Finish gracefully
43+
Use the `disable` attribute to let the progress bar finish gracefully instead of abruptly.
44+
45+
46+
## API reference
4347

4448
Disable the progress element using the `hidden` attribute.
4549

4650
Custom property | Description | Default
4751
-------------------------------------------------|---------------------------------------------|--------------
4852
`--progress-bar-color ` | Color of the progress bar | `#37A0CE`
49-
`--progress-bar-duration` | Duration of the animation | `0.2s`
53+
`--progress-bar-duration` | Duration of the animation | `1s`
5054
`--progress-bar-delay` | Delay before the animation begins | `0s`

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "progress-bar.html",
55
"keywords": ["loading", "progress", "bar"],
66
"devDependencies": {
7-
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
7+
"webcomponentsjs": "webcomponents/webcomponentsjs#^v1.0.0-rc.11"
88
},
99
"demos": {
1010
"Simple demo": "demo.html"

demo.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<head>
2+
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
23
<link rel="import" href="progress-bar.html">
34
</head>
45
<body>

progress-bar.html

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@
2121
left: 0;
2222
transform: scaleX(0);
2323
transform-origin: right center;
24-
animation: indeterminate-bar var(--progress-bar-duration, 2s) var(--progress-bar-delay, 0s) linear infinite;
24+
animation: indeterminate-bar var(--progress-bar-duration, 1s) var(--progress-bar-delay, 0s) linear infinite;
25+
}
26+
27+
#primaryProgress.finished {
28+
animation: none;
2529
}
2630

2731
#primaryProgress::after {
2832
content: "";
2933
transform-origin: center center;
30-
animation: indeterminate-splitter var(--progress-bar-duration, 2s) var(--progress-bar-delay, 0s) linear infinite;
34+
animation: indeterminate-splitter var(--progress-bar-duration, 1s) var(--progress-bar-delay, 0s) linear infinite;
35+
}
36+
37+
#primaryProgress.finished::after {
38+
animation: none;
3139
}
3240

3341
@keyframes indeterminate-bar {
@@ -67,15 +75,46 @@
6775
</template>
6876

6977
<script>
70-
(function() {
71-
var template = document.currentScript.ownerDocument.querySelector('template#progress-bar');
72-
var prototype = Object.create(HTMLElement.prototype);
78+
class ProgressBar extends HTMLElement {
79+
static get is() {
80+
return 'progress-bar';
81+
}
82+
83+
constructor() {
84+
super();
85+
const shadowRoot = this.attachShadow({mode: 'open'});
86+
const template = document.currentScript.ownerDocument.querySelector('template#progress-bar');
87+
shadowRoot.appendChild(template.content.cloneNode(true));
88+
}
89+
90+
static get observedAttributes() {
91+
return ['disabled'];
92+
}
93+
94+
get disabled() {
95+
return this.hasAttribute('disabled');
96+
}
97+
98+
set disabled(value) {
99+
if (value) {
100+
this.setAttribute('disabled', '');
101+
} else {
102+
this.removeAttribute('disabled');
103+
}
104+
}
105+
106+
_iterationCallback() {
107+
this.shadowRoot.querySelector('#primaryProgress').classList.add('finished');
108+
}
73109

74-
prototype.createdCallback = function() {
75-
this.setAttribute('role', 'progressbar');
76-
this.createShadowRoot().appendChild(document.importNode(template.content, true));
110+
attributeChangedCallback() {
111+
const progress = this.shadowRoot.querySelector('#primaryProgress');
112+
if (this.disabled)
113+
progress.addEventListener('animationiteration', this._iterationCallback.bind(this), {once: true, passive: true});
114+
else
115+
progress.classList.remove('finished');
77116
}
117+
}
78118

79-
document.registerElement('progress-bar', {prototype: prototype});
80-
})();
119+
customElements.define('progress-bar', ProgressBar);
81120
</script>

0 commit comments

Comments
 (0)