diff --git a/progress/demo/demo.ts b/progress/demo/demo.ts index 897c193eb..d2556f542 100644 --- a/progress/demo/demo.ts +++ b/progress/demo/demo.ts @@ -23,6 +23,7 @@ function cssWire(prop: string, unit = '') { const collection = new MaterialCollection>( 'Progress indicators', [ new Knob('value', {ui: numberInput({step: 0.1}), defaultValue: 0.5}), + new Knob('max', {ui: numberInput(), defaultValue: 1}), new Knob('indeterminate', {ui: boolInput(), defaultValue: false}), new Knob('fourColor', {ui: boolInput(), defaultValue: false}), new Knob( diff --git a/progress/demo/stories.ts b/progress/demo/stories.ts index 2d8d3b1e4..bc83ee55c 100644 --- a/progress/demo/stories.ts +++ b/progress/demo/stories.ts @@ -20,6 +20,7 @@ import {classMap} from 'lit/directives/class-map.js'; /** Knob types for linear progress stories. */ export interface StoryKnobs { value: number; + max: number; 'buffer (linear)': number; indeterminate: boolean; fourColor: boolean; @@ -47,7 +48,7 @@ const standard: MaterialStoryInit = { } `, render(knobs) { - const {value, indeterminate, fourColor} = knobs; + const {value, max, indeterminate, fourColor} = knobs; const buffer = knobs['buffer (linear)']; const classes = {'custom': knobs['custom theme (linear)']}; @@ -55,6 +56,7 @@ const standard: MaterialStoryInit = { = { const standardCircular: MaterialStoryInit = { name: 'Circular progress', - render({value, indeterminate, fourColor}) { + render({value, max, indeterminate, fourColor}) { return html` `; @@ -87,7 +90,7 @@ const iconButton: MaterialStoryInit = { position: absolute; } `, - render({value, indeterminate, fourColor}) { + render({value, max, indeterminate, fourColor}) { const toggle = ({target}: Event) => { const spinner = ((target as HTMLElement).parentElement as MdCircularProgress); @@ -98,6 +101,7 @@ const iconButton: MaterialStoryInit = {
@@ -116,7 +120,7 @@ const insideButton: MaterialStoryInit = { --md-tonal-button-with-icon-spacing-trailing: 8px; width: 80px; }`, - render({value, indeterminate, fourColor}) { + render({value, max, indeterminate, fourColor}) { const loadTime = 2500; let loadTimeout = -1; const toggleLoad = (target: MdTonalButton) => { @@ -141,6 +145,7 @@ const insideButton: MaterialStoryInit = { }}> diff --git a/progress/lib/circular-progress.ts b/progress/lib/circular-progress.ts index 55594ade1..1da9c5f86 100644 --- a/progress/lib/circular-progress.ts +++ b/progress/lib/circular-progress.ts @@ -23,15 +23,16 @@ export class CircularProgress extends Progress { // Determinate mode is rendered with an svg so the progress arc can be // easily animated via stroke-dashoffset. private renderDeterminateContainer() { - const dashOffset = (1 - this.value) * 100; + const dashOffset = (1 - this.value / this.max) * 100; // note, dash-array/offset are relative to Setting `pathLength` but // Chrome seems to render this inaccurately and using a large viewbox helps. - const pathLength = 100; - return html` - - - `; + return html` + + + + + `; } // Indeterminate mode rendered with 2 bordered-divs. The borders are diff --git a/progress/lib/linear-progress.ts b/progress/lib/linear-progress.ts index 07726ada5..69be0669c 100644 --- a/progress/lib/linear-progress.ts +++ b/progress/lib/linear-progress.ts @@ -36,10 +36,12 @@ export class LinearProgress extends Progress { // due to a now fixed Chrome bug: crbug.com/389359. protected override renderIndicator() { const progressStyles = { - transform: `scaleX(${(this.indeterminate ? 1 : this.value) * 100}%)` + transform: + `scaleX(${(this.indeterminate ? 1 : this.value / this.max) * 100}%)` }; const bufferStyles = { - transform: `scaleX(${(this.indeterminate ? 1 : this.buffer) * 100}%)` + transform: + `scaleX(${(this.indeterminate ? 1 : this.buffer / this.max) * 100}%)` }; return html` diff --git a/progress/lib/progress.ts b/progress/lib/progress.ts index a3910afa3..342c051b5 100644 --- a/progress/lib/progress.ts +++ b/progress/lib/progress.ts @@ -20,10 +20,15 @@ export abstract class Progress extends LitElement { } /** - * Progress to display, a fraction between 0 and 1. + * Progress to display, a fraction between 0 and `max`. */ @property({type: Number}) value = 0; + /** + * Maximum progress to display, defaults to 1. + */ + @property({type: Number}) max = 1; + /** * Whether or not to display indeterminate progress, which gives no indication * to how long an activity will take. @@ -43,7 +48,7 @@ export abstract class Progress extends LitElement { role="progressbar" aria-label="${ariaLabel || nothing}" aria-valuemin="0" - aria-valuemax="1" + aria-valuemax=${this.max} aria-valuenow=${this.indeterminate ? nothing : this.value} >${this.renderIndicator()}
`;