2021-07-10 00:45:44 +00:00
|
|
|
import { LitElement, html } from 'lit';
|
2021-05-27 21:00:43 +00:00
|
|
|
import { customElement, property } from 'lit/decorators.js';
|
2021-10-10 02:24:01 +00:00
|
|
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
2021-09-29 12:40:26 +00:00
|
|
|
import { classMap } from 'lit/directives/class-map.js';
|
|
|
|
import { styleMap } from 'lit/directives/style-map.js';
|
2021-12-06 15:57:54 +00:00
|
|
|
import { LocalizeController } from '../../utilities/localize';
|
2021-07-10 00:45:44 +00:00
|
|
|
import styles from './progress-bar.styles';
|
2021-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.0
|
|
|
|
* @status stable
|
|
|
|
*
|
2021-06-25 20:25:46 +00:00
|
|
|
* @slot - A label to show inside the indicator.
|
2021-02-26 14:09:13 +00:00
|
|
|
*
|
2021-06-25 20:25:46 +00:00
|
|
|
* @csspart base - The component's base wrapper.
|
|
|
|
* @csspart indicator - The progress bar indicator.
|
|
|
|
* @csspart label - The progress bar label.
|
2021-05-17 22:04:28 +00:00
|
|
|
*
|
2021-06-25 20:25:46 +00:00
|
|
|
* @cssproperty --height - The progress bar's height.
|
|
|
|
* @cssproperty --track-color - The track color.
|
|
|
|
* @cssproperty --indicator-color - The indicator color.
|
|
|
|
* @cssproperty --label-color - The label color.
|
2021-02-26 14:09:13 +00:00
|
|
|
*/
|
2021-03-18 13:04:23 +00:00
|
|
|
@customElement('sl-progress-bar')
|
2021-03-09 00:14:32 +00:00
|
|
|
export default class SlProgressBar extends LitElement {
|
2021-07-10 00:45:44 +00:00
|
|
|
static styles = styles;
|
2021-12-06 15:57:54 +00:00
|
|
|
private localize = new LocalizeController(this);
|
2021-02-26 14:09:13 +00:00
|
|
|
|
2021-09-30 13:02:28 +00:00
|
|
|
/** The current progress, 0 to 100. */
|
|
|
|
@property({ type: Number, reflect: true }) value = 0;
|
2021-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
/** When true, percentage is ignored, the label is hidden, and the progress bar is drawn in an indeterminate state. */
|
2021-07-01 00:04:46 +00:00
|
|
|
@property({ type: Boolean, reflect: true }) indeterminate = false;
|
2021-02-26 14:09:13 +00:00
|
|
|
|
2021-12-06 15:57:54 +00:00
|
|
|
/** A custom label for the progress bar's aria label. */
|
|
|
|
@property() label: string;
|
|
|
|
|
|
|
|
/** The locale to render the component in. */
|
|
|
|
@property() lang: string;
|
2021-10-10 02:24:01 +00:00
|
|
|
|
2021-02-26 14:09:13 +00:00
|
|
|
render() {
|
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
part="base"
|
|
|
|
class=${classMap({
|
|
|
|
'progress-bar': true,
|
|
|
|
'progress-bar--indeterminate': this.indeterminate
|
|
|
|
})}
|
|
|
|
role="progressbar"
|
2021-10-10 02:24:01 +00:00
|
|
|
title=${ifDefined(this.title)}
|
2021-12-06 15:57:54 +00:00
|
|
|
aria-label=${this.label || this.localize.term('progress')}
|
2021-02-26 14:09:13 +00:00
|
|
|
aria-valuemin="0"
|
|
|
|
aria-valuemax="100"
|
2021-10-14 12:24:38 +00:00
|
|
|
aria-valuenow=${this.indeterminate ? 0 : this.value}
|
2021-02-26 14:09:13 +00:00
|
|
|
>
|
2021-09-30 13:02:28 +00:00
|
|
|
<div part="indicator" class="progress-bar__indicator" style=${styleMap({ width: this.value + '%' })}>
|
2021-02-26 14:09:13 +00:00
|
|
|
${!this.indeterminate
|
|
|
|
? html`
|
|
|
|
<span part="label" class="progress-bar__label">
|
2021-11-18 22:41:03 +00:00
|
|
|
<slot></slot>
|
2021-02-26 14:09:13 +00:00
|
|
|
</span>
|
|
|
|
`
|
|
|
|
: ''}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
2021-03-12 14:07:38 +00:00
|
|
|
|
2021-03-12 14:09:08 +00:00
|
|
|
declare global {
|
|
|
|
interface HTMLElementTagNameMap {
|
|
|
|
'sl-progress-bar': SlProgressBar;
|
|
|
|
}
|
|
|
|
}
|