${when(this.label || this.value,
() => html`
${this.linearProgressBarLabel}
`,
)}
`
}
getInfinityScrollLoader() {
return html`
${this.getLoader()}
${this.displayedLabel}
${when(!!this.displayedLabelText, () => html`
${this.displayedLabelText}
`)}
`
}
completeFilling(element: SVGElement, radius: number, value: number) {
if (!this.workTime)
return
const dasharray = this.calcStrokeDasharray(radius)
const dashoffset = this.calcStrokeDashoffset(value, dasharray)
element.style.setProperty('--stroke-min', `${dasharray}px`)
element.style.setProperty('--stroke-max', `${dashoffset}px`)
element.style.animation = `filling ${this.workTime / 1000}s linear`
const setDoneState = () => {
this.value = 100
}
const options = { once: true }
element.addEventListener('animationend', setDoneState, options)
}
updatedWorkTime() {
const circle = this.circleRef.value
if (!circle || !this.workTime)
return
const circleOneRadius = this.circle_1.radius
return this.completeFilling(circle, circleOneRadius, this.value)
}
updatedType() {
if (this.type === 'infinity' || this.type === 'infinity-scroll') {
this.value = 25
this.circle_1.strokeDashoffset = this.calcStrokeDashoffset(this.value, this.circle_1.strokeDasharray)
}
if (this.type === 'infinity-scroll') {
this.circle_1 = this.circle_2 = this.recalcCircleParams(24, this.loaderStrokeWidthSmall)
} else {
this.circle_1 = this.recalcCircleParams(this.circleLoaderDaimeter, this.circleLoaderStroke)
this.circle_2 = this.recalcCircleParams(this.circleLoaderDaimeter, this.circleLoaderStroke)
}
}
updatedValue() {
this.isDone = this.value >= 100
this.value = this.value > 100 ? 100 : this.value
this.circle_1.strokeDashoffset = this.calcStrokeDashoffset(this.value, this.circle_1.strokeDasharray)
if (this.isDone) {
setTimeout(() => {
this.dispatchEvent(new CustomEvent('done'))
}, 500)
}
}
updateLabel() {
if (this.showPercentages && !this.isDone)
this.displayedLabel = `${this.value}%`
else if (this.isDone)
this.displayedLabel = this.checkedMark
}
updateLabelText() {
this.displayedLabelText = this.isDone ? this.doneLabel : this.label
}
updateLinearLoaderLabel() {
if (this.value)
this.linearProgressBarLabel = `${this.value}%${this.value < 100 ? '...' : ''}`
else
this.linearProgressBarLabel = this.label
}
recalcCircleParams(circleDaimeter: number, strokeWidth: number): ILoaderCircle {
const radius = this.calcRadius(circleDaimeter, strokeWidth)
const strokeDasharray = this.calcStrokeDasharray(radius)
const strokeDashoffset = this.calcStrokeDashoffset(this.value, strokeDasharray)
return { circleDaimeter, strokeWidth, radius, strokeDasharray, strokeDashoffset }
}
calcRadius(circleDaimeter: number, strokeWidth: number): number {
return circleDaimeter / 2 - strokeWidth / 2
}
calcStrokeDasharray(radius: number): number {
const strokeDasharray = Math.PI * radius * 2
return Math.round(strokeDasharray * 100) / 100
}
calcStrokeDashoffset(value: number, strokeDasharray: number): number {
const currentValue = (value !== undefined && value !== null) ? value : 100
const strokeDashoffset = ((100 - currentValue) / 100) * strokeDasharray
return Math.round(strokeDashoffset * 100) / 100
}
getLoaderContainerClasses(): DirectiveResult