UNPKG

@webkom/react-meter-bar

Version:

A simple react meter component

687 lines (683 loc) 22.5 kB
import Se from "react"; var N = {}, lr = { get exports() { return N; }, set exports(f) { N = f; } }, $ = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Te; function fr() { if (Te) return $; Te = 1; var f = Se, m = Symbol.for("react.element"), _ = Symbol.for("react.fragment"), h = Object.prototype.hasOwnProperty, p = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, T = { key: !0, ref: !0, __self: !0, __source: !0 }; function F(C, c, P) { var g, y = {}, S = null, W = null; P !== void 0 && (S = "" + P), c.key !== void 0 && (S = "" + c.key), c.ref !== void 0 && (W = c.ref); for (g in c) h.call(c, g) && !T.hasOwnProperty(g) && (y[g] = c[g]); if (C && C.defaultProps) for (g in c = C.defaultProps, c) y[g] === void 0 && (y[g] = c[g]); return { $$typeof: m, type: C, key: S, ref: W, props: y, _owner: p.current }; } return $.Fragment = _, $.jsx = F, $.jsxs = F, $; } var I = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Oe; function cr() { return Oe || (Oe = 1, process.env.NODE_ENV !== "production" && function() { var f = Se, m = Symbol.for("react.element"), _ = Symbol.for("react.portal"), h = Symbol.for("react.fragment"), p = Symbol.for("react.strict_mode"), T = Symbol.for("react.profiler"), F = Symbol.for("react.provider"), C = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), P = Symbol.for("react.suspense"), g = Symbol.for("react.suspense_list"), y = Symbol.for("react.memo"), S = Symbol.for("react.lazy"), W = Symbol.for("react.offscreen"), Z = Symbol.iterator, Pe = "@@iterator"; function xe(e) { if (e === null || typeof e != "object") return null; var r = Z && e[Z] || e[Pe]; return typeof r == "function" ? r : null; } var x = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function d(e) { { for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++) t[n - 1] = arguments[n]; je("error", e, t); } } function je(e, r, t) { { var n = x.ReactDebugCurrentFrame, i = n.getStackAddendum(); i !== "" && (r += "%s", t = t.concat([i])); var u = t.map(function(o) { return String(o); }); u.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, u); } } var ke = !1, Fe = !1, De = !1, Ae = !1, $e = !1, Q; Q = Symbol.for("react.module.reference"); function Ie(e) { return !!(typeof e == "string" || typeof e == "function" || e === h || e === T || $e || e === p || e === P || e === g || Ae || e === W || ke || Fe || De || typeof e == "object" && e !== null && (e.$$typeof === S || e.$$typeof === y || e.$$typeof === F || e.$$typeof === C || e.$$typeof === c || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === Q || e.getModuleId !== void 0)); } function Ne(e, r, t) { var n = e.displayName; if (n) return n; var i = r.displayName || r.name || ""; return i !== "" ? t + "(" + i + ")" : t; } function ee(e) { return e.displayName || "Context"; } function E(e) { if (e == null) return null; if (typeof e.tag == "number" && d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case h: return "Fragment"; case _: return "Portal"; case T: return "Profiler"; case p: return "StrictMode"; case P: return "Suspense"; case g: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case C: var r = e; return ee(r) + ".Consumer"; case F: var t = e; return ee(t._context) + ".Provider"; case c: return Ne(e, e.render, "ForwardRef"); case y: var n = e.displayName || null; return n !== null ? n : E(e.type) || "Memo"; case S: { var i = e, u = i._payload, o = i._init; try { return E(o(u)); } catch { return null; } } } return null; } var w = Object.assign, D = 0, re, te, ne, ae, oe, ie, ue; function se() { } se.__reactDisabledLog = !0; function We() { { if (D === 0) { re = console.log, te = console.info, ne = console.warn, ae = console.error, oe = console.group, ie = console.groupCollapsed, ue = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: se, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } D++; } } function Ye() { { if (D--, D === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: w({}, e, { value: re }), info: w({}, e, { value: te }), warn: w({}, e, { value: ne }), error: w({}, e, { value: ae }), group: w({}, e, { value: oe }), groupCollapsed: w({}, e, { value: ie }), groupEnd: w({}, e, { value: ue }) }); } D < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var B = x.ReactCurrentDispatcher, q; function Y(e, r, t) { { if (q === void 0) try { throw Error(); } catch (i) { var n = i.stack.trim().match(/\n( *(at )?)/); q = n && n[1] || ""; } return ` ` + q + e; } } var J = !1, L; { var Le = typeof WeakMap == "function" ? WeakMap : Map; L = new Le(); } function le(e, r) { if (!e || J) return ""; { var t = L.get(e); if (t !== void 0) return t; } var n; J = !0; var i = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var u; u = B.current, B.current = null, We(); try { if (r) { var o = function() { throw Error(); }; if (Object.defineProperty(o.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(o, []); } catch (R) { n = R; } Reflect.construct(e, [], o); } else { try { o.call(); } catch (R) { n = R; } e.call(o.prototype); } } else { try { throw Error(); } catch (R) { n = R; } e(); } } catch (R) { if (R && n && typeof R.stack == "string") { for (var a = R.stack.split(` `), v = n.stack.split(` `), s = a.length - 1, l = v.length - 1; s >= 1 && l >= 0 && a[s] !== v[l]; ) l--; for (; s >= 1 && l >= 0; s--, l--) if (a[s] !== v[l]) { if (s !== 1 || l !== 1) do if (s--, l--, l < 0 || a[s] !== v[l]) { var b = ` ` + a[s].replace(" at new ", " at "); return e.displayName && b.includes("<anonymous>") && (b = b.replace("<anonymous>", e.displayName)), typeof e == "function" && L.set(e, b), b; } while (s >= 1 && l >= 0); break; } } } finally { J = !1, B.current = u, Ye(), Error.prepareStackTrace = i; } var k = e ? e.displayName || e.name : "", Re = k ? Y(k) : ""; return typeof e == "function" && L.set(e, Re), Re; } function Ve(e, r, t) { return le(e, !1); } function Me(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function V(e, r, t) { if (e == null) return ""; if (typeof e == "function") return le(e, Me(e)); if (typeof e == "string") return Y(e); switch (e) { case P: return Y("Suspense"); case g: return Y("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case c: return Ve(e.render); case y: return V(e.type, r, t); case S: { var n = e, i = n._payload, u = n._init; try { return V(u(i), r, t); } catch { } } } return ""; } var M = Object.prototype.hasOwnProperty, fe = {}, ce = x.ReactDebugCurrentFrame; function U(e) { if (e) { var r = e._owner, t = V(e.type, e._source, r ? r.type : null); ce.setExtraStackFrame(t); } else ce.setExtraStackFrame(null); } function Ue(e, r, t, n, i) { { var u = Function.call.bind(M); for (var o in e) if (u(e, o)) { var a = void 0; try { if (typeof e[o] != "function") { var v = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw v.name = "Invariant Violation", v; } a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (s) { a = s; } a && !(a instanceof Error) && (U(i), d("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, o, typeof a), U(null)), a instanceof Error && !(a.message in fe) && (fe[a.message] = !0, U(i), d("Failed %s type: %s", t, a.message), U(null)); } } } var Be = Array.isArray; function G(e) { return Be(e); } function qe(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function Je(e) { try { return de(e), !1; } catch { return !0; } } function de(e) { return "" + e; } function ve(e) { if (Je(e)) return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", qe(e)), de(e); } var A = x.ReactCurrentOwner, Ge = { key: !0, ref: !0, __self: !0, __source: !0 }, pe, ge, z; z = {}; function ze(e) { if (M.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function Ke(e) { if (M.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function He(e, r) { if (typeof e.ref == "string" && A.current && r && A.current.stateNode !== r) { var t = E(A.current.type); z[t] || (d('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', E(A.current.type), e.ref), z[t] = !0); } } function Xe(e, r) { { var t = function() { pe || (pe = !0, d("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "key", { get: t, configurable: !0 }); } } function Ze(e, r) { { var t = function() { ge || (ge = !0, d("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "ref", { get: t, configurable: !0 }); } } var Qe = function(e, r, t, n, i, u, o) { var a = { // This tag allows us to uniquely identify this as a React Element $$typeof: m, // Built-in properties that belong on the element type: e, key: r, ref: t, props: o, // Record the component responsible for creating this element. _owner: u }; return a._store = {}, Object.defineProperty(a._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(a, "_self", { configurable: !1, enumerable: !1, writable: !1, value: n }), Object.defineProperty(a, "_source", { configurable: !1, enumerable: !1, writable: !1, value: i }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a; }; function er(e, r, t, n, i) { { var u, o = {}, a = null, v = null; t !== void 0 && (ve(t), a = "" + t), Ke(r) && (ve(r.key), a = "" + r.key), ze(r) && (v = r.ref, He(r, i)); for (u in r) M.call(r, u) && !Ge.hasOwnProperty(u) && (o[u] = r[u]); if (e && e.defaultProps) { var s = e.defaultProps; for (u in s) o[u] === void 0 && (o[u] = s[u]); } if (a || v) { var l = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; a && Xe(o, l), v && Ze(o, l); } return Qe(e, a, v, i, n, A.current, o); } } var K = x.ReactCurrentOwner, he = x.ReactDebugCurrentFrame; function j(e) { if (e) { var r = e._owner, t = V(e.type, e._source, r ? r.type : null); he.setExtraStackFrame(t); } else he.setExtraStackFrame(null); } var H; H = !1; function X(e) { return typeof e == "object" && e !== null && e.$$typeof === m; } function be() { { if (K.current) { var e = E(K.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function rr(e) { { if (e !== void 0) { var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber; return ` Check your code at ` + r + ":" + t + "."; } return ""; } } var me = {}; function tr(e) { { var r = be(); if (!r) { var t = typeof e == "string" ? e : e.displayName || e.name; t && (r = ` Check the top-level render call using <` + t + ">."); } return r; } } function _e(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = tr(r); if (me[t]) return; me[t] = !0; var n = ""; e && e._owner && e._owner !== K.current && (n = " It was passed a child from " + E(e._owner.type) + "."), j(e), d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), j(null); } } function ye(e, r) { { if (typeof e != "object") return; if (G(e)) for (var t = 0; t < e.length; t++) { var n = e[t]; X(n) && _e(n, r); } else if (X(e)) e._store && (e._store.validated = !0); else if (e) { var i = xe(e); if (typeof i == "function" && i !== e.entries) for (var u = i.call(e), o; !(o = u.next()).done; ) X(o.value) && _e(o.value, r); } } } function nr(e) { { var r = e.type; if (r == null || typeof r == "string") return; var t; if (typeof r == "function") t = r.propTypes; else if (typeof r == "object" && (r.$$typeof === c || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === y)) t = r.propTypes; else return; if (t) { var n = E(r); Ue(t, e.props, "prop", n, e); } else if (r.PropTypes !== void 0 && !H) { H = !0; var i = E(r); d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function ar(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var n = r[t]; if (n !== "children" && n !== "key") { j(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), j(null); break; } } e.ref !== null && (j(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), j(null)); } } function Ee(e, r, t, n, i, u) { { var o = Ie(e); if (!o) { var a = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var v = rr(i); v ? a += v : a += be(); var s; e === null ? s = "null" : G(e) ? s = "array" : e !== void 0 && e.$$typeof === m ? (s = "<" + (E(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : s = typeof e, d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", s, a); } var l = er(e, r, t, i, u); if (l == null) return l; if (o) { var b = r.children; if (b !== void 0) if (n) if (G(b)) { for (var k = 0; k < b.length; k++) ye(b[k], e); Object.freeze && Object.freeze(b); } else d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else ye(b, e); } return e === h ? ar(l) : nr(l), l; } } function or(e, r, t) { return Ee(e, r, t, !0); } function ir(e, r, t) { return Ee(e, r, t, !1); } var ur = ir, sr = or; I.Fragment = h, I.jsx = ur, I.jsxs = sr; }()), I; } (function(f) { process.env.NODE_ENV === "production" ? f.exports = fr() : f.exports = cr(); })(lr); const we = N.Fragment, O = N.jsx, Ce = N.jsxs; const gr = ({ labels: f, progress: m, labelColor: _, barColor: h, separatorColor: p }) => { const T = { width: `${m}%`, backgroundColor: h }; return /* @__PURE__ */ Ce("div", { className: "progress-bar", children: [ /* @__PURE__ */ O("div", { className: "progress-bar__label-holder", children: /* @__PURE__ */ O(dr, { labels: f, color: _ }) }), /* @__PURE__ */ Ce("div", { className: "progress-bar__progress-bg", children: [ /* @__PURE__ */ O("div", { className: "progress-bar__progress", style: T }), /* @__PURE__ */ O(vr, { labels: f, color: p }) ] }) ] }); }, dr = ({ labels: f, color: m }) => { const _ = 100 / (f.length - 1), h = { color: m }; return /* @__PURE__ */ O(we, { children: f.map((p, T) => /* @__PURE__ */ O( "span", { style: { left: `${_ * T}%`, ...h }, className: "label", children: p }, p )) }); }, vr = ({ labels: f, color: m }) => { const _ = 100 / (f.length - 1); return /* @__PURE__ */ O(we, { children: f.map( (h, p) => p === 0 || p === f.length - 1 ? null : /* @__PURE__ */ O( "div", { style: { left: `${_ * p}%`, backgroundColor: m }, className: "label progress-bar__seperator" }, h ) ) }); }; export { gr as default }; //# sourceMappingURL=react-meter-bar.js.map