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-09-21 02:01:21 +00:00
|
|
|
import { classMap } from 'lit-html/directives/class-map.js';
|
|
|
|
import { styleMap } from 'lit-html/directives/style-map.js';
|
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-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
/** The progress bar's percentage, 0 to 100. */
|
2021-07-01 00:04:46 +00:00
|
|
|
@property({ type: Number, reflect: true }) percentage = 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
|
|
|
|
|
|
|
render() {
|
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
part="base"
|
|
|
|
class=${classMap({
|
|
|
|
'progress-bar': true,
|
|
|
|
'progress-bar--indeterminate': this.indeterminate
|
|
|
|
})}
|
|
|
|
role="progressbar"
|
|
|
|
aria-valuemin="0"
|
|
|
|
aria-valuemax="100"
|
2021-05-03 15:25:20 +00:00
|
|
|
aria-valuenow="${this.indeterminate ? '' : this.percentage}"
|
2021-02-26 14:09:13 +00:00
|
|
|
>
|
|
|
|
<div part="indicator" class="progress-bar__indicator" style=${styleMap({ width: this.percentage + '%' })}>
|
|
|
|
${!this.indeterminate
|
|
|
|
? html`
|
|
|
|
<span part="label" class="progress-bar__label">
|
2021-03-06 17:01:39 +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;
|
|
|
|
}
|
|
|
|
}
|