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

56 wiersze
1.6 KiB
TypeScript

import { LitElement, html } from 'lit';
import { customElement, property, query } from 'lit/decorators.js';
import styles from './progress-ring.styles';
/**
* @since 2.0
* @status stable
*
* @slot - A label to show inside the ring.
*
* @csspart base - The component's base wrapper.
* @csspart label - The progress ring label.
*
* @cssproperty --size - The diameter of the progress ring (cannot be a percentage).
* @cssproperty --track-width - The width of the track.
* @cssproperty --track-color - The color of the track.
* @cssproperty --indicator-color - The indicator color.
*/
@customElement('sl-progress-ring')
export default class SlProgressRing extends LitElement {
static styles = styles;
@query('.progress-ring__indicator') indicator: SVGCircleElement;
/** The current progress percentage, 0 - 100. */
@property({ type: Number, reflect: true }) percentage: number;
render() {
return html`
<div
part="base"
class="progress-ring"
role="progressbar"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="${this.percentage}"
>
<svg class="progress-ring__image" style="--percentage: ${this.percentage}; --pi: ${Math.PI.toFixed(10)}">
<circle class="progress-ring__track"></circle>
<circle class="progress-ring__indicator"></circle>
</svg>
<span part="label" class="progress-ring__label">
<slot></slot>
</span>
</div>
`;
}
}
declare global {
interface HTMLElementTagNameMap {
'sl-progress-ring': SlProgressRing;
}
}