Add indeterminate mode

This commit is contained in:
pk
2026-08-05 22:18:55 +02:00
parent e5e1d8d1a1
commit 54d8ecbfd7
3 changed files with 42 additions and 7 deletions
+12 -1
View File
@@ -18,4 +18,15 @@ npm i @tp/tp-progress-bar
| Property | Type | Description | | Property | Type | Description |
| -------- | ---- | ----------- | | -------- | ---- | ----------- |
| `progress` | `Number` | The current progress of the progress bar. | `progress` | `Number` | The current progress of the progress bar (0-100). Ignored when `indeterminate` is set. |
| `indeterminate` | `Boolean` | When set, shows an animated indicator that travels back and forth continuously. Use for operations whose progress can't be determined. |
## Usage
```html
<!-- Determinate -->
<tp-progress-bar progress="50"></tp-progress-bar>
<!-- Indeterminate -->
<tp-progress-bar indeterminate></tp-progress-bar>
```
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@tp/tp-progress-bar", "name": "@tp/tp-progress-bar",
"version": "1.0.0", "version": "1.1.0",
"description": "", "description": "",
"main": "tp-progress-bar.js", "main": "tp-progress-bar.js",
"scripts": { "scripts": {
+27 -3
View File
@@ -15,9 +15,8 @@ export class TpProgressBar extends LitElement {
.bar { .bar {
background: #EEEEEE; background: #EEEEEE;
border-radius: 8px;
height: var(--tp-progress-bar-height, 16px);
border-radius: var(--tp-progress-bar-border-radius, 8px); border-radius: var(--tp-progress-bar-border-radius, 8px);
height: var(--tp-progress-bar-height, 16px);
position: relative; position: relative;
overflow: hidden; overflow: hidden;
transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0);
@@ -34,6 +33,29 @@ export class TpProgressBar extends LitElement {
background: var(--tp-progress-bar-color, #039BE5); background: var(--tp-progress-bar-color, #039BE5);
transition: transform 200ms linear; transition: transform 200ms linear;
} }
/* Indeterminate mode: a fixed-width indicator travels across the bar. */
:host([indeterminate]) #progress {
right: auto;
width: 40%;
transform: none;
transition: none;
animation: tp-progress-indeterminate 1.4s ease-in-out infinite;
}
@keyframes tp-progress-indeterminate {
0% {
left: -40%;
}
50% {
left: 100%;
}
100% {
left: -40%;
}
}
`; `;
} }
@@ -48,16 +70,18 @@ export class TpProgressBar extends LitElement {
static get properties() { static get properties() {
return { return {
progress: { type: Number }, progress: { type: Number },
indeterminate: { type: Boolean, reflect: true },
}; };
} }
constructor() { constructor() {
super(); super();
this.progress = 0; this.progress = 0;
this.indeterminate = false;
} }
updated(changedProperties) { updated(changedProperties) {
if (changedProperties.has('progress')) { if (changedProperties.has('progress') && !this.indeterminate) {
this._progressChanged(this.progress); this._progressChanged(this.progress);
} }
} }