react-customizable-progressbar
Version:
Customizable circular SVG progress bar component for React
794 lines (790 loc) • 26 kB
JavaScript
import Ye, { useState as pr, useEffect as gr } from "react";
var Re = { exports: {} }, G = {};
/**
* @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 Ie;
function yr() {
if (Ie)
return G;
Ie = 1;
var x = Ye, D = Symbol.for("react.element"), R = Symbol.for("react.fragment"), T = Object.prototype.hasOwnProperty, W = x.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, C = { key: !0, ref: !0, __self: !0, __source: !0 };
function A(k, v, P) {
var p, h = {}, O = null, L = null;
P !== void 0 && (O = "" + P), v.key !== void 0 && (O = "" + v.key), v.ref !== void 0 && (L = v.ref);
for (p in v)
T.call(v, p) && !C.hasOwnProperty(p) && (h[p] = v[p]);
if (k && k.defaultProps)
for (p in v = k.defaultProps, v)
h[p] === void 0 && (h[p] = v[p]);
return { $$typeof: D, type: k, key: O, ref: L, props: h, _owner: W.current };
}
return G.Fragment = R, G.jsx = A, G.jsxs = A, G;
}
var z = {};
/**
* @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 We;
function hr() {
return We || (We = 1, process.env.NODE_ENV !== "production" && function() {
var x = Ye, D = Symbol.for("react.element"), R = Symbol.for("react.portal"), T = Symbol.for("react.fragment"), W = Symbol.for("react.strict_mode"), C = Symbol.for("react.profiler"), A = Symbol.for("react.provider"), k = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), P = Symbol.for("react.suspense"), p = Symbol.for("react.suspense_list"), h = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), L = Symbol.for("react.offscreen"), X = Symbol.iterator, $ = "@@iterator";
function ie(e) {
if (e === null || typeof e != "object")
return null;
var r = X && e[X] || e[$];
return typeof r == "function" ? r : null;
}
var j = x.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function l(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
H("error", e, t);
}
}
function H(e, r, t) {
{
var n = j.ReactDebugCurrentFrame, i = n.getStackAddendum();
i !== "" && (r += "%s", t = t.concat([i]));
var s = t.map(function(o) {
return String(o);
});
s.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, s);
}
}
var U = !1, se = !1, ue = !1, le = !1, Z = !1, Q;
Q = Symbol.for("react.module.reference");
function B(e) {
return !!(typeof e == "string" || typeof e == "function" || e === T || e === C || Z || e === W || e === P || e === p || le || e === L || U || se || ue || typeof e == "object" && e !== null && (e.$$typeof === O || e.$$typeof === h || e.$$typeof === A || e.$$typeof === k || e.$$typeof === v || // 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 fe(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 m(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && l("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 T:
return "Fragment";
case R:
return "Portal";
case C:
return "Profiler";
case W:
return "StrictMode";
case P:
return "Suspense";
case p:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case k:
var r = e;
return ee(r) + ".Consumer";
case A:
var t = e;
return ee(t._context) + ".Provider";
case v:
return fe(e, e.render, "ForwardRef");
case h:
var n = e.displayName || null;
return n !== null ? n : m(e.type) || "Memo";
case O: {
var i = e, s = i._payload, o = i._init;
try {
return m(o(s));
} catch {
return null;
}
}
}
return null;
}
var S = Object.assign, F = 0, J, _, Y, N, f, E, w;
function re() {
}
re.__reactDisabledLog = !0;
function Me() {
{
if (F === 0) {
J = console.log, _ = console.info, Y = console.warn, N = console.error, f = console.group, E = console.groupCollapsed, w = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: re,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
F++;
}
}
function Ve() {
{
if (F--, F === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: S({}, e, {
value: J
}),
info: S({}, e, {
value: _
}),
warn: S({}, e, {
value: Y
}),
error: S({}, e, {
value: N
}),
group: S({}, e, {
value: f
}),
groupCollapsed: S({}, e, {
value: E
}),
groupEnd: S({}, e, {
value: w
})
});
}
F < 0 && l("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var ce = j.ReactCurrentDispatcher, de;
function te(e, r, t) {
{
if (de === void 0)
try {
throw Error();
} catch (i) {
var n = i.stack.trim().match(/\n( *(at )?)/);
de = n && n[1] || "";
}
return `
` + de + e;
}
}
var ve = !1, ne;
{
var Ue = typeof WeakMap == "function" ? WeakMap : Map;
ne = new Ue();
}
function Ee(e, r) {
if (!e || ve)
return "";
{
var t = ne.get(e);
if (t !== void 0)
return t;
}
var n;
ve = !0;
var i = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var s;
s = ce.current, ce.current = null, Me();
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 (y) {
n = y;
}
Reflect.construct(e, [], o);
} else {
try {
o.call();
} catch (y) {
n = y;
}
e.call(o.prototype);
}
} else {
try {
throw Error();
} catch (y) {
n = y;
}
e();
}
} catch (y) {
if (y && n && typeof y.stack == "string") {
for (var a = y.stack.split(`
`), g = n.stack.split(`
`), c = a.length - 1, d = g.length - 1; c >= 1 && d >= 0 && a[c] !== g[d]; )
d--;
for (; c >= 1 && d >= 0; c--, d--)
if (a[c] !== g[d]) {
if (c !== 1 || d !== 1)
do
if (c--, d--, d < 0 || a[c] !== g[d]) {
var b = `
` + a[c].replace(" at new ", " at ");
return e.displayName && b.includes("<anonymous>") && (b = b.replace("<anonymous>", e.displayName)), typeof e == "function" && ne.set(e, b), b;
}
while (c >= 1 && d >= 0);
break;
}
}
} finally {
ve = !1, ce.current = s, Ve(), Error.prepareStackTrace = i;
}
var V = e ? e.displayName || e.name : "", I = V ? te(V) : "";
return typeof e == "function" && ne.set(e, I), I;
}
function Be(e, r, t) {
return Ee(e, !1);
}
function Je(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function ae(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return Ee(e, Je(e));
if (typeof e == "string")
return te(e);
switch (e) {
case P:
return te("Suspense");
case p:
return te("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case v:
return Be(e.render);
case h:
return ae(e.type, r, t);
case O: {
var n = e, i = n._payload, s = n._init;
try {
return ae(s(i), r, t);
} catch {
}
}
}
return "";
}
var q = Object.prototype.hasOwnProperty, Te = {}, Ce = j.ReactDebugCurrentFrame;
function oe(e) {
if (e) {
var r = e._owner, t = ae(e.type, e._source, r ? r.type : null);
Ce.setExtraStackFrame(t);
} else
Ce.setExtraStackFrame(null);
}
function qe(e, r, t, n, i) {
{
var s = Function.call.bind(q);
for (var o in e)
if (s(e, o)) {
var a = void 0;
try {
if (typeof e[o] != "function") {
var g = 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 g.name = "Invariant Violation", g;
}
a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (c) {
a = c;
}
a && !(a instanceof Error) && (oe(i), l("%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), oe(null)), a instanceof Error && !(a.message in Te) && (Te[a.message] = !0, oe(i), l("Failed %s type: %s", t, a.message), oe(null));
}
}
}
var Ke = Array.isArray;
function pe(e) {
return Ke(e);
}
function Ge(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function ze(e) {
try {
return Se(e), !1;
} catch {
return !0;
}
}
function Se(e) {
return "" + e;
}
function ke(e) {
if (ze(e))
return l("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ge(e)), Se(e);
}
var K = j.ReactCurrentOwner, Xe = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Pe, Oe, ge;
ge = {};
function He(e) {
if (q.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function Ze(e) {
if (q.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function Qe(e, r) {
if (typeof e.ref == "string" && K.current && r && K.current.stateNode !== r) {
var t = m(K.current.type);
ge[t] || (l('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', m(K.current.type), e.ref), ge[t] = !0);
}
}
function er(e, r) {
{
var t = function() {
Pe || (Pe = !0, l("%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 rr(e, r) {
{
var t = function() {
Oe || (Oe = !0, l("%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 tr = function(e, r, t, n, i, s, o) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: D,
// 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: s
};
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 nr(e, r, t, n, i) {
{
var s, o = {}, a = null, g = null;
t !== void 0 && (ke(t), a = "" + t), Ze(r) && (ke(r.key), a = "" + r.key), He(r) && (g = r.ref, Qe(r, i));
for (s in r)
q.call(r, s) && !Xe.hasOwnProperty(s) && (o[s] = r[s]);
if (e && e.defaultProps) {
var c = e.defaultProps;
for (s in c)
o[s] === void 0 && (o[s] = c[s]);
}
if (a || g) {
var d = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && er(o, d), g && rr(o, d);
}
return tr(e, a, g, i, n, K.current, o);
}
}
var ye = j.ReactCurrentOwner, we = j.ReactDebugCurrentFrame;
function M(e) {
if (e) {
var r = e._owner, t = ae(e.type, e._source, r ? r.type : null);
we.setExtraStackFrame(t);
} else
we.setExtraStackFrame(null);
}
var he;
he = !1;
function me(e) {
return typeof e == "object" && e !== null && e.$$typeof === D;
}
function xe() {
{
if (ye.current) {
var e = m(ye.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function ar(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var je = {};
function or(e) {
{
var r = xe();
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 De(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = or(r);
if (je[t])
return;
je[t] = !0;
var n = "";
e && e._owner && e._owner !== ye.current && (n = " It was passed a child from " + m(e._owner.type) + "."), M(e), l('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), M(null);
}
}
function Ae(e, r) {
{
if (typeof e != "object")
return;
if (pe(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
me(n) && De(n, r);
}
else if (me(e))
e._store && (e._store.validated = !0);
else if (e) {
var i = ie(e);
if (typeof i == "function" && i !== e.entries)
for (var s = i.call(e), o; !(o = s.next()).done; )
me(o.value) && De(o.value, r);
}
}
}
function ir(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 === v || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === h))
t = r.propTypes;
else
return;
if (t) {
var n = m(r);
qe(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !he) {
he = !0;
var i = m(r);
l("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && l("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function sr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
M(e), l("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), M(null);
break;
}
}
e.ref !== null && (M(e), l("Invalid attribute `ref` supplied to `React.Fragment`."), M(null));
}
}
var $e = {};
function Fe(e, r, t, n, i, s) {
{
var o = B(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 g = ar(i);
g ? a += g : a += xe();
var c;
e === null ? c = "null" : pe(e) ? c = "array" : e !== void 0 && e.$$typeof === D ? (c = "<" + (m(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : c = typeof e, l("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", c, a);
}
var d = nr(e, r, t, i, s);
if (d == null)
return d;
if (o) {
var b = r.children;
if (b !== void 0)
if (n)
if (pe(b)) {
for (var V = 0; V < b.length; V++)
Ae(b[V], e);
Object.freeze && Object.freeze(b);
} else
l("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
Ae(b, e);
}
if (q.call(r, "key")) {
var I = m(e), y = Object.keys(r).filter(function(vr) {
return vr !== "key";
}), _e = y.length > 0 ? "{key: someKey, " + y.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!$e[I + _e]) {
var dr = y.length > 0 ? "{" + y.join(": ..., ") + ": ...}" : "{}";
l(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, _e, I, dr, I), $e[I + _e] = !0;
}
}
return e === T ? sr(d) : ir(d), d;
}
}
function ur(e, r, t) {
return Fe(e, r, t, !0);
}
function lr(e, r, t) {
return Fe(e, r, t, !1);
}
var fr = lr, cr = ur;
z.Fragment = T, z.jsx = fr, z.jsxs = cr;
}()), z;
}
process.env.NODE_ENV === "production" ? Re.exports = yr() : Re.exports = hr();
var Ne = Re.exports;
const be = Ne.jsx, Le = Ne.jsxs, _r = ({
radius: x = u.radius,
progress: D = u.progress,
steps: R = u.steps,
cut: T = u.cut,
rotate: W = u.rotate,
strokeWidth: C = u.strokeWidth,
strokeColor: A = u.strokeColor,
fillColor: k = u.fillColor,
strokeLinecap: v = u.strokeLinecap,
transition: P = u.transition,
pointerRadius: p = u.pointerRadius,
pointerStrokeWidth: h = u.pointerStrokeWidth,
pointerStrokeColor: O = u.pointerStrokeColor,
pointerFillColor: L = u.pointerFillColor,
trackStrokeColor: X = u.trackStrokeColor,
trackStrokeWidth: $ = u.trackStrokeWidth,
trackStrokeLinecap: ie = u.trackStrokeLinecap,
trackTransition: j = u.trackTransition,
counterClockwise: l = u.counterClockwise,
inverse: H = u.inverse,
initialAnimation: U = u.initialAnimation,
initialAnimationDelay: se = u.initialAnimationDelay,
className: ue = u.className,
children: le = u.children
}) => {
const [Z, Q] = pr(!1);
gr(() => {
let f;
return U && (f = setTimeout(
() => Q(!0),
se
)), () => clearTimeout(f);
}, []);
const B = () => U && !Z ? 0 : D, fe = (f) => {
const E = B(), w = f / R * (R - E);
return H ? l ? 0 : w - f : l ? -1 * w : w;
}, ee = (f, E) => {
const w = B(), re = f / R * (R - w);
return H ? `${re}, ${E}` : l ? `${f * (w / 100)}, ${E}` : `${f}, ${E}`;
}, m = (f, E) => U && !Z ? `0, ${E}` : `${f}, ${E}`, S = () => {
const f = p + h;
return f > C && f > $ ? f * 2 : C > $ ? C * 2 : $ * 2;
}, F = () => {
const f = B();
return l ? (360 - T) / R * (R - f) : (360 - T) / R * f;
}, J = 2 * x, _ = J + S(), Y = 2 * Math.PI * x, N = Y / 360 * (360 - T);
return /* @__PURE__ */ Le(
"div",
{
className: `RCP ${ue}`,
style: {
position: "relative",
width: `${_}px`
},
children: [
/* @__PURE__ */ Le(
"svg",
{
width: _,
height: _,
viewBox: `0 0 ${_} ${_}`,
style: { transform: `rotate(${W}deg)` },
children: [
$ > 0 && /* @__PURE__ */ be(
"circle",
{
cx: _ / 2,
cy: _ / 2,
r: x,
fill: "none",
stroke: X,
strokeWidth: $,
strokeDasharray: m(
N,
Y
),
strokeLinecap: ie,
className: "RCP__track",
style: { transition: j }
}
),
C > 0 && /* @__PURE__ */ be(
"circle",
{
cx: _ / 2,
cy: _ / 2,
r: x,
fill: k,
stroke: A,
strokeWidth: C,
strokeDasharray: ee(N, Y),
strokeDashoffset: fe(N),
strokeLinecap: v,
className: "RCP__progress",
style: { transition: P }
}
),
p > 0 && /* @__PURE__ */ be(
"circle",
{
cx: J,
cy: "50%",
r: p,
fill: L,
stroke: O,
strokeWidth: h,
className: "RCP__pointer",
style: {
transformOrigin: "50% 50%",
transform: `rotate(${F()}deg) translate(${S() / 2}px)`,
transition: P
}
}
)
]
}
),
le || null
]
}
);
}, u = {
radius: 100,
progress: 0,
steps: 100,
cut: 0,
rotate: -90,
strokeWidth: 20,
strokeColor: "indianred",
fillColor: "none",
strokeLinecap: "round",
transition: ".3s ease",
pointerRadius: 0,
pointerStrokeWidth: 20,
pointerStrokeColor: "indianred",
pointerFillColor: "white",
trackStrokeColor: "#e6e6e6",
trackStrokeWidth: 20,
trackStrokeLinecap: "round",
trackTransition: ".3s ease",
counterClockwise: !1,
inverse: !1,
initialAnimation: !1,
initialAnimationDelay: 0,
className: ""
};
export {
_r as default
};