File size: 1,311 Bytes
04ec17f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import { attachRef } from "svelte-toolbelt";
import { createBitsAttrs } from "../../internal/attrs.js";
const progressAttrs = createBitsAttrs({
component: "progress",
parts: ["root"],
});
export class ProgressRootState {
static create(opts) {
return new ProgressRootState(opts);
}
opts;
attachment;
constructor(opts) {
this.opts = opts;
this.attachment = attachRef(this.opts.ref);
}
props = $derived.by(() => ({
role: "progressbar",
value: this.opts.value.current,
"aria-valuemin": this.opts.min.current,
"aria-valuemax": this.opts.max.current,
"aria-valuenow": this.opts.value.current === null ? undefined : this.opts.value.current,
"data-value": this.opts.value.current === null ? undefined : this.opts.value.current,
"data-state": getProgressDataState(this.opts.value.current, this.opts.max.current),
"data-max": this.opts.max.current,
"data-min": this.opts.min.current,
"data-indeterminate": this.opts.value.current === null ? "" : undefined,
[progressAttrs.root]: "",
...this.attachment,
}));
}
function getProgressDataState(value, max) {
if (value === null)
return "indeterminate";
return value === max ? "loaded" : "loading";
}
|