react-multi-segment-progress
Version:
A React progress bar component that supports multiple segments with overlapping effect
31 lines (28 loc) • 15 kB
JavaScript
(function(O,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],C):(O=typeof globalThis<"u"?globalThis:O||self,C(O.MultiSegmentProgress={},O.React))})(this,function(O,C){"use strict";var V={exports:{}},$={};/**
* @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 je(){if(te)return $;te=1;var m=C,P=Symbol.for("react.element"),W=Symbol.for("react.fragment"),T=Object.prototype.hasOwnProperty,b=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,j={key:!0,ref:!0,__self:!0,__source:!0};function g(h,f,S){var v,E={},_=null,k=null;S!==void 0&&(_=""+S),f.key!==void 0&&(_=""+f.key),f.ref!==void 0&&(k=f.ref);for(v in f)T.call(f,v)&&!j.hasOwnProperty(v)&&(E[v]=f[v]);if(h&&h.defaultProps)for(v in f=h.defaultProps,f)E[v]===void 0&&(E[v]=f[v]);return{$$typeof:P,type:h,key:_,ref:k,props:E,_owner:b.current}}return $.Fragment=W,$.jsx=g,$.jsxs=g,$}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 ne;function ke(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var m=C,P=Symbol.for("react.element"),W=Symbol.for("react.portal"),T=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),g=Symbol.for("react.provider"),h=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),E=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),k=Symbol.for("react.offscreen"),U=Symbol.iterator,Ae="@@iterator";function $e(e){if(e===null||typeof e!="object")return null;var r=U&&e[U]||e[Ae];return typeof r=="function"?r:null}var F=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function c(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Ie("error",e,t)}}function Ie(e,r,t){{var n=F.ReactDebugCurrentFrame,o=n.getStackAddendum();o!==""&&(r+="%s",t=t.concat([o]));var u=t.map(function(i){return String(i)});u.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,u)}}var We=!1,Ye=!1,Me=!1,Le=!1,Ve=!1,oe;oe=Symbol.for("react.module.reference");function Ue(e){return!!(typeof e=="string"||typeof e=="function"||e===T||e===j||Ve||e===b||e===S||e===v||Le||e===k||We||Ye||Me||typeof e=="object"&&e!==null&&(e.$$typeof===_||e.$$typeof===E||e.$$typeof===g||e.$$typeof===h||e.$$typeof===f||e.$$typeof===oe||e.getModuleId!==void 0))}function Ne(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return o!==""?t+"("+o+")":t}function ue(e){return e.displayName||"Context"}function R(e){if(e==null)return null;if(typeof e.tag=="number"&&c("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 W:return"Portal";case j:return"Profiler";case b:return"StrictMode";case S:return"Suspense";case v:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case h:var r=e;return ue(r)+".Consumer";case g:var t=e;return ue(t._context)+".Provider";case f:return Ne(e,e.render,"ForwardRef");case E:var n=e.displayName||null;return n!==null?n:R(e.type)||"Memo";case _:{var o=e,u=o._payload,i=o._init;try{return R(i(u))}catch{return null}}}return null}var w=Object.assign,Y=0,se,le,fe,ce,de,ve,pe;function ge(){}ge.__reactDisabledLog=!0;function Je(){{if(Y===0){se=console.log,le=console.info,fe=console.warn,ce=console.error,de=console.group,ve=console.groupCollapsed,pe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ge,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Y++}}function Be(){{if(Y--,Y===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:w({},e,{value:se}),info:w({},e,{value:le}),warn:w({},e,{value:fe}),error:w({},e,{value:ce}),group:w({},e,{value:de}),groupCollapsed:w({},e,{value:ve}),groupEnd:w({},e,{value:pe})})}Y<0&&c("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var K=F.ReactCurrentDispatcher,z;function N(e,r,t){{if(z===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);z=n&&n[1]||""}return`
`+z+e}}var G=!1,J;{var qe=typeof WeakMap=="function"?WeakMap:Map;J=new qe}function he(e,r){if(!e||G)return"";{var t=J.get(e);if(t!==void 0)return t}var n;G=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=K.current,K.current=null,Je();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(p){n=p}Reflect.construct(e,[],i)}else{try{i.call()}catch(p){n=p}e.call(i.prototype)}}else{try{throw Error()}catch(p){n=p}e()}}catch(p){if(p&&n&&typeof p.stack=="string"){for(var a=p.stack.split(`
`),d=n.stack.split(`
`),s=a.length-1,l=d.length-1;s>=1&&l>=0&&a[s]!==d[l];)l--;for(;s>=1&&l>=0;s--,l--)if(a[s]!==d[l]){if(s!==1||l!==1)do if(s--,l--,l<0||a[s]!==d[l]){var y=`
`+a[s].replace(" at new "," at ");return e.displayName&&y.includes("<anonymous>")&&(y=y.replace("<anonymous>",e.displayName)),typeof e=="function"&&J.set(e,y),y}while(s>=1&&l>=0);break}}}finally{G=!1,K.current=u,Be(),Error.prepareStackTrace=o}var A=e?e.displayName||e.name:"",x=A?N(A):"";return typeof e=="function"&&J.set(e,x),x}function Ke(e,r,t){return he(e,!1)}function ze(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function B(e,r,t){if(e==null)return"";if(typeof e=="function")return he(e,ze(e));if(typeof e=="string")return N(e);switch(e){case S:return N("Suspense");case v:return N("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Ke(e.render);case E:return B(e.type,r,t);case _:{var n=e,o=n._payload,u=n._init;try{return B(u(o),r,t)}catch{}}}return""}var M=Object.prototype.hasOwnProperty,ye={},be=F.ReactDebugCurrentFrame;function q(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);be.setExtraStackFrame(t)}else be.setExtraStackFrame(null)}function Ge(e,r,t,n,o){{var u=Function.call.bind(M);for(var i in e)if(u(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var d=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw d.name="Invariant Violation",d}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(s){a=s}a&&!(a instanceof Error)&&(q(o),c("%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,i,typeof a),q(null)),a instanceof Error&&!(a.message in ye)&&(ye[a.message]=!0,q(o),c("Failed %s type: %s",t,a.message),q(null))}}}var Xe=Array.isArray;function X(e){return Xe(e)}function He(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Ze(e){try{return Ee(e),!1}catch{return!0}}function Ee(e){return""+e}function Re(e){if(Ze(e))return c("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",He(e)),Ee(e)}var L=F.ReactCurrentOwner,Qe={key:!0,ref:!0,__self:!0,__source:!0},_e,me,H;H={};function er(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 rr(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 tr(e,r){if(typeof e.ref=="string"&&L.current&&r&&L.current.stateNode!==r){var t=R(L.current.type);H[t]||(c('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',R(L.current.type),e.ref),H[t]=!0)}}function nr(e,r){{var t=function(){_e||(_e=!0,c("%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 ar(e,r){{var t=function(){me||(me=!0,c("%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 ir=function(e,r,t,n,o,u,i){var a={$$typeof:P,type:e,key:r,ref:t,props:i,_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:o}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function or(e,r,t,n,o){{var u,i={},a=null,d=null;t!==void 0&&(Re(t),a=""+t),rr(r)&&(Re(r.key),a=""+r.key),er(r)&&(d=r.ref,tr(r,o));for(u in r)M.call(r,u)&&!Qe.hasOwnProperty(u)&&(i[u]=r[u]);if(e&&e.defaultProps){var s=e.defaultProps;for(u in s)i[u]===void 0&&(i[u]=s[u])}if(a||d){var l=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&nr(i,l),d&&ar(i,l)}return ir(e,a,d,o,n,L.current,i)}}var Z=F.ReactCurrentOwner,Te=F.ReactDebugCurrentFrame;function D(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);Te.setExtraStackFrame(t)}else Te.setExtraStackFrame(null)}var Q;Q=!1;function ee(e){return typeof e=="object"&&e!==null&&e.$$typeof===P}function Se(){{if(Z.current){var e=R(Z.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function ur(e){return""}var Oe={};function sr(e){{var r=Se();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 Pe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=sr(r);if(Oe[t])return;Oe[t]=!0;var n="";e&&e._owner&&e._owner!==Z.current&&(n=" It was passed a child from "+R(e._owner.type)+"."),D(e),c('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),D(null)}}function we(e,r){{if(typeof e!="object")return;if(X(e))for(var t=0;t<e.length;t++){var n=e[t];ee(n)&&Pe(n,r)}else if(ee(e))e._store&&(e._store.validated=!0);else if(e){var o=$e(e);if(typeof o=="function"&&o!==e.entries)for(var u=o.call(e),i;!(i=u.next()).done;)ee(i.value)&&Pe(i.value,r)}}}function lr(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===f||r.$$typeof===E))t=r.propTypes;else return;if(t){var n=R(r);Ge(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!Q){Q=!0;var o=R(r);c("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",o||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&c("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function fr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){D(e),c("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),D(null);break}}e.ref!==null&&(D(e),c("Invalid attribute `ref` supplied to `React.Fragment`."),D(null))}}var xe={};function Ce(e,r,t,n,o,u){{var i=Ue(e);if(!i){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 d=ur();d?a+=d:a+=Se();var s;e===null?s="null":X(e)?s="array":e!==void 0&&e.$$typeof===P?(s="<"+(R(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):s=typeof e,c("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=or(e,r,t,o,u);if(l==null)return l;if(i){var y=r.children;if(y!==void 0)if(n)if(X(y)){for(var A=0;A<y.length;A++)we(y[A],e);Object.freeze&&Object.freeze(y)}else c("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 we(y,e)}if(M.call(r,"key")){var x=R(e),p=Object.keys(r).filter(function(hr){return hr!=="key"}),re=p.length>0?"{key: someKey, "+p.join(": ..., ")+": ...}":"{key: someKey}";if(!xe[x+re]){var gr=p.length>0?"{"+p.join(": ..., ")+": ...}":"{}";c(`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} />`,re,x,gr,x),xe[x+re]=!0}}return e===T?fr(l):lr(l),l}}function cr(e,r,t){return Ce(e,r,t,!0)}function dr(e,r,t){return Ce(e,r,t,!1)}var vr=dr,pr=cr;I.Fragment=T,I.jsx=vr,I.jsxs=pr}()),I}var ae;function Fe(){return ae||(ae=1,process.env.NODE_ENV==="production"?V.exports=je():V.exports=ke()),V.exports}var ie=Fe();const De=({segments:m,height:P=12,backgroundColor:W="#E4E5E6",showTooltips:T=!0,borderRadius:b=0})=>{const j={position:"relative",display:"flex",width:"100%",overflow:"hidden",height:`${P}px`,borderRadius:`${b||0}px`,backgroundColor:W};return ie.jsx("div",{style:j,children:m.map((g,h)=>{const f=m.slice(0,h).reduce((k,U)=>k+U.percentage,0),S=h===m.length-1||g.percentage===0?0:b,E=h===0?`${b}px`:`0 ${b}px ${b}px 0`,_={position:"absolute",cursor:"pointer",height:"100%",transition:"all 0.3s ease",left:`${f}%`,width:`calc(${g.percentage}% + ${S}px)`,backgroundColor:g.color,zIndex:m.length-h,borderRadius:E};return ie.jsx("div",{style:_,title:T&&g.label?g.label:void 0},g.id)})})};O.MultiSegmentProgress=De,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});