@stanfordspezi/spezi-web-design-system
Version:
Stanford Biodesign Digital Health Spezi Web Design System
161 lines (159 loc) • 4.03 kB
JavaScript
import { jsx as u } from "react/jsx-runtime";
import { c as y } from "./index-DG4iIeSU.mjs";
import { c as $ } from "./index-2NvaPZWc.mjs";
import { s as w } from "./misc-CHmrAmhc.mjs";
import * as c from "react";
import { c as I } from "./index-DFZozV_h.mjs";
import "react-dom";
import { c as M } from "./index-D2LZVjSn.mjs";
var R = [
"a",
"button",
"div",
"form",
"h2",
"h3",
"img",
"input",
"label",
"li",
"nav",
"ol",
"p",
"select",
"span",
"svg",
"ul"
], g = R.reduce((r, e) => {
const s = M(`Primitive.${e}`), t = c.forwardRef((a, n) => {
const { asChild: l, ...o } = a, i = l ? s : e;
return typeof window < "u" && (window[/* @__PURE__ */ Symbol.for("radix-ui")] = !0), /* @__PURE__ */ u(i, { ...o, ref: n });
});
return t.displayName = `Primitive.${e}`, { ...r, [e]: t };
}, {}), m = "Progress", v = 100, [S] = I(m), [E, V] = S(m), x = c.forwardRef(
(r, e) => {
const {
__scopeProgress: s,
value: t = null,
max: a,
getValueLabel: n = _,
...l
} = r;
(a || a === 0) && !p(a) && console.error(C(`${a}`, "Progress"));
const o = p(a) ? a : v;
t !== null && !f(t, o) && console.error(A(`${t}`, "Progress"));
const i = f(t, o) ? t : null, h = d(i) ? n(i, o) : void 0;
return /* @__PURE__ */ u(E, { scope: s, value: i, max: o, children: /* @__PURE__ */ u(
g.div,
{
"aria-valuemax": o,
"aria-valuemin": 0,
"aria-valuenow": d(i) ? i : void 0,
"aria-valuetext": h,
role: "progressbar",
"data-state": N(i, o),
"data-value": i ?? void 0,
"data-max": o,
...l,
ref: e
}
) });
}
);
x.displayName = m;
var P = "ProgressIndicator", b = c.forwardRef(
(r, e) => {
const { __scopeProgress: s, ...t } = r, a = V(P, s);
return /* @__PURE__ */ u(
g.div,
{
"data-state": N(a.value, a.max),
"data-value": a.value ?? void 0,
"data-max": a.max,
...t,
ref: e
}
);
}
);
b.displayName = P;
function _(r, e) {
return `${Math.round(r / e * 100)}%`;
}
function N(r, e) {
return r == null ? "indeterminate" : r === e ? "complete" : "loading";
}
function d(r) {
return typeof r == "number";
}
function p(r) {
return d(r) && !isNaN(r) && r > 0;
}
function f(r, e) {
return d(r) && !isNaN(r) && r <= e && r >= 0;
}
function C(r, e) {
return `Invalid prop \`max\` of value \`${r}\` supplied to \`${e}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${v}\`.`;
}
function A(r, e) {
return `Invalid prop \`value\` of value \`${r}\` supplied to \`${e}\`. The \`value\` prop must be:
- a positive number
- less than the value passed to \`max\` (or ${v} if no \`max\` prop is set)
- \`null\` or \`undefined\` if the progress is indeterminate.
Defaulting to \`null\`.`;
}
var D = x, L = b;
const O = y(
"relative h-1 w-full overflow-hidden rounded-full",
{
variants: {
color: {
primary: "bg-primary/10",
foreground: "bg-foreground/10",
destructive: "bg-destructive/10"
}
}
}
), k = ({
className: r,
value: e,
max: s = 100,
color: t = "foreground",
...a
}) => {
const n = Number.isFinite(s) && s > 0 ? s : 100, l = Math.min(Math.max(e ?? 0, 0), n), o = l / n * 100;
return /* @__PURE__ */ u(
D,
{
"data-slot": "progress",
"data-color": t,
className: O({ color: t, className: r }),
value: l,
max: n,
...a,
children: /* @__PURE__ */ u(
L,
{
"data-slot": "progress-indicator",
className: $(
"size-full flex-1 transition",
w(
{
primary: "bg-primary",
foreground: "bg-foreground",
destructive: "bg-destructive"
},
t
)
),
style: {
transform: `translateX(-${100 - o}%)`
}
}
)
}
);
};
export {
k as P
};