shoelace/src/components/progress-bar/progress-bar.ts

59 wiersze
1.7 KiB
TypeScript
Czysty Zwykły widok Historia

import { LitElement, html, property, unsafeCSS } from 'lit-element';
2021-03-06 17:01:39 +00:00
import { classMap } from 'lit-html/directives/class-map';
import { styleMap } from 'lit-html/directives/style-map';
import { tag } from '../../internal/decorators';
2021-02-26 14:09:13 +00:00
import styles from 'sass:./progress-bar.scss';
/**
* @since 2.0
* @status stable
*
* @slot - A label to show inside the indicator.
*
* @part base - The component's base wrapper.
* @part indicator - The progress bar indicator.
* @part label - The progress bar label.
*/
@tag('sl-progress-bar')
2021-03-09 00:14:32 +00:00
export default class SlProgressBar extends LitElement {
2021-03-06 17:01:39 +00:00
static styles = unsafeCSS(styles);
2021-02-26 14:09:13 +00:00
/** The progress bar's percentage, 0 to 100. */
2021-03-06 17:01:39 +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-03-06 17:01:39 +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"
aria-valuenow="${this.indeterminate ? null : this.percentage}"
>
<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:09:08 +00:00
declare global {
interface HTMLElementTagNameMap {
'sl-progress-bar': SlProgressBar;
}
}