UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

247 lines (245 loc) 7.43 kB
import { j as p } from "../jsx-runtime-DS1N_tNq.js"; import * as i from "react"; import "react-dom"; import { c as V } from "../index-DLcqcWxM.js"; import { c as A } from "../utils-B6fNqzRf.js"; function O(e, r = []) { let o = []; function n(a, u) { const s = i.createContext(u); s.displayName = a + "Context"; const l = o.length; o = [...o, u]; const c = (f) => { var S; const { scope: d, children: P, ...m } = f, x = ((S = d == null ? void 0 : d[e]) == null ? void 0 : S[l]) || s, I = i.useMemo(() => m, Object.values(m)); return /* @__PURE__ */ p.jsx(x.Provider, { value: I, children: P }); }; c.displayName = a + "Provider"; function v(f, d) { var x; const P = ((x = d == null ? void 0 : d[e]) == null ? void 0 : x[l]) || s, m = i.useContext(P); if (m) return m; if (u !== void 0) return u; throw new Error(`\`${f}\` must be used within \`${a}\``); } return [c, v]; } const t = () => { const a = o.map((u) => i.createContext(u)); return function(s) { const l = (s == null ? void 0 : s[e]) || a; return i.useMemo( () => ({ [`__scope${e}`]: { ...s, [e]: l } }), [s, l] ); }; }; return t.scopeName = e, [n, L(t, ...r)]; } function L(...e) { const r = e[0]; if (e.length === 1) return r; const o = () => { const n = e.map((t) => ({ useScope: t(), scopeName: t.scopeName })); return function(a) { const u = n.reduce((s, { useScope: l, scopeName: c }) => { const f = l(a)[`__scope${c}`]; return { ...s, ...f }; }, {}); return i.useMemo(() => ({ [`__scope${r.scopeName}`]: u }), [u]); }; }; return o.scopeName = r.scopeName, o; } var M = Symbol.for("react.lazy"), g = i[" use ".trim().toString()]; function D(e) { return typeof e == "object" && e !== null && "then" in e; } function $(e) { return e != null && typeof e == "object" && "$$typeof" in e && e.$$typeof === M && "_payload" in e && D(e._payload); } // @__NO_SIDE_EFFECTS__ function T(e) { const r = /* @__PURE__ */ W(e), o = i.forwardRef((n, t) => { let { children: a, ...u } = n; $(a) && typeof g == "function" && (a = g(a._payload)); const s = i.Children.toArray(a), l = s.find(F); if (l) { const c = l.props.children, v = s.map((f) => f === l ? i.Children.count(c) > 1 ? i.Children.only(null) : i.isValidElement(c) ? c.props.children : null : f); return /* @__PURE__ */ p.jsx(r, { ...u, ref: t, children: i.isValidElement(c) ? i.cloneElement(c, void 0, v) : null }); } return /* @__PURE__ */ p.jsx(r, { ...u, ref: t, children: a }); }); return o.displayName = `${e}.Slot`, o; } // @__NO_SIDE_EFFECTS__ function W(e) { const r = i.forwardRef((o, n) => { let { children: t, ...a } = o; if ($(t) && typeof g == "function" && (t = g(t._payload)), i.isValidElement(t)) { const u = k(t), s = H(a, t.props); return t.type !== i.Fragment && (s.ref = n ? V(n, u) : u), i.cloneElement(t, s); } return i.Children.count(t) > 1 ? i.Children.only(null) : null; }); return r.displayName = `${e}.SlotClone`, r; } var B = Symbol("radix.slottable"); function F(e) { return i.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === B; } function H(e, r) { const o = { ...r }; for (const n in r) { const t = e[n], a = r[n]; /^on[A-Z]/.test(n) ? t && a ? o[n] = (...s) => { const l = a(...s); return t(...s), l; } : t && (o[n] = t) : n === "style" ? o[n] = { ...t, ...a } : n === "className" && (o[n] = [t, a].filter(Boolean).join(" ")); } return { ...e, ...o }; } function k(e) { var n, t; let r = (n = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : n.get, o = r && "isReactWarning" in r && r.isReactWarning; return o ? e.ref : (r = (t = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : t.get, o = r && "isReactWarning" in r && r.isReactWarning, o ? e.props.ref : e.props.ref || e.ref); } var z = [ "a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "select", "span", "svg", "ul" ], N = z.reduce((e, r) => { const o = /* @__PURE__ */ T(`Primitive.${r}`), n = i.forwardRef((t, a) => { const { asChild: u, ...s } = t, l = u ? o : r; return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ p.jsx(l, { ...s, ref: a }); }); return n.displayName = `Primitive.${r}`, { ...e, [r]: n }; }, {}), b = "Progress", h = 100, [G, ne] = O(b), [X, Y] = G(b), E = i.forwardRef( (e, r) => { const { __scopeProgress: o, value: n = null, max: t, getValueLabel: a = Z, ...u } = e; (t || t === 0) && !C(t) && console.error(U(`${t}`, "Progress")); const s = C(t) ? t : h; n !== null && !_(n, s) && console.error(q(`${n}`, "Progress")); const l = _(n, s) ? n : null, c = y(l) ? a(l, s) : void 0; return /* @__PURE__ */ p.jsx(X, { scope: o, value: l, max: s, children: /* @__PURE__ */ p.jsx( N.div, { "aria-valuemax": s, "aria-valuemin": 0, "aria-valuenow": y(l) ? l : void 0, "aria-valuetext": c, role: "progressbar", "data-state": R(l, s), "data-value": l ?? void 0, "data-max": s, ...u, ref: r } ) }); } ); E.displayName = b; var j = "ProgressIndicator", w = i.forwardRef( (e, r) => { const { __scopeProgress: o, ...n } = e, t = Y(j, o); return /* @__PURE__ */ p.jsx( N.div, { "data-state": R(t.value, t.max), "data-value": t.value ?? void 0, "data-max": t.max, ...n, ref: r } ); } ); w.displayName = j; function Z(e, r) { return `${Math.round(e / r * 100)}%`; } function R(e, r) { return e == null ? "indeterminate" : e === r ? "complete" : "loading"; } function y(e) { return typeof e == "number"; } function C(e) { return y(e) && !isNaN(e) && e > 0; } function _(e, r) { return y(e) && !isNaN(e) && e <= r && e >= 0; } function U(e, r) { return `Invalid prop \`max\` of value \`${e}\` supplied to \`${r}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${h}\`.`; } function q(e, r) { return `Invalid prop \`value\` of value \`${e}\` supplied to \`${r}\`. The \`value\` prop must be: - a positive number - less than the value passed to \`max\` (or ${h} if no \`max\` prop is set) - \`null\` or \`undefined\` if the progress is indeterminate. Defaulting to \`null\`.`; } var J = E, K = w; function oe({ className: e, value: r, children: o, ...n }) { return /* @__PURE__ */ p.jsxs( J, { "data-slot": "progress", className: A( "bg-primary/20 relative h-3 w-full overflow-hidden rounded-full", e ), ...n, children: [ /* @__PURE__ */ p.jsx( K, { "data-slot": "progress-indicator", className: "bg-primary h-full w-full flex-1 transition-all", style: { transform: `translateX(-${100 - (r || 0)}%)` } } ), /* @__PURE__ */ p.jsx( "div", { className: "text-body-2xs-semi-bold text-inverted absolute top-0 left-1 leading-3.5", children: o } ) ] } ); } export { oe as Progress };