@radix-ui/react-progress 0.1.5-rc.2 → 0.1.5-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"mappings":"A;A;A;AAeA,OAAA,0FAAsF,CAAC;AAQvF,yBAAyB,MAAM,wBAAwB,CAAC,OAAO,UAAU,GAAG,CAAC,CAAC;AAC9E,8BAAwB,SAAQ,iBAAiB;IAC/C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACpD;AAED,OAAA,MAAM,8FA+BL,CAAC;AA+BF,uCAAiC,SAAQ,iBAAiB;CAAG;AAE7D,OAAA,MAAM,gHAcL,CAAC;AAmDF,OAAA,MAAM,0FAAe,CAAC;AACtB,OAAA,MAAM,wGAA6B,CAAC","sources":["./packages/react/progress/src/packages/react/progress/src/Progress.tsx","./packages/react/progress/src/packages/react/progress/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";;;AAeA,OAAA,0FAAsF,CAAC;AAQvF,yBAAyB,MAAM,wBAAwB,CAAC,OAAO,UAAU,GAAG,CAAC,CAAC;AAC9E,8BAAwB,SAAQ,iBAAiB;IAC/C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACpD;AAED,OAAA,MAAM,8FA+BL,CAAC;AA+BF,uCAAiC,SAAQ,iBAAiB;CAAG;AAE7D,OAAA,MAAM,gHAcL,CAAC;AAmDF,OAAA,MAAM,0FAAe,CAAC;AACtB,OAAA,MAAM,wGAA6B,CAAC","sources":["packages/react/progress/src/packages/react/progress/src/Progress.tsx","packages/react/progress/src/packages/react/progress/src/index.ts","packages/react/progress/src/index.ts"],"sourcesContent":[null,null,"export * from './Progress';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,2 +1,138 @@
1
- var e,r,t,a=require("@radix-ui/react-primitive").Primitive,n=require("@radix-ui/react-context").createContextScope,o=(e={},r=require("react"),Object.keys(r).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})})),e),u=(t=require("@babel/runtime/helpers/extends"))&&t.__esModule?t.default:t;const[i,s]=n("Progress");exports.createProgressScope=s;const[l,c]=i("Progress"),d=/*#__PURE__*/o.forwardRef(((e,r)=>{const{__scopeProgress:t,value:n,max:i,getValueLabel:s=v,...c}=e,d=x(i)?i:100,p=g(n,d)?n:null,b=f(p)?s(p,d):void 0;/*#__PURE__*/return o.createElement(l,{scope:t,value:p,max:d},/*#__PURE__*/o.createElement(a.div,u({"aria-valuemax":d,"aria-valuemin":0,"aria-valuenow":f(p)?p:void 0,"aria-valuetext":b,role:"progressbar","data-state":m(p,d),"data-value":null!=p?p:void 0,"data-max":d},c,{ref:r})))}));exports.Progress=d,d.propTypes={max(e,r,t){const a=e[r],n=String(a);return a&&!x(a)?new Error(function(e,r){return`Invalid prop \`max\` of value \`${e}\` supplied to \`${r}\`. Only numbers greater than 0 are valid max values. Defaulting to \`100\`.`}(n,t)):null},value(e,r,t){const a=e[r],n=String(a),o=x(e.max)?e.max:100;return null==a||g(a,o)?null:new Error(function(e,r){return`Invalid prop \`value\` of value \`${e}\` supplied to \`${r}\`. The \`value\` prop must be:\n - a positive number\n - less than the value passed to \`max\` (or 100 if no \`max\` prop is set)\n - \`null\` if the progress is indeterminate.\n\nDefaulting to \`null\`.`}(n,t))}};const p=/*#__PURE__*/o.forwardRef(((e,r)=>{var t;const{__scopeProgress:n,...i}=e,s=c("ProgressIndicator",n);/*#__PURE__*/return o.createElement(a.div,u({"data-state":m(s.value,s.max),"data-value":null!==(t=s.value)&&void 0!==t?t:void 0,"data-max":s.max},i,{ref:r}))}));function v(e,r){return`${Math.round(e/r*100)}%`}function m(e,r){return null==e?"indeterminate":e===r?"complete":"loading"}function f(e){return"number"==typeof e}function x(e){return f(e)&&!isNaN(e)&&e>0}function g(e,r){return f(e)&&!isNaN(e)&&e<=r&&e>=0}exports.ProgressIndicator=p;const b=d;exports.Root=b;const P=p;exports.Indicator=P;
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
+
6
+ function $parcel$exportWildcard(dest, source) {
7
+ Object.keys(source).forEach(function(key) {
8
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
9
+ return;
10
+ }
11
+
12
+ Object.defineProperty(dest, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return source[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ return dest;
21
+ }
22
+ function $parcel$interopDefault(a) {
23
+ return a && a.__esModule ? a.default : a;
24
+ }
25
+ function $parcel$export(e, n, v, s) {
26
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
27
+ }
28
+ var $66e9ff9cece0fdb5$exports = {};
29
+
30
+ $parcel$export($66e9ff9cece0fdb5$exports, "createProgressScope", () => $66e9ff9cece0fdb5$export$388eb2d8f6d3261f);
31
+ $parcel$export($66e9ff9cece0fdb5$exports, "Progress", () => $66e9ff9cece0fdb5$export$b25a304ec7d746bb);
32
+ $parcel$export($66e9ff9cece0fdb5$exports, "ProgressIndicator", () => $66e9ff9cece0fdb5$export$2b776f7e7ee60dbd);
33
+ $parcel$export($66e9ff9cece0fdb5$exports, "Root", () => $66e9ff9cece0fdb5$export$be92b6f5f03c0fe9);
34
+ $parcel$export($66e9ff9cece0fdb5$exports, "Indicator", () => $66e9ff9cece0fdb5$export$adb584737d712b70);
35
+
36
+
37
+
38
+
39
+ /* -------------------------------------------------------------------------------------------------
40
+ * Progress
41
+ * -----------------------------------------------------------------------------------------------*/ const $66e9ff9cece0fdb5$var$PROGRESS_NAME = 'Progress';
42
+ const $66e9ff9cece0fdb5$var$DEFAULT_MAX = 100;
43
+ const [$66e9ff9cece0fdb5$var$createProgressContext, $66e9ff9cece0fdb5$export$388eb2d8f6d3261f] = $1DGzP$radixuireactcontext.createContextScope($66e9ff9cece0fdb5$var$PROGRESS_NAME);
44
+ const [$66e9ff9cece0fdb5$var$ProgressProvider, $66e9ff9cece0fdb5$var$useProgressContext] = $66e9ff9cece0fdb5$var$createProgressContext($66e9ff9cece0fdb5$var$PROGRESS_NAME);
45
+ const $66e9ff9cece0fdb5$export$b25a304ec7d746bb = /*#__PURE__*/ $1DGzP$react.forwardRef((props, forwardedRef)=>{
46
+ const { __scopeProgress: __scopeProgress , value: valueProp , max: maxProp , getValueLabel: getValueLabel = $66e9ff9cece0fdb5$var$defaultGetValueLabel , ...progressProps } = props;
47
+ const max = $66e9ff9cece0fdb5$var$isValidMaxNumber(maxProp) ? maxProp : $66e9ff9cece0fdb5$var$DEFAULT_MAX;
48
+ const value = $66e9ff9cece0fdb5$var$isValidValueNumber(valueProp, max) ? valueProp : null;
49
+ const valueLabel = $66e9ff9cece0fdb5$var$isNumber(value) ? getValueLabel(value, max) : undefined;
50
+ return /*#__PURE__*/ $1DGzP$react.createElement($66e9ff9cece0fdb5$var$ProgressProvider, {
51
+ scope: __scopeProgress,
52
+ value: value,
53
+ max: max
54
+ }, /*#__PURE__*/ $1DGzP$react.createElement($1DGzP$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($1DGzP$babelruntimehelpersextends))({
55
+ "aria-valuemax": max,
56
+ "aria-valuemin": 0,
57
+ "aria-valuenow": $66e9ff9cece0fdb5$var$isNumber(value) ? value : undefined,
58
+ "aria-valuetext": valueLabel,
59
+ role: "progressbar",
60
+ "data-state": $66e9ff9cece0fdb5$var$getProgressState(value, max),
61
+ "data-value": value !== null && value !== void 0 ? value : undefined,
62
+ "data-max": max
63
+ }, progressProps, {
64
+ ref: forwardedRef
65
+ })));
66
+ });
67
+ /*#__PURE__*/ Object.assign($66e9ff9cece0fdb5$export$b25a304ec7d746bb, {
68
+ displayName: $66e9ff9cece0fdb5$var$PROGRESS_NAME
69
+ });
70
+ $66e9ff9cece0fdb5$export$b25a304ec7d746bb.propTypes = {
71
+ max (props, propName, componentName) {
72
+ const propValue = props[propName];
73
+ const strVal = String(propValue);
74
+ if (propValue && !$66e9ff9cece0fdb5$var$isValidMaxNumber(propValue)) return new Error($66e9ff9cece0fdb5$var$getInvalidMaxError(strVal, componentName));
75
+ return null;
76
+ },
77
+ value (props, propName, componentName) {
78
+ const valueProp = props[propName];
79
+ const strVal = String(valueProp);
80
+ const max = $66e9ff9cece0fdb5$var$isValidMaxNumber(props.max) ? props.max : $66e9ff9cece0fdb5$var$DEFAULT_MAX;
81
+ if (valueProp != null && !$66e9ff9cece0fdb5$var$isValidValueNumber(valueProp, max)) return new Error($66e9ff9cece0fdb5$var$getInvalidValueError(strVal, componentName));
82
+ return null;
83
+ }
84
+ };
85
+ /* -------------------------------------------------------------------------------------------------
86
+ * ProgressIndicator
87
+ * -----------------------------------------------------------------------------------------------*/ const $66e9ff9cece0fdb5$var$INDICATOR_NAME = 'ProgressIndicator';
88
+ const $66e9ff9cece0fdb5$export$2b776f7e7ee60dbd = /*#__PURE__*/ $1DGzP$react.forwardRef((props, forwardedRef)=>{
89
+ var _context$value;
90
+ const { __scopeProgress: __scopeProgress , ...indicatorProps } = props;
91
+ const context = $66e9ff9cece0fdb5$var$useProgressContext($66e9ff9cece0fdb5$var$INDICATOR_NAME, __scopeProgress);
92
+ return /*#__PURE__*/ $1DGzP$react.createElement($1DGzP$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($1DGzP$babelruntimehelpersextends))({
93
+ "data-state": $66e9ff9cece0fdb5$var$getProgressState(context.value, context.max),
94
+ "data-value": (_context$value = context.value) !== null && _context$value !== void 0 ? _context$value : undefined,
95
+ "data-max": context.max
96
+ }, indicatorProps, {
97
+ ref: forwardedRef
98
+ }));
99
+ });
100
+ /*#__PURE__*/ Object.assign($66e9ff9cece0fdb5$export$2b776f7e7ee60dbd, {
101
+ displayName: $66e9ff9cece0fdb5$var$INDICATOR_NAME
102
+ });
103
+ /* ---------------------------------------------------------------------------------------------- */ function $66e9ff9cece0fdb5$var$defaultGetValueLabel(value, max) {
104
+ return `${Math.round(value / max * 100)}%`;
105
+ }
106
+ function $66e9ff9cece0fdb5$var$getProgressState(value, maxValue) {
107
+ return value == null ? 'indeterminate' : value === maxValue ? 'complete' : 'loading';
108
+ }
109
+ function $66e9ff9cece0fdb5$var$isNumber(value) {
110
+ return typeof value === 'number';
111
+ }
112
+ function $66e9ff9cece0fdb5$var$isValidMaxNumber(max) {
113
+ // prettier-ignore
114
+ return $66e9ff9cece0fdb5$var$isNumber(max) && !isNaN(max) && max > 0;
115
+ }
116
+ function $66e9ff9cece0fdb5$var$isValidValueNumber(value, max) {
117
+ // prettier-ignore
118
+ return $66e9ff9cece0fdb5$var$isNumber(value) && !isNaN(value) && value <= max && value >= 0;
119
+ } // Split this out for clearer readability of the error message.
120
+ function $66e9ff9cece0fdb5$var$getInvalidMaxError(propValue, componentName) {
121
+ 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}\`.`;
122
+ }
123
+ function $66e9ff9cece0fdb5$var$getInvalidValueError(propValue, componentName) {
124
+ return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
125
+ - a positive number
126
+ - less than the value passed to \`max\` (or ${$66e9ff9cece0fdb5$var$DEFAULT_MAX} if no \`max\` prop is set)
127
+ - \`null\` if the progress is indeterminate.
128
+
129
+ Defaulting to \`null\`.`;
130
+ }
131
+ const $66e9ff9cece0fdb5$export$be92b6f5f03c0fe9 = $66e9ff9cece0fdb5$export$b25a304ec7d746bb;
132
+ const $66e9ff9cece0fdb5$export$adb584737d712b70 = $66e9ff9cece0fdb5$export$2b776f7e7ee60dbd;
133
+
134
+
135
+ $parcel$exportWildcard(module.exports, $66e9ff9cece0fdb5$exports);
136
+
137
+
2
138
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"IAYgCA,EAAMC,EAZNC,8GAYAF,KAAMC,mBACpCE,OAAOC,KAAKH,GAAQI,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeP,EAAMM,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOR,EAAOK,SAKbN,MA1BuBE,8CAClBA,EAAEQ,WAAaR,EAAES,QAAUT,ECUzC,MAIOU,EAAuBC,GAAuBC,EAJ/B,0CAQtB,MAAOC,EAAkBC,GACvBJ,EAToB,YAmBhBK,eAAWC,EAAMC,YACrB,CAACC,EAAmCC,KAClC,MAAMC,gBACJA,EACAC,MAAOC,EACPC,IAAKC,EAHDC,cAIJA,EAAgBC,KACbC,GACDT,EAEEK,EAAMK,EAAiBJ,GAAWA,EA5BxB,IA6BVH,EAAQQ,EAAmBP,EAAWC,GAAOD,EAAY,KACzDQ,EAAaC,EAASV,GAASI,EAAcJ,EAAOE,QAAOS,eAEjE,OACEC,EAAAC,cAACC,EAAD,CAAkBC,MAAOhB,EAAiBC,MAAOA,EAAOE,IAAKA,gBAC3DU,EAAAC,cAACG,EAAUC,IAAXC,EAAA,CACE,gBAAehB,EACf,gBAAe,EACf,gBAAeQ,EAASV,GAASA,OAAQW,EACzC,iBAAgBF,EAChBU,KAAK,cACL,aAAYC,EAAiBpB,EAAOE,GACpC,aAAYF,MAAAA,EAAAA,OAASW,EACrB,WAAUT,GACNI,EATN,CAUEe,IAAKvB,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AMtC,IACPA,GAASE,GACTF,GAAS,8BAkBb,MAAMuC,EAAO7C,iBACb,MAAM8C,EAAYT","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/progress/src/Progress.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Progress\n * -----------------------------------------------------------------------------------------------*/\n\nconst PROGRESS_NAME = 'Progress';\nconst DEFAULT_MAX = 100;\n\ntype ScopedProps<P> = P & { __scopeProgress?: Scope };\nconst [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);\n\ntype ProgressState = 'indeterminate' | 'complete' | 'loading';\ntype ProgressContextValue = { value: number | null; max: number };\nconst [ProgressProvider, useProgressContext] =\n createProgressContext<ProgressContextValue>(PROGRESS_NAME);\n\ntype ProgressElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface ProgressProps extends PrimitiveDivProps {\n value?: number | null | undefined;\n max?: number;\n getValueLabel?(value: number, max: number): string;\n}\n\nconst Progress = React.forwardRef<ProgressElement, ProgressProps>(\n (props: ScopedProps<ProgressProps>, forwardedRef) => {\n const {\n __scopeProgress,\n value: valueProp,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n ...progressProps\n } = props;\n\n const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;\n const value = isValidValueNumber(valueProp, max) ? valueProp : null;\n const valueLabel = isNumber(value) ? getValueLabel(value, max) : undefined;\n\n return (\n <ProgressProvider scope={__scopeProgress} value={value} max={max}>\n <Primitive.div\n aria-valuemax={max}\n aria-valuemin={0}\n aria-valuenow={isNumber(value) ? value : undefined}\n aria-valuetext={valueLabel}\n role=\"progressbar\"\n data-state={getProgressState(value, max)}\n data-value={value ?? undefined}\n data-max={max}\n {...progressProps}\n ref={forwardedRef}\n />\n </ProgressProvider>\n );\n }\n);\n\nProgress.displayName = PROGRESS_NAME;\n\nProgress.propTypes = {\n max(props, propName, componentName) {\n const propValue = props[propName];\n const strVal = String(propValue);\n if (propValue && !isValidMaxNumber(propValue)) {\n return new Error(getInvalidMaxError(strVal, componentName));\n }\n return null;\n },\n value(props, propName, componentName) {\n const valueProp = props[propName];\n const strVal = String(valueProp);\n const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;\n if (valueProp != null && !isValidValueNumber(valueProp, max)) {\n return new Error(getInvalidValueError(strVal, componentName));\n }\n return null;\n },\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProgressIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'ProgressIndicator';\n\ntype ProgressIndicatorElement = React.ElementRef<typeof Primitive.div>;\ninterface ProgressIndicatorProps extends PrimitiveDivProps {}\n\nconst ProgressIndicator = React.forwardRef<ProgressIndicatorElement, ProgressIndicatorProps>(\n (props: ScopedProps<ProgressIndicatorProps>, forwardedRef) => {\n const { __scopeProgress, ...indicatorProps } = props;\n const context = useProgressContext(INDICATOR_NAME, __scopeProgress);\n return (\n <Primitive.div\n data-state={getProgressState(context.value, context.max)}\n data-value={context.value ?? undefined}\n data-max={context.max}\n {...indicatorProps}\n ref={forwardedRef}\n />\n );\n }\n);\n\nProgressIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction defaultGetValueLabel(value: number, max: number) {\n return `${Math.round((value / max) * 100)}%`;\n}\n\nfunction getProgressState(value: number | undefined | null, maxValue: number): ProgressState {\n return value == null ? 'indeterminate' : value === maxValue ? 'complete' : 'loading';\n}\n\nfunction isNumber(value: any): value is number {\n return typeof value === 'number';\n}\n\nfunction isValidMaxNumber(max: any): max is number {\n // prettier-ignore\n return (\n isNumber(max) &&\n !isNaN(max) &&\n max > 0\n );\n}\n\nfunction isValidValueNumber(value: any, max: number): value is number {\n // prettier-ignore\n return (\n isNumber(value) &&\n !isNaN(value) &&\n value <= max &&\n value >= 0\n );\n}\n\n// Split this out for clearer readability of the error message.\nfunction getInvalidMaxError(propValue: string, componentName: string) {\n return `Invalid prop \\`max\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. Only numbers greater than 0 are valid max values. Defaulting to \\`${DEFAULT_MAX}\\`.`;\n}\n\nfunction getInvalidValueError(propValue: string, componentName: string) {\n return `Invalid prop \\`value\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. The \\`value\\` prop must be:\n - a positive number\n - less than the value passed to \\`max\\` (or ${DEFAULT_MAX} if no \\`max\\` prop is set)\n - \\`null\\` if the progress is indeterminate.\n\nDefaulting to \\`null\\`.`;\n}\n\nconst Root = Progress;\nconst Indicator = ProgressIndicator;\n\nexport {\n createProgressScope,\n //\n Progress,\n ProgressIndicator,\n //\n Root,\n Indicator,\n};\nexport type { ProgressProps, ProgressIndicatorProps };\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","createProgressContext","createProgressScope","createContextScope","ProgressProvider","useProgressContext","Progress","React","forwardRef","props","forwardedRef","__scopeProgress","value","valueProp","max","maxProp","getValueLabel","defaultGetValueLabel","progressProps","isValidMaxNumber","isValidValueNumber","valueLabel","isNumber","undefined","_react","createElement","$b3fbbcf6ced69600a6d4c5fc151c3856$var$ProgressProvider","scope","Primitive","div","_babelRuntimeHelpersExtends","role","getProgressState","ref","propTypes","propName","componentName","propValue","strVal","String","Error","getInvalidMaxError","getInvalidValueError","ProgressIndicator","_context$value","indicatorProps","context","Math","round","maxValue","isNaN","Root","Indicator"],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;ACOA;;oGAEA,CAEA,MAAMG,mCAAa,GAAG,UAAtB,AAAA;AACA,MAAMC,iCAAW,GAAG,GAApB,AAAA;AAGA,MAAM,CAACC,2CAAD,EAAwBC,yCAAxB,CAAA,GAA+CL,6CAAkB,CAACE,mCAAD,CAAvE,AAAA;AAIA,MAAM,CAACI,sCAAD,EAAmBC,wCAAnB,CAAA,GACJH,2CAAqB,CAAuBF,mCAAvB,CADvB,AAAA;AAWA,MAAMM,yCAAQ,GAAA,aAAGT,CAAAA,uBAAA,CACf,CAACW,KAAD,EAAoCC,YAApC,GAAqD;IACnD,MAAM,E,iBACJC,eADI,CAAA,EAEJC,KAAK,EAAEC,SAFH,CAAA,EAGJC,GAAG,EAAEC,OAHD,CAAA,iBAIJC,aAAa,GAAGC,0CAJZ,GAKJ,GAAGC,aAAH,EALI,GAMFT,KANJ,AAAM;IAQN,MAAMK,GAAG,GAAGK,sCAAgB,CAACJ,OAAD,CAAhB,GAA4BA,OAA5B,GAAsCb,iCAAlD,AAAA;IACA,MAAMU,KAAK,GAAGQ,wCAAkB,CAACP,SAAD,EAAYC,GAAZ,CAAlB,GAAqCD,SAArC,GAAiD,IAA/D,AAAA;IACA,MAAMQ,UAAU,GAAGC,8BAAQ,CAACV,KAAD,CAAR,GAAkBI,aA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;IACtE,OAAQ,CAAA,kCAAA,EAAoCC,SAAU,CAAA,iBAAA,EAAmBD,aAAc,CAAvF;;8CAEF,EAAgDzB,iCAAY,CAA5D;;;uBAGA,CALE,CAKF;CACC;AAED,MAAMwC,yCAAI,GAAGnC,yCAAb,AAAA;AACA,MAAMoC,yCAAS,GAAGR,yCAAlB,AAAA;;ADhKA","sources":["packages/react/progress/src/index.ts","packages/react/progress/src/Progress.tsx"],"sourcesContent":["export * from './Progress';\n","import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Progress\n * -----------------------------------------------------------------------------------------------*/\n\nconst PROGRESS_NAME = 'Progress';\nconst DEFAULT_MAX = 100;\n\ntype ScopedProps<P> = P & { __scopeProgress?: Scope };\nconst [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);\n\ntype ProgressState = 'indeterminate' | 'complete' | 'loading';\ntype ProgressContextValue = { value: number | null; max: number };\nconst [ProgressProvider, useProgressContext] =\n createProgressContext<ProgressContextValue>(PROGRESS_NAME);\n\ntype ProgressElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface ProgressProps extends PrimitiveDivProps {\n value?: number | null | undefined;\n max?: number;\n getValueLabel?(value: number, max: number): string;\n}\n\nconst Progress = React.forwardRef<ProgressElement, ProgressProps>(\n (props: ScopedProps<ProgressProps>, forwardedRef) => {\n const {\n __scopeProgress,\n value: valueProp,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n ...progressProps\n } = props;\n\n const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;\n const value = isValidValueNumber(valueProp, max) ? valueProp : null;\n const valueLabel = isNumber(value) ? getValueLabel(value, max) : undefined;\n\n return (\n <ProgressProvider scope={__scopeProgress} value={value} max={max}>\n <Primitive.div\n aria-valuemax={max}\n aria-valuemin={0}\n aria-valuenow={isNumber(value) ? value : undefined}\n aria-valuetext={valueLabel}\n role=\"progressbar\"\n data-state={getProgressState(value, max)}\n data-value={value ?? undefined}\n data-max={max}\n {...progressProps}\n ref={forwardedRef}\n />\n </ProgressProvider>\n );\n }\n);\n\nProgress.displayName = PROGRESS_NAME;\n\nProgress.propTypes = {\n max(props, propName, componentName) {\n const propValue = props[propName];\n const strVal = String(propValue);\n if (propValue && !isValidMaxNumber(propValue)) {\n return new Error(getInvalidMaxError(strVal, componentName));\n }\n return null;\n },\n value(props, propName, componentName) {\n const valueProp = props[propName];\n const strVal = String(valueProp);\n const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;\n if (valueProp != null && !isValidValueNumber(valueProp, max)) {\n return new Error(getInvalidValueError(strVal, componentName));\n }\n return null;\n },\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProgressIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'ProgressIndicator';\n\ntype ProgressIndicatorElement = React.ElementRef<typeof Primitive.div>;\ninterface ProgressIndicatorProps extends PrimitiveDivProps {}\n\nconst ProgressIndicator = React.forwardRef<ProgressIndicatorElement, ProgressIndicatorProps>(\n (props: ScopedProps<ProgressIndicatorProps>, forwardedRef) => {\n const { __scopeProgress, ...indicatorProps } = props;\n const context = useProgressContext(INDICATOR_NAME, __scopeProgress);\n return (\n <Primitive.div\n data-state={getProgressState(context.value, context.max)}\n data-value={context.value ?? undefined}\n data-max={context.max}\n {...indicatorProps}\n ref={forwardedRef}\n />\n );\n }\n);\n\nProgressIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction defaultGetValueLabel(value: number, max: number) {\n return `${Math.round((value / max) * 100)}%`;\n}\n\nfunction getProgressState(value: number | undefined | null, maxValue: number): ProgressState {\n return value == null ? 'indeterminate' : value === maxValue ? 'complete' : 'loading';\n}\n\nfunction isNumber(value: any): value is number {\n return typeof value === 'number';\n}\n\nfunction isValidMaxNumber(max: any): max is number {\n // prettier-ignore\n return (\n isNumber(max) &&\n !isNaN(max) &&\n max > 0\n );\n}\n\nfunction isValidValueNumber(value: any, max: number): value is number {\n // prettier-ignore\n return (\n isNumber(value) &&\n !isNaN(value) &&\n value <= max &&\n value >= 0\n );\n}\n\n// Split this out for clearer readability of the error message.\nfunction getInvalidMaxError(propValue: string, componentName: string) {\n return `Invalid prop \\`max\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. Only numbers greater than 0 are valid max values. Defaulting to \\`${DEFAULT_MAX}\\`.`;\n}\n\nfunction getInvalidValueError(propValue: string, componentName: string) {\n return `Invalid prop \\`value\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. The \\`value\\` prop must be:\n - a positive number\n - less than the value passed to \\`max\\` (or ${DEFAULT_MAX} if no \\`max\\` prop is set)\n - \\`null\\` if the progress is indeterminate.\n\nDefaulting to \\`null\\`.`;\n}\n\nconst Root = Progress;\nconst Indicator = ProgressIndicator;\n\nexport {\n createProgressScope,\n //\n Progress,\n ProgressIndicator,\n //\n Root,\n Indicator,\n};\nexport type { ProgressProps, ProgressIndicatorProps };\n"],"names":["React","createContextScope","Primitive","PROGRESS_NAME","DEFAULT_MAX","createProgressContext","createProgressScope","ProgressProvider","useProgressContext","Progress","forwardRef","props","forwardedRef","__scopeProgress","value","valueProp","max","maxProp","getValueLabel","defaultGetValueLabel","progressProps","isValidMaxNumber","isValidValueNumber","valueLabel","isNumber","undefined","getProgressState","propTypes","propName","componentName","propValue","strVal","String","Error","getInvalidMaxError","getInvalidValueError","INDICATOR_NAME","ProgressIndicator","indicatorProps","context","Math","round","maxValue","isNaN","Root","Indicator"],"version":3,"file":"index.js.map"}
@@ -1,2 +1,119 @@
1
- import{Primitive as e}from"@radix-ui/react-primitive";import{createContextScope as r}from"@radix-ui/react-context";import*as t from"react";import a from"@babel/runtime/helpers/esm/extends";const[n,o]=r("Progress");export{o as createProgressScope};const[s,i]=n("Progress");export const Progress=/*#__PURE__*/t.forwardRef(((r,n)=>{const{__scopeProgress:o,value:i,max:d,getValueLabel:v=u,...f}=r,x=p(d)?d:100,g=c(i,x)?i:null,P=m(g)?v(g,x):void 0;/*#__PURE__*/return t.createElement(s,{scope:o,value:g,max:x},/*#__PURE__*/t.createElement(e.div,a({"aria-valuemax":x,"aria-valuemin":0,"aria-valuenow":m(g)?g:void 0,"aria-valuetext":P,role:"progressbar","data-state":l(g,x),"data-value":null!=g?g:void 0,"data-max":x},f,{ref:n})))}));/*#__PURE__*/Progress.propTypes={max(e,r,t){const a=e[r],n=String(a);return a&&!p(a)?new Error(function(e,r){return`Invalid prop \`max\` of value \`${e}\` supplied to \`${r}\`. Only numbers greater than 0 are valid max values. Defaulting to \`100\`.`}(n,t)):null},value(e,r,t){const a=e[r],n=String(a),o=p(e.max)?e.max:100;return null==a||c(a,o)?null:new Error(function(e,r){return`Invalid prop \`value\` of value \`${e}\` supplied to \`${r}\`. The \`value\` prop must be:\n - a positive number\n - less than the value passed to \`max\` (or 100 if no \`max\` prop is set)\n - \`null\` if the progress is indeterminate.\n\nDefaulting to \`null\`.`}(n,t))}};export const ProgressIndicator=/*#__PURE__*/t.forwardRef(((r,n)=>{var o;const{__scopeProgress:s,...u}=r,m=i("ProgressIndicator",s);/*#__PURE__*/return t.createElement(e.div,a({"data-state":l(m.value,m.max),"data-value":null!==(o=m.value)&&void 0!==o?o:void 0,"data-max":m.max},u,{ref:n}))}));/*#__PURE__*/function u(e,r){return`${Math.round(e/r*100)}%`}function l(e,r){return null==e?"indeterminate":e===r?"complete":"loading"}function m(e){return"number"==typeof e}function p(e){return m(e)&&!isNaN(e)&&e>0}function c(e,r){return m(e)&&!isNaN(e)&&e<=r&&e>=0}export const Root=Progress;export const Indicator=ProgressIndicator;
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
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+ var $67824d98245208a0$exports = {};
10
+
11
+ $parcel$export($67824d98245208a0$exports, "createProgressScope", () => $67824d98245208a0$export$388eb2d8f6d3261f);
12
+ $parcel$export($67824d98245208a0$exports, "Progress", () => $67824d98245208a0$export$b25a304ec7d746bb);
13
+ $parcel$export($67824d98245208a0$exports, "ProgressIndicator", () => $67824d98245208a0$export$2b776f7e7ee60dbd);
14
+ $parcel$export($67824d98245208a0$exports, "Root", () => $67824d98245208a0$export$be92b6f5f03c0fe9);
15
+ $parcel$export($67824d98245208a0$exports, "Indicator", () => $67824d98245208a0$export$adb584737d712b70);
16
+
17
+
18
+
19
+
20
+ /* -------------------------------------------------------------------------------------------------
21
+ * Progress
22
+ * -----------------------------------------------------------------------------------------------*/ const $67824d98245208a0$var$PROGRESS_NAME = 'Progress';
23
+ const $67824d98245208a0$var$DEFAULT_MAX = 100;
24
+ const [$67824d98245208a0$var$createProgressContext, $67824d98245208a0$export$388eb2d8f6d3261f] = $k03wI$createContextScope($67824d98245208a0$var$PROGRESS_NAME);
25
+ const [$67824d98245208a0$var$ProgressProvider, $67824d98245208a0$var$useProgressContext] = $67824d98245208a0$var$createProgressContext($67824d98245208a0$var$PROGRESS_NAME);
26
+ const $67824d98245208a0$export$b25a304ec7d746bb = /*#__PURE__*/ $k03wI$forwardRef((props, forwardedRef)=>{
27
+ const { __scopeProgress: __scopeProgress , value: valueProp , max: maxProp , getValueLabel: getValueLabel = $67824d98245208a0$var$defaultGetValueLabel , ...progressProps } = props;
28
+ const max = $67824d98245208a0$var$isValidMaxNumber(maxProp) ? maxProp : $67824d98245208a0$var$DEFAULT_MAX;
29
+ const value = $67824d98245208a0$var$isValidValueNumber(valueProp, max) ? valueProp : null;
30
+ const valueLabel = $67824d98245208a0$var$isNumber(value) ? getValueLabel(value, max) : undefined;
31
+ return /*#__PURE__*/ $k03wI$createElement($67824d98245208a0$var$ProgressProvider, {
32
+ scope: __scopeProgress,
33
+ value: value,
34
+ max: max
35
+ }, /*#__PURE__*/ $k03wI$createElement($k03wI$Primitive.div, $k03wI$babelruntimehelpersesmextends({
36
+ "aria-valuemax": max,
37
+ "aria-valuemin": 0,
38
+ "aria-valuenow": $67824d98245208a0$var$isNumber(value) ? value : undefined,
39
+ "aria-valuetext": valueLabel,
40
+ role: "progressbar",
41
+ "data-state": $67824d98245208a0$var$getProgressState(value, max),
42
+ "data-value": value !== null && value !== void 0 ? value : undefined,
43
+ "data-max": max
44
+ }, progressProps, {
45
+ ref: forwardedRef
46
+ })));
47
+ });
48
+ /*#__PURE__*/ Object.assign($67824d98245208a0$export$b25a304ec7d746bb, {
49
+ displayName: $67824d98245208a0$var$PROGRESS_NAME
50
+ });
51
+ $67824d98245208a0$export$b25a304ec7d746bb.propTypes = {
52
+ max (props, propName, componentName) {
53
+ const propValue = props[propName];
54
+ const strVal = String(propValue);
55
+ if (propValue && !$67824d98245208a0$var$isValidMaxNumber(propValue)) return new Error($67824d98245208a0$var$getInvalidMaxError(strVal, componentName));
56
+ return null;
57
+ },
58
+ value (props, propName, componentName) {
59
+ const valueProp = props[propName];
60
+ const strVal = String(valueProp);
61
+ const max = $67824d98245208a0$var$isValidMaxNumber(props.max) ? props.max : $67824d98245208a0$var$DEFAULT_MAX;
62
+ if (valueProp != null && !$67824d98245208a0$var$isValidValueNumber(valueProp, max)) return new Error($67824d98245208a0$var$getInvalidValueError(strVal, componentName));
63
+ return null;
64
+ }
65
+ };
66
+ /* -------------------------------------------------------------------------------------------------
67
+ * ProgressIndicator
68
+ * -----------------------------------------------------------------------------------------------*/ const $67824d98245208a0$var$INDICATOR_NAME = 'ProgressIndicator';
69
+ const $67824d98245208a0$export$2b776f7e7ee60dbd = /*#__PURE__*/ $k03wI$forwardRef((props, forwardedRef)=>{
70
+ var _context$value;
71
+ const { __scopeProgress: __scopeProgress , ...indicatorProps } = props;
72
+ const context = $67824d98245208a0$var$useProgressContext($67824d98245208a0$var$INDICATOR_NAME, __scopeProgress);
73
+ return /*#__PURE__*/ $k03wI$createElement($k03wI$Primitive.div, $k03wI$babelruntimehelpersesmextends({
74
+ "data-state": $67824d98245208a0$var$getProgressState(context.value, context.max),
75
+ "data-value": (_context$value = context.value) !== null && _context$value !== void 0 ? _context$value : undefined,
76
+ "data-max": context.max
77
+ }, indicatorProps, {
78
+ ref: forwardedRef
79
+ }));
80
+ });
81
+ /*#__PURE__*/ Object.assign($67824d98245208a0$export$2b776f7e7ee60dbd, {
82
+ displayName: $67824d98245208a0$var$INDICATOR_NAME
83
+ });
84
+ /* ---------------------------------------------------------------------------------------------- */ function $67824d98245208a0$var$defaultGetValueLabel(value, max) {
85
+ return `${Math.round(value / max * 100)}%`;
86
+ }
87
+ function $67824d98245208a0$var$getProgressState(value, maxValue) {
88
+ return value == null ? 'indeterminate' : value === maxValue ? 'complete' : 'loading';
89
+ }
90
+ function $67824d98245208a0$var$isNumber(value) {
91
+ return typeof value === 'number';
92
+ }
93
+ function $67824d98245208a0$var$isValidMaxNumber(max) {
94
+ // prettier-ignore
95
+ return $67824d98245208a0$var$isNumber(max) && !isNaN(max) && max > 0;
96
+ }
97
+ function $67824d98245208a0$var$isValidValueNumber(value, max) {
98
+ // prettier-ignore
99
+ return $67824d98245208a0$var$isNumber(value) && !isNaN(value) && value <= max && value >= 0;
100
+ } // Split this out for clearer readability of the error message.
101
+ function $67824d98245208a0$var$getInvalidMaxError(propValue, componentName) {
102
+ 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}\`.`;
103
+ }
104
+ function $67824d98245208a0$var$getInvalidValueError(propValue, componentName) {
105
+ return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
106
+ - a positive number
107
+ - less than the value passed to \`max\` (or ${$67824d98245208a0$var$DEFAULT_MAX} if no \`max\` prop is set)
108
+ - \`null\` if the progress is indeterminate.
109
+
110
+ Defaulting to \`null\`.`;
111
+ }
112
+ const $67824d98245208a0$export$be92b6f5f03c0fe9 = $67824d98245208a0$export$b25a304ec7d746bb;
113
+ const $67824d98245208a0$export$adb584737d712b70 = $67824d98245208a0$export$2b776f7e7ee60dbd;
114
+
115
+
116
+
117
+
118
+ 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};
2
119
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"6LAWA,MAIOA,EAAuBC,GAAuBC,EAJ/B,6CAQtB,MAAOC,EAAkBC,GACvBJ,EAToB,mBAmBtB,MAAMK,sBAAWC,EAAMC,YACrB,CAACC,EAAmCC,KAClC,MAAMC,gBACJA,EACAC,MAAOC,EACPC,IAAKC,EAHDC,cAIJA,EAAgBC,KACbC,GACDT,EAEEK,EAAMK,EAAiBJ,GAAWA,EA5BxB,IA6BVH,EAAQQ,EAAmBP,EAAWC,GAAOD,EAAY,KACzDQ,EAAaC,EAASV,GAASI,EAAcJ,EAAOE,QAAOS,eAEjE,OACEC,EAAAC,cAACC,EAAD,CAAkBC,MAAOhB,EAAiBC,MAAOA,EAAOE,IAAKA,gBAC3DU,EAAAC,cAACG,EAAUC,IAAXC,EAAA,CACE,gBAAehB,EACf,gBAAe,EACf,gBAAeQ,EAASV,GAASA,OAAQW,EACzC,iBAAgBF,EAChBU,KAAK,cACL,aAAYC,EAAiBpB,EAAOE,GACpC,aAAYF,MAAAA,EAAAA,OAASW,EACrB,WAAUT,GACNI,EATN,CAU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ASV,KACRsC,MAAMtC,IACPA,GAASE,GACTF,GAAS,SAkBb,MAAMuC,KAAO7C,gBACb,MAAM8C,UAAYT","sources":["./packages/react/progress/src/Progress.tsx"],"sourcesContent":["import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Progress\n * -----------------------------------------------------------------------------------------------*/\n\nconst PROGRESS_NAME = 'Progress';\nconst DEFAULT_MAX = 100;\n\ntype ScopedProps<P> = P & { __scopeProgress?: Scope };\nconst [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);\n\ntype ProgressState = 'indeterminate' | 'complete' | 'loading';\ntype ProgressContextValue = { value: number | null; max: number };\nconst [ProgressProvider, useProgressContext] =\n createProgressContext<ProgressContextValue>(PROGRESS_NAME);\n\ntype ProgressElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface ProgressProps extends PrimitiveDivProps {\n value?: number | null | undefined;\n max?: number;\n getValueLabel?(value: number, max: number): string;\n}\n\nconst Progress = React.forwardRef<ProgressElement, ProgressProps>(\n (props: ScopedProps<ProgressProps>, forwardedRef) => {\n const {\n __scopeProgress,\n value: valueProp,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n ...progressProps\n } = props;\n\n const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;\n const value = isValidValueNumber(valueProp, max) ? valueProp : null;\n const valueLabel = isNumber(value) ? getValueLabel(value, max) : undefined;\n\n return (\n <ProgressProvider scope={__scopeProgress} value={value} max={max}>\n <Primitive.div\n aria-valuemax={max}\n aria-valuemin={0}\n aria-valuenow={isNumber(value) ? value : undefined}\n aria-valuetext={valueLabel}\n role=\"progressbar\"\n data-state={getProgressState(value, max)}\n data-value={value ?? undefined}\n data-max={max}\n {...progressProps}\n ref={forwardedRef}\n />\n </ProgressProvider>\n );\n }\n);\n\nProgress.displayName = PROGRESS_NAME;\n\nProgress.propTypes = {\n max(props, propName, componentName) {\n const propValue = props[propName];\n const strVal = String(propValue);\n if (propValue && !isValidMaxNumber(propValue)) {\n return new Error(getInvalidMaxError(strVal, componentName));\n }\n return null;\n },\n value(props, propName, componentName) {\n const valueProp = props[propName];\n const strVal = String(valueProp);\n const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;\n if (valueProp != null && !isValidValueNumber(valueProp, max)) {\n return new Error(getInvalidValueError(strVal, componentName));\n }\n return null;\n },\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProgressIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'ProgressIndicator';\n\ntype ProgressIndicatorElement = React.ElementRef<typeof Primitive.div>;\ninterface ProgressIndicatorProps extends PrimitiveDivProps {}\n\nconst ProgressIndicator = React.forwardRef<ProgressIndicatorElement, ProgressIndicatorProps>(\n (props: ScopedProps<ProgressIndicatorProps>, forwardedRef) => {\n const { __scopeProgress, ...indicatorProps } = props;\n const context = useProgressContext(INDICATOR_NAME, __scopeProgress);\n return (\n <Primitive.div\n data-state={getProgressState(context.value, context.max)}\n data-value={context.value ?? undefined}\n data-max={context.max}\n {...indicatorProps}\n ref={forwardedRef}\n />\n );\n }\n);\n\nProgressIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction defaultGetValueLabel(value: number, max: number) {\n return `${Math.round((value / max) * 100)}%`;\n}\n\nfunction getProgressState(value: number | undefined | null, maxValue: number): ProgressState {\n return value == null ? 'indeterminate' : value === maxValue ? 'complete' : 'loading';\n}\n\nfunction isNumber(value: any): value is number {\n return typeof value === 'number';\n}\n\nfunction isValidMaxNumber(max: any): max is number {\n // prettier-ignore\n return (\n isNumber(max) &&\n !isNaN(max) &&\n max > 0\n );\n}\n\nfunction isValidValueNumber(value: any, max: number): value is number {\n // prettier-ignore\n return (\n isNumber(value) &&\n !isNaN(value) &&\n value <= max &&\n value >= 0\n );\n}\n\n// Split this out for clearer readability of the error message.\nfunction getInvalidMaxError(propValue: string, componentName: string) {\n return `Invalid prop \\`max\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. Only numbers greater than 0 are valid max values. Defaulting to \\`${DEFAULT_MAX}\\`.`;\n}\n\nfunction getInvalidValueError(propValue: string, componentName: string) {\n return `Invalid prop \\`value\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. The \\`value\\` prop must be:\n - a positive number\n - less than the value passed to \\`max\\` (or ${DEFAULT_MAX} if no \\`max\\` prop is set)\n - \\`null\\` if the progress is indeterminate.\n\nDefaulting to \\`null\\`.`;\n}\n\nconst Root = Progress;\nconst Indicator = ProgressIndicator;\n\nexport {\n createProgressScope,\n //\n Progress,\n ProgressIndicator,\n //\n Root,\n Indicator,\n};\nexport type { ProgressProps, ProgressIndicatorProps };\n"],"names":["createProgressContext","createProgressScope","createContextScope","ProgressProvider","useProgressContext","Progress","React","forwardRef","props","forwardedRef","__scopeProgress","value","valueProp","max","maxProp","getValueLabel","defaultGetValueLabel","progressProps","isValidMaxNumber","isValidValueNumber","valueLabel","isNumber","undefined","_react","createElement","$fc61ea0f5d6587188592ef12afccad3f$var$ProgressProvider","scope","Primitive","div","_babelRuntimeHelpersEsmExtends","role","getProgressState","ref","propTypes","propName","componentName","propValue","strVal","String","Error","getInvalidMaxError","getInvalidValueError","ProgressIndicator","_context$value","indicatorProps","context","Math","round","maxValue","isNaN","Root","Indicator"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;A;;;;ACOA;;oGAEA,CAEA,MAAMG,mCAAa,GAAG,UAAtB,AAAA;AACA,MAAMC,iCAAW,GAAG,GAApB,AAAA;AAGA,MAAM,CAACC,2CAAD,EAAwBC,yCAAxB,CAAA,GAA+CL,yBAAkB,CAACE,mCAAD,CAAvE,AAAA;AAIA,MAAM,CAACI,sCAA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,kBAAA;IACA,OACEQ,8BAAQ,CAACR,GAAD,CAAR,IACA,CAAC2B,KAAK,CAAC3B,GAAD,CADN,IAEAA,GAAG,GAAG,CAHR,CAAA;CAKD;AAED,SAASM,wCAAT,CAA4BR,KAA5B,EAAwCE,GAAxC,EAAsE;IACpE,kBAAA;IACA,OACEQ,8BAAQ,CAACV,KAAD,CAAR,IACA,CAAC6B,KAAK,CAAC7B,KAAD,CADN,IAEAA,KAAK,IAAIE,GAFT,IAGAF,KAAK,IAAI,CAJX,CAAA;C,CAQF,+DAFC;AAGD,SAASoB,wCAAT,CAA4BJ,SAA5B,EAA+CD,aAA/C,EAAsE;IACpE,OAAQ,CAAA,gCAAA,EAAkCC,SAAU,CAAA,iBAAA,EAAmBD,aAAc,CAAA,sEAAA,EAAwEzB,iCAAY,CAAA,GAAA,CAAzK,CAAA;CACD;AAED,SAAS+B,0CAAT,CAA8BL,SAA9B,EAAiDD,aAAjD,EAAwE;IACtE,OAAQ,CAAA,kCAAA,EAAoCC,SAAU,CAAA,iBAAA,EAAmBD,aAAc,CAAvF;;8CAEF,EAAgDzB,iCAAY,CAA5D;;;uBAGA,CALE,CAKF;CACC;AAED,MAAMwC,yCAAI,GAAGnC,yCAAb,AAAA;AACA,MAAMoC,yCAAS,GAAGR,yCAAlB,AAAA;;ADhKA","sources":["packages/react/progress/src/index.ts","packages/react/progress/src/Progress.tsx"],"sourcesContent":["export * from './Progress';\n","import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Progress\n * -----------------------------------------------------------------------------------------------*/\n\nconst PROGRESS_NAME = 'Progress';\nconst DEFAULT_MAX = 100;\n\ntype ScopedProps<P> = P & { __scopeProgress?: Scope };\nconst [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);\n\ntype ProgressState = 'indeterminate' | 'complete' | 'loading';\ntype ProgressContextValue = { value: number | null; max: number };\nconst [ProgressProvider, useProgressContext] =\n createProgressContext<ProgressContextValue>(PROGRESS_NAME);\n\ntype ProgressElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface ProgressProps extends PrimitiveDivProps {\n value?: number | null | undefined;\n max?: number;\n getValueLabel?(value: number, max: number): string;\n}\n\nconst Progress = React.forwardRef<ProgressElement, ProgressProps>(\n (props: ScopedProps<ProgressProps>, forwardedRef) => {\n const {\n __scopeProgress,\n value: valueProp,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n ...progressProps\n } = props;\n\n const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;\n const value = isValidValueNumber(valueProp, max) ? valueProp : null;\n const valueLabel = isNumber(value) ? getValueLabel(value, max) : undefined;\n\n return (\n <ProgressProvider scope={__scopeProgress} value={value} max={max}>\n <Primitive.div\n aria-valuemax={max}\n aria-valuemin={0}\n aria-valuenow={isNumber(value) ? value : undefined}\n aria-valuetext={valueLabel}\n role=\"progressbar\"\n data-state={getProgressState(value, max)}\n data-value={value ?? undefined}\n data-max={max}\n {...progressProps}\n ref={forwardedRef}\n />\n </ProgressProvider>\n );\n }\n);\n\nProgress.displayName = PROGRESS_NAME;\n\nProgress.propTypes = {\n max(props, propName, componentName) {\n const propValue = props[propName];\n const strVal = String(propValue);\n if (propValue && !isValidMaxNumber(propValue)) {\n return new Error(getInvalidMaxError(strVal, componentName));\n }\n return null;\n },\n value(props, propName, componentName) {\n const valueProp = props[propName];\n const strVal = String(valueProp);\n const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;\n if (valueProp != null && !isValidValueNumber(valueProp, max)) {\n return new Error(getInvalidValueError(strVal, componentName));\n }\n return null;\n },\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProgressIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'ProgressIndicator';\n\ntype ProgressIndicatorElement = React.ElementRef<typeof Primitive.div>;\ninterface ProgressIndicatorProps extends PrimitiveDivProps {}\n\nconst ProgressIndicator = React.forwardRef<ProgressIndicatorElement, ProgressIndicatorProps>(\n (props: ScopedProps<ProgressIndicatorProps>, forwardedRef) => {\n const { __scopeProgress, ...indicatorProps } = props;\n const context = useProgressContext(INDICATOR_NAME, __scopeProgress);\n return (\n <Primitive.div\n data-state={getProgressState(context.value, context.max)}\n data-value={context.value ?? undefined}\n data-max={context.max}\n {...indicatorProps}\n ref={forwardedRef}\n />\n );\n }\n);\n\nProgressIndicator.displayName = INDICATOR_NAME;\n\n/* ---------------------------------------------------------------------------------------------- */\n\nfunction defaultGetValueLabel(value: number, max: number) {\n return `${Math.round((value / max) * 100)}%`;\n}\n\nfunction getProgressState(value: number | undefined | null, maxValue: number): ProgressState {\n return value == null ? 'indeterminate' : value === maxValue ? 'complete' : 'loading';\n}\n\nfunction isNumber(value: any): value is number {\n return typeof value === 'number';\n}\n\nfunction isValidMaxNumber(max: any): max is number {\n // prettier-ignore\n return (\n isNumber(max) &&\n !isNaN(max) &&\n max > 0\n );\n}\n\nfunction isValidValueNumber(value: any, max: number): value is number {\n // prettier-ignore\n return (\n isNumber(value) &&\n !isNaN(value) &&\n value <= max &&\n value >= 0\n );\n}\n\n// Split this out for clearer readability of the error message.\nfunction getInvalidMaxError(propValue: string, componentName: string) {\n return `Invalid prop \\`max\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. Only numbers greater than 0 are valid max values. Defaulting to \\`${DEFAULT_MAX}\\`.`;\n}\n\nfunction getInvalidValueError(propValue: string, componentName: string) {\n return `Invalid prop \\`value\\` of value \\`${propValue}\\` supplied to \\`${componentName}\\`. The \\`value\\` prop must be:\n - a positive number\n - less than the value passed to \\`max\\` (or ${DEFAULT_MAX} if no \\`max\\` prop is set)\n - \\`null\\` if the progress is indeterminate.\n\nDefaulting to \\`null\\`.`;\n}\n\nconst Root = Progress;\nconst Indicator = ProgressIndicator;\n\nexport {\n createProgressScope,\n //\n Progress,\n ProgressIndicator,\n //\n Root,\n Indicator,\n};\nexport type { ProgressProps, ProgressIndicatorProps };\n"],"names":["React","createContextScope","Primitive","PROGRESS_NAME","DEFAULT_MAX","createProgressContext","createProgressScope","ProgressProvider","useProgressContext","Progress","forwardRef","props","forwardedRef","__scopeProgress","value","valueProp","max","maxProp","getValueLabel","defaultGetValueLabel","progressProps","isValidMaxNumber","isValidValueNumber","valueLabel","isNumber","undefined","getProgressState","propTypes","propName","componentName","propValue","strVal","String","Error","getInvalidMaxError","getInvalidValueError","INDICATOR_NAME","ProgressIndicator","indicatorProps","context","Math","round","maxValue","isNaN","Root","Indicator"],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-progress",
3
- "version": "0.1.5-rc.2",
3
+ "version": "0.1.5-rc.5",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.13.10",
20
- "@radix-ui/react-context": "0.1.2-rc.2",
21
- "@radix-ui/react-primitive": "0.1.5-rc.2"
20
+ "@radix-ui/react-context": "0.1.2-rc.5",
21
+ "@radix-ui/react-primitive": "0.1.5-rc.5"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": "^16.8 || ^17.0 || ^18.0"