/** * @license * Copyright 2023 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import {html, LitElement, nothing} from 'lit'; import {property, query, state} from 'lit/decorators.js'; import {classMap} from 'lit/directives/class-map.js'; import {styleMap} from 'lit/directives/style-map.js'; import {requestUpdateOnAriaChange} from '../../aria/delegate.js'; import {ARIAMixinStrict} from '../../types/aria.js'; /** * A linear progress component. */ export class LinearProgress extends LitElement { static { requestUpdateOnAriaChange(this); } /** * Whether or not to render indeterminate progress in an animated state. */ @property({type: Boolean}) indeterminate = false; /** * Progress to display, a fraction between 0 and 1. */ @property({type: Number}) progress = 0; /** * Buffer amount to display, a fraction between 0 and 1. */ @property({type: Number}) buffer = 1; /** * Whether or not to render indeterminate mode using 4 colors instead of one. * */ @property({type: Boolean, attribute: 'four-color'}) fourColor = false; @query('.linear-progress') private readonly rootEl!: HTMLElement|null; @state() private animationReady = true; private resizeObserver: ResizeObserver|null = null; // Note, the indeterminate animation is rendered with transform %'s // Previously, this was optimized to use px calculated with the resizeObserver // due to a now fixed Chrome bug: crbug.com/389359. protected override render() { const rootClasses = { 'indeterminate': this.indeterminate, 'animation-ready': this.animationReady, 'four-color': this.fourColor }; const progressStyles = { transform: `scaleX(${(this.indeterminate ? 1 : this.progress) * 100}%)` }; const bufferStyles = { transform: `scaleX(${(this.indeterminate ? 1 : this.buffer) * 100}%)` }; // Needed for closure conformance const {ariaLabel} = this as ARIAMixinStrict; return html`