index.mjs 6.4 KB

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