index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. var $1DGzP$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
  2. var $1DGzP$react = require("react");
  3. var $1DGzP$radixuireactcontext = require("@radix-ui/react-context");
  4. var $1DGzP$radixuireactprimitive = require("@radix-ui/react-primitive");
  5. function $parcel$export(e, n, v, s) {
  6. Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
  7. }
  8. function $parcel$interopDefault(a) {
  9. return a && a.__esModule ? a.default : a;
  10. }
  11. $parcel$export(module.exports, "createProgressScope", () => $66e9ff9cece0fdb5$export$388eb2d8f6d3261f);
  12. $parcel$export(module.exports, "Progress", () => $66e9ff9cece0fdb5$export$b25a304ec7d746bb);
  13. $parcel$export(module.exports, "ProgressIndicator", () => $66e9ff9cece0fdb5$export$2b776f7e7ee60dbd);
  14. $parcel$export(module.exports, "Root", () => $66e9ff9cece0fdb5$export$be92b6f5f03c0fe9);
  15. $parcel$export(module.exports, "Indicator", () => $66e9ff9cece0fdb5$export$adb584737d712b70);
  16. /* -------------------------------------------------------------------------------------------------
  17. * Progress
  18. * -----------------------------------------------------------------------------------------------*/ const $66e9ff9cece0fdb5$var$PROGRESS_NAME = 'Progress';
  19. const $66e9ff9cece0fdb5$var$DEFAULT_MAX = 100;
  20. const [$66e9ff9cece0fdb5$var$createProgressContext, $66e9ff9cece0fdb5$export$388eb2d8f6d3261f] = $1DGzP$radixuireactcontext.createContextScope($66e9ff9cece0fdb5$var$PROGRESS_NAME);
  21. const [$66e9ff9cece0fdb5$var$ProgressProvider, $66e9ff9cece0fdb5$var$useProgressContext] = $66e9ff9cece0fdb5$var$createProgressContext($66e9ff9cece0fdb5$var$PROGRESS_NAME);
  22. const $66e9ff9cece0fdb5$export$b25a304ec7d746bb = /*#__PURE__*/ $1DGzP$react.forwardRef((props, forwardedRef)=>{
  23. const { __scopeProgress: __scopeProgress , value: valueProp , max: maxProp , getValueLabel: getValueLabel = $66e9ff9cece0fdb5$var$defaultGetValueLabel , ...progressProps } = props;
  24. const max = $66e9ff9cece0fdb5$var$isValidMaxNumber(maxProp) ? maxProp : $66e9ff9cece0fdb5$var$DEFAULT_MAX;
  25. const value = $66e9ff9cece0fdb5$var$isValidValueNumber(valueProp, max) ? valueProp : null;
  26. const valueLabel = $66e9ff9cece0fdb5$var$isNumber(value) ? getValueLabel(value, max) : undefined;
  27. return /*#__PURE__*/ $1DGzP$react.createElement($66e9ff9cece0fdb5$var$ProgressProvider, {
  28. scope: __scopeProgress,
  29. value: value,
  30. max: max
  31. }, /*#__PURE__*/ $1DGzP$react.createElement($1DGzP$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($1DGzP$babelruntimehelpersextends))({
  32. "aria-valuemax": max,
  33. "aria-valuemin": 0,
  34. "aria-valuenow": $66e9ff9cece0fdb5$var$isNumber(value) ? value : undefined,
  35. "aria-valuetext": valueLabel,
  36. role: "progressbar",
  37. "data-state": $66e9ff9cece0fdb5$var$getProgressState(value, max),
  38. "data-value": value !== null && value !== void 0 ? value : undefined,
  39. "data-max": max
  40. }, progressProps, {
  41. ref: forwardedRef
  42. })));
  43. });
  44. /*#__PURE__*/ Object.assign($66e9ff9cece0fdb5$export$b25a304ec7d746bb, {
  45. displayName: $66e9ff9cece0fdb5$var$PROGRESS_NAME
  46. });
  47. $66e9ff9cece0fdb5$export$b25a304ec7d746bb.propTypes = {
  48. max (props, propName, componentName) {
  49. const propValue = props[propName];
  50. const strVal = String(propValue);
  51. if (propValue && !$66e9ff9cece0fdb5$var$isValidMaxNumber(propValue)) return new Error($66e9ff9cece0fdb5$var$getInvalidMaxError(strVal, componentName));
  52. return null;
  53. },
  54. value (props, propName, componentName) {
  55. const valueProp = props[propName];
  56. const strVal = String(valueProp);
  57. const max = $66e9ff9cece0fdb5$var$isValidMaxNumber(props.max) ? props.max : $66e9ff9cece0fdb5$var$DEFAULT_MAX;
  58. if (valueProp != null && !$66e9ff9cece0fdb5$var$isValidValueNumber(valueProp, max)) return new Error($66e9ff9cece0fdb5$var$getInvalidValueError(strVal, componentName));
  59. return null;
  60. }
  61. };
  62. /* -------------------------------------------------------------------------------------------------
  63. * ProgressIndicator
  64. * -----------------------------------------------------------------------------------------------*/ const $66e9ff9cece0fdb5$var$INDICATOR_NAME = 'ProgressIndicator';
  65. const $66e9ff9cece0fdb5$export$2b776f7e7ee60dbd = /*#__PURE__*/ $1DGzP$react.forwardRef((props, forwardedRef)=>{
  66. var _context$value;
  67. const { __scopeProgress: __scopeProgress , ...indicatorProps } = props;
  68. const context = $66e9ff9cece0fdb5$var$useProgressContext($66e9ff9cece0fdb5$var$INDICATOR_NAME, __scopeProgress);
  69. return /*#__PURE__*/ $1DGzP$react.createElement($1DGzP$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($1DGzP$babelruntimehelpersextends))({
  70. "data-state": $66e9ff9cece0fdb5$var$getProgressState(context.value, context.max),
  71. "data-value": (_context$value = context.value) !== null && _context$value !== void 0 ? _context$value : undefined,
  72. "data-max": context.max
  73. }, indicatorProps, {
  74. ref: forwardedRef
  75. }));
  76. });
  77. /*#__PURE__*/ Object.assign($66e9ff9cece0fdb5$export$2b776f7e7ee60dbd, {
  78. displayName: $66e9ff9cece0fdb5$var$INDICATOR_NAME
  79. });
  80. /* ---------------------------------------------------------------------------------------------- */ function $66e9ff9cece0fdb5$var$defaultGetValueLabel(value, max) {
  81. return `${Math.round(value / max * 100)}%`;
  82. }
  83. function $66e9ff9cece0fdb5$var$getProgressState(value, maxValue) {
  84. return value == null ? 'indeterminate' : value === maxValue ? 'complete' : 'loading';
  85. }
  86. function $66e9ff9cece0fdb5$var$isNumber(value) {
  87. return typeof value === 'number';
  88. }
  89. function $66e9ff9cece0fdb5$var$isValidMaxNumber(max) {
  90. // prettier-ignore
  91. return $66e9ff9cece0fdb5$var$isNumber(max) && !isNaN(max) && max > 0;
  92. }
  93. function $66e9ff9cece0fdb5$var$isValidValueNumber(value, max) {
  94. // prettier-ignore
  95. return $66e9ff9cece0fdb5$var$isNumber(value) && !isNaN(value) && value <= max && value >= 0;
  96. } // Split this out for clearer readability of the error message.
  97. function $66e9ff9cece0fdb5$var$getInvalidMaxError(propValue, componentName) {
  98. return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${$66e9ff9cece0fdb5$var$DEFAULT_MAX}\`.`;
  99. }
  100. function $66e9ff9cece0fdb5$var$getInvalidValueError(propValue, componentName) {
  101. return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
  102. - a positive number
  103. - less than the value passed to \`max\` (or ${$66e9ff9cece0fdb5$var$DEFAULT_MAX} if no \`max\` prop is set)
  104. - \`null\` if the progress is indeterminate.
  105. Defaulting to \`null\`.`;
  106. }
  107. const $66e9ff9cece0fdb5$export$be92b6f5f03c0fe9 = $66e9ff9cece0fdb5$export$b25a304ec7d746bb;
  108. const $66e9ff9cece0fdb5$export$adb584737d712b70 = $66e9ff9cece0fdb5$export$2b776f7e7ee60dbd;
  109. //# sourceMappingURL=index.js.map