react-customizable-progressbar
Version:
Customizable circular SVG progress bar component for React
33 lines (29 loc) • 16.5 kB
JavaScript
const ie=require("react");var Ee={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 We;function pr(){if(We)return G;We=1;var x=ie,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 Le;function gr(){return Le||(Le=1,process.env.NODE_ENV!=="production"&&function(){var x=ie,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 se(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,ue=!1,le=!1,ce=!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||ce||e===L||U||ue||le||typeof e=="object"&&e!==null&&(e.$$typeof===O||e.$$typeof===h||e.$$typeof===A||e.$$typeof===k||e.$$typeof===v||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,q,_,Y,N,c,E,w;function re(){}re.__reactDisabledLog=!0;function Me(){{if(F===0){q=console.log,_=console.info,Y=console.warn,N=console.error,c=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:q}),info:S({},e,{value:_}),warn:S({},e,{value:Y}),error:S({},e,{value:N}),group:S({},e,{value:c}),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 de=j.ReactCurrentDispatcher,ve;function te(e,r,t){{if(ve===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);ve=n&&n[1]||""}return`
`+ve+e}}var pe=!1,ne;{var Ue=typeof WeakMap=="function"?WeakMap:Map;ne=new Ue}function Te(e,r){if(!e||pe)return"";{var t=ne.get(e);if(t!==void 0)return t}var n;pe=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=de.current,de.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(`
`),f=a.length-1,d=g.length-1;f>=1&&d>=0&&a[f]!==g[d];)d--;for(;f>=1&&d>=0;f--,d--)if(a[f]!==g[d]){if(f!==1||d!==1)do if(f--,d--,d<0||a[f]!==g[d]){var b=`
`+a[f].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(f>=1&&d>=0);break}}}finally{pe=!1,de.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 Te(e,!1)}function qe(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function ae(e,r,t){if(e==null)return"";if(typeof e=="function")return Te(e,qe(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 J=Object.prototype.hasOwnProperty,Ce={},Se=j.ReactDebugCurrentFrame;function oe(e){if(e){var r=e._owner,t=ae(e.type,e._source,r?r.type:null);Se.setExtraStackFrame(t)}else Se.setExtraStackFrame(null)}function Je(e,r,t,n,i){{var s=Function.call.bind(J);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(f){a=f}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 Ce)&&(Ce[a.message]=!0,oe(i),l("Failed %s type: %s",t,a.message),oe(null))}}}var Ke=Array.isArray;function ge(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 ke(e),!1}catch{return!0}}function ke(e){return""+e}function Pe(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)),ke(e)}var K=j.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},Oe,we,ye;ye={};function He(e){if(J.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(J.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);ye[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),ye[t]=!0)}}function er(e,r){{var t=function(){Oe||(Oe=!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(){we||(we=!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={$$typeof:D,type:e,key:r,ref:t,props:o,_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&&(Pe(t),a=""+t),Ze(r)&&(Pe(r.key),a=""+r.key),He(r)&&(g=r.ref,Qe(r,i));for(s in r)J.call(r,s)&&!Xe.hasOwnProperty(s)&&(o[s]=r[s]);if(e&&e.defaultProps){var f=e.defaultProps;for(s in f)o[s]===void 0&&(o[s]=f[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 he=j.ReactCurrentOwner,xe=j.ReactDebugCurrentFrame;function M(e){if(e){var r=e._owner,t=ae(e.type,e._source,r?r.type:null);xe.setExtraStackFrame(t)}else xe.setExtraStackFrame(null)}var me;me=!1;function _e(e){return typeof e=="object"&&e!==null&&e.$$typeof===D}function je(){{if(he.current){var e=m(he.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 De={};function or(e){{var r=je();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 Ae(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=or(r);if(De[t])return;De[t]=!0;var n="";e&&e._owner&&e._owner!==he.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 $e(e,r){{if(typeof e!="object")return;if(ge(e))for(var t=0;t<e.length;t++){var n=e[t];_e(n)&&Ae(n,r)}else if(_e(e))e._store&&(e._store.validated=!0);else if(e){var i=se(e);if(typeof i=="function"&&i!==e.entries)for(var s=i.call(e),o;!(o=s.next()).done;)_e(o.value)&&Ae(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||r.$$typeof===h))t=r.propTypes;else return;if(t){var n=m(r);Je(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!me){me=!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 Fe={};function Ie(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+=je();var f;e===null?f="null":ge(e)?f="array":e!==void 0&&e.$$typeof===D?(f="<"+(m(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):f=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",f,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(ge(b)){for(var V=0;V<b.length;V++)$e(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 $e(b,e)}if(J.call(r,"key")){var I=m(e),y=Object.keys(r).filter(function(vr){return vr!=="key"}),be=y.length>0?"{key: someKey, "+y.join(": ..., ")+": ...}":"{key: someKey}";if(!Fe[I+be]){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} />`,be,I,dr,I),Fe[I+be]=!0}}return e===T?sr(d):ir(d),d}}function ur(e,r,t){return Ie(e,r,t,!0)}function lr(e,r,t){return Ie(e,r,t,!1)}var cr=lr,fr=ur;z.Fragment=T,z.jsx=cr,z.jsxs=fr}()),z}process.env.NODE_ENV==="production"?Ee.exports=pr():Ee.exports=gr();var Ne=Ee.exports;const Re=Ne.jsx,Ye=Ne.jsxs,yr=({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:se=u.trackStrokeLinecap,trackTransition:j=u.trackTransition,counterClockwise:l=u.counterClockwise,inverse:H=u.inverse,initialAnimation:U=u.initialAnimation,initialAnimationDelay:ue=u.initialAnimationDelay,className:le=u.className,children:ce=u.children})=>{const[Z,Q]=ie.useState(!1);ie.useEffect(()=>{let c;return U&&(c=setTimeout(()=>Q(!0),ue)),()=>clearTimeout(c)},[]);const B=()=>U&&!Z?0:D,fe=c=>{const E=B(),w=c/R*(R-E);return H?l?0:w-c:l?-1*w:w},ee=(c,E)=>{const w=B(),re=c/R*(R-w);return H?`${re}, ${E}`:l?`${c*(w/100)}, ${E}`:`${c}, ${E}`},m=(c,E)=>U&&!Z?`0, ${E}`:`${c}, ${E}`,S=()=>{const c=p+h;return c>C&&c>$?c*2:C>$?C*2:$*2},F=()=>{const c=B();return l?(360-T)/R*(R-c):(360-T)/R*c},q=2*x,_=q+S(),Y=2*Math.PI*x,N=Y/360*(360-T);return Ye("div",{className:`RCP ${le}`,style:{position:"relative",width:`${_}px`},children:[Ye("svg",{width:_,height:_,viewBox:`0 0 ${_} ${_}`,style:{transform:`rotate(${W}deg)`},children:[$>0&&Re("circle",{cx:_/2,cy:_/2,r:x,fill:"none",stroke:X,strokeWidth:$,strokeDasharray:m(N,Y),strokeLinecap:se,className:"RCP__track",style:{transition:j}}),C>0&&Re("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&&Re("circle",{cx:q,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}})]}),ce||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:""};module.exports=yr;
;