mirror of
https://github.com/material-components/material-web.git
synced 2024-09-11 13:46:10 +03:00
Merge pull request #5352 from datvm:linear-progress-buffer
PiperOrigin-RevId: 609528198
This commit is contained in:
commit
2613de471b
@ -16,8 +16,9 @@ import {Progress} from './progress.js';
|
|||||||
export class LinearProgress extends Progress {
|
export class LinearProgress extends Progress {
|
||||||
/**
|
/**
|
||||||
* Buffer amount to display, a fraction between 0 and `max`.
|
* Buffer amount to display, a fraction between 0 and `max`.
|
||||||
|
* If the value is 0 or negative, the buffer is not displayed.
|
||||||
*/
|
*/
|
||||||
@property({type: Number}) buffer = 1;
|
@property({type: Number}) buffer = 0;
|
||||||
|
|
||||||
// Note, the indeterminate animation is rendered with transform %'s
|
// Note, the indeterminate animation is rendered with transform %'s
|
||||||
// Previously, this was optimized to use px calculated with the resizeObserver
|
// Previously, this was optimized to use px calculated with the resizeObserver
|
||||||
@ -28,16 +29,20 @@ export class LinearProgress extends Progress {
|
|||||||
(this.indeterminate ? 1 : this.value / this.max) * 100
|
(this.indeterminate ? 1 : this.value / this.max) * 100
|
||||||
}%)`,
|
}%)`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const bufferValue = this.buffer ?? 0;
|
||||||
|
const hasBuffer = bufferValue > 0;
|
||||||
|
|
||||||
|
const dotSize = this.indeterminate || !hasBuffer ? 1 : bufferValue / this.max;
|
||||||
|
|
||||||
const dotStyles = {
|
const dotStyles = {
|
||||||
transform: `scaleX(${
|
transform: `scaleX(${dotSize * 100}%)`,
|
||||||
(this.indeterminate ? 1 : this.buffer / this.max) * 100
|
|
||||||
}%)`,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only display dots when visible - this prevents invisible infinite
|
// Only display dots when visible - this prevents invisible infinite
|
||||||
// animation.
|
// animation.
|
||||||
const hideDots =
|
const hideDots =
|
||||||
this.indeterminate || this.buffer >= this.max || this.value >= this.max;
|
this.indeterminate || !hasBuffer || bufferValue >= this.max || this.value >= this.max;
|
||||||
return html`
|
return html`
|
||||||
<div class="dots" ?hidden=${hideDots}></div>
|
<div class="dots" ?hidden=${hideDots}></div>
|
||||||
<div class="inactive-track" style=${styleMap(dotStyles)}></div>
|
<div class="inactive-track" style=${styleMap(dotStyles)}></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user