|
21 | 21 | left: 0; |
22 | 22 | transform: scaleX(0); |
23 | 23 | 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; |
25 | 29 | } |
26 | 30 |
|
27 | 31 | #primaryProgress::after { |
28 | 32 | content: ""; |
29 | 33 | 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; |
31 | 39 | } |
32 | 40 |
|
33 | 41 | @keyframes indeterminate-bar { |
|
67 | 75 | </template> |
68 | 76 |
|
69 | 77 | <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 | + } |
73 | 109 |
|
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'); |
77 | 116 | } |
| 117 | + } |
78 | 118 |
|
79 | | - document.registerElement('progress-bar', {prototype: prototype}); |
80 | | - })(); |
| 119 | + customElements.define('progress-bar', ProgressBar); |
81 | 120 | </script> |
0 commit comments