@studiocms/ui
Version:
The UI library for StudioCMS. Includes the layouts & components we use to build StudioCMS.
33 lines (32 loc) • 739 B
JavaScript
class ProgressHelper {
bar;
progress;
value;
max;
constructor(id) {
this.bar = document.getElementById(id);
this.progress = this.bar.firstElementChild;
this.value = this.getValue();
this.max = this.getMax();
}
getValue() {
return Number.parseInt(this.bar.dataset.value, 10);
}
setValue(value) {
const max = Number.parseInt(this.bar.dataset.max, 10);
const percent = Math.round(value / max * 100);
this.progress.style.width = `${percent}%`;
}
getMax() {
return Number.parseInt(this.bar.dataset.max, 10);
}
setMax(value) {
this.bar.dataset.max = value.toString();
}
getPercentage() {
return Math.round(this.value / this.max * 100);
}
}
export {
ProgressHelper
};