@radix-ui/react-progress 1.0.3 → 1.1.0-rc.1
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.
- package/dist/index.d.mts +24 -12
- package/dist/index.d.ts +24 -12
- package/dist/index.js +127 -110
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +93 -90
- package/dist/index.mjs.map +7 -1
- package/package.json +5 -5
- package/dist/index.d.ts.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as Radix from
|
|
3
|
-
import { Primitive } from
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as Radix from '@radix-ui/react-primitive';
|
|
3
|
+
import { Primitive } from '@radix-ui/react-primitive';
|
|
4
|
+
|
|
5
|
+
declare type Scope<C = any> = {
|
|
6
|
+
[scopeName: string]: React.Context<C>[];
|
|
7
|
+
} | undefined;
|
|
8
|
+
declare type ScopeHook = (scope: Scope) => {
|
|
9
|
+
[__scopeProp: string]: Scope;
|
|
10
|
+
};
|
|
11
|
+
interface CreateScope {
|
|
12
|
+
scopeName: string;
|
|
13
|
+
(): ScopeHook;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const createProgressScope: CreateScope;
|
|
17
|
+
declare type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
18
|
+
interface ProgressProps extends PrimitiveDivProps {
|
|
7
19
|
value?: number | null | undefined;
|
|
8
20
|
max?: number;
|
|
9
21
|
getValueLabel?(value: number, max: number): string;
|
|
10
22
|
}
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
declare const Progress: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
|
|
24
|
+
interface ProgressIndicatorProps extends PrimitiveDivProps {
|
|
13
25
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
declare const ProgressIndicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
27
|
+
declare const Root: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
|
|
28
|
+
declare const Indicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
17
29
|
|
|
18
|
-
|
|
30
|
+
export { Indicator, Progress, ProgressIndicator, type ProgressIndicatorProps, type ProgressProps, Root, createProgressScope };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as Radix from
|
|
3
|
-
import { Primitive } from
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as Radix from '@radix-ui/react-primitive';
|
|
3
|
+
import { Primitive } from '@radix-ui/react-primitive';
|
|
4
|
+
|
|
5
|
+
declare type Scope<C = any> = {
|
|
6
|
+
[scopeName: string]: React.Context<C>[];
|
|
7
|
+
} | undefined;
|
|
8
|
+
declare type ScopeHook = (scope: Scope) => {
|
|
9
|
+
[__scopeProp: string]: Scope;
|
|
10
|
+
};
|
|
11
|
+
interface CreateScope {
|
|
12
|
+
scopeName: string;
|
|
13
|
+
(): ScopeHook;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const createProgressScope: CreateScope;
|
|
17
|
+
declare type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
18
|
+
interface ProgressProps extends PrimitiveDivProps {
|
|
7
19
|
value?: number | null | undefined;
|
|
8
20
|
max?: number;
|
|
9
21
|
getValueLabel?(value: number, max: number): string;
|
|
10
22
|
}
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
declare const Progress: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
|
|
24
|
+
interface ProgressIndicatorProps extends PrimitiveDivProps {
|
|
13
25
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
declare const ProgressIndicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
27
|
+
declare const Root: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
|
|
28
|
+
declare const Indicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
17
29
|
|
|
18
|
-
|
|
30
|
+
export { Indicator, Progress, ProgressIndicator, type ProgressIndicatorProps, type ProgressProps, Root, createProgressScope };
|
package/dist/index.js
CHANGED
|
@@ -1,120 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
21
31
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
value:
|
|
36
|
-
max:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
// packages/react/progress/src/Progress.tsx
|
|
33
|
+
var React = __toESM(__require("react"));
|
|
34
|
+
var import_react_context = __require("@radix-ui/react-context");
|
|
35
|
+
var import_react_primitive = __require("@radix-ui/react-primitive");
|
|
36
|
+
var import_jsx_runtime = __require("react/jsx-runtime");
|
|
37
|
+
var PROGRESS_NAME = "Progress";
|
|
38
|
+
var DEFAULT_MAX = 100;
|
|
39
|
+
var [createProgressContext, createProgressScope] = (0, import_react_context.createContextScope)(PROGRESS_NAME);
|
|
40
|
+
var [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
|
|
41
|
+
var Progress = React.forwardRef(
|
|
42
|
+
(props, forwardedRef) => {
|
|
43
|
+
const {
|
|
44
|
+
__scopeProgress,
|
|
45
|
+
value: valueProp,
|
|
46
|
+
max: maxProp,
|
|
47
|
+
getValueLabel = defaultGetValueLabel,
|
|
48
|
+
...progressProps
|
|
49
|
+
} = props;
|
|
50
|
+
const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
|
|
51
|
+
const value = isValidValueNumber(valueProp, max) ? valueProp : null;
|
|
52
|
+
const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressProvider, { scope: __scopeProgress, value, max, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
54
|
+
import_react_primitive.Primitive.div,
|
|
55
|
+
{
|
|
56
|
+
"aria-valuemax": max,
|
|
57
|
+
"aria-valuemin": 0,
|
|
58
|
+
"aria-valuenow": isNumber(value) ? value : void 0,
|
|
59
|
+
"aria-valuetext": valueLabel,
|
|
60
|
+
role: "progressbar",
|
|
61
|
+
"data-state": getProgressState(value, max),
|
|
62
|
+
"data-value": value ?? void 0,
|
|
63
|
+
"data-max": max,
|
|
64
|
+
...progressProps,
|
|
65
|
+
ref: forwardedRef
|
|
66
|
+
}
|
|
67
|
+
) });
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
Progress.displayName = PROGRESS_NAME;
|
|
71
|
+
Progress.propTypes = {
|
|
72
|
+
max(props, propName, componentName) {
|
|
73
|
+
const propValue = props[propName];
|
|
74
|
+
const strVal = String(propValue);
|
|
75
|
+
if (propValue && !isValidMaxNumber(propValue)) {
|
|
76
|
+
return new Error(getInvalidMaxError(strVal, componentName));
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
59
79
|
},
|
|
60
|
-
value
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return
|
|
80
|
+
value(props, propName, componentName) {
|
|
81
|
+
const valueProp = props[propName];
|
|
82
|
+
const strVal = String(valueProp);
|
|
83
|
+
const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;
|
|
84
|
+
if (valueProp != null && !isValidValueNumber(valueProp, max)) {
|
|
85
|
+
return new Error(getInvalidValueError(strVal, componentName));
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var INDICATOR_NAME = "ProgressIndicator";
|
|
91
|
+
var ProgressIndicator = React.forwardRef(
|
|
92
|
+
(props, forwardedRef) => {
|
|
93
|
+
const { __scopeProgress, ...indicatorProps } = props;
|
|
94
|
+
const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
|
|
95
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
|
+
import_react_primitive.Primitive.div,
|
|
97
|
+
{
|
|
98
|
+
"data-state": getProgressState(context.value, context.max),
|
|
99
|
+
"data-value": context.value ?? void 0,
|
|
100
|
+
"data-max": context.max,
|
|
101
|
+
...indicatorProps,
|
|
102
|
+
ref: forwardedRef
|
|
103
|
+
}
|
|
104
|
+
);
|
|
66
105
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* -----------------------------------------------------------------------------------------------*/ const $66e9ff9cece0fdb5$var$INDICATOR_NAME = 'ProgressIndicator';
|
|
71
|
-
const $66e9ff9cece0fdb5$export$2b776f7e7ee60dbd = /*#__PURE__*/ $1DGzP$react.forwardRef((props, forwardedRef)=>{
|
|
72
|
-
var _context$value;
|
|
73
|
-
const { __scopeProgress: __scopeProgress , ...indicatorProps } = props;
|
|
74
|
-
const context = $66e9ff9cece0fdb5$var$useProgressContext($66e9ff9cece0fdb5$var$INDICATOR_NAME, __scopeProgress);
|
|
75
|
-
return /*#__PURE__*/ $1DGzP$react.createElement($1DGzP$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($1DGzP$babelruntimehelpersextends))({
|
|
76
|
-
"data-state": $66e9ff9cece0fdb5$var$getProgressState(context.value, context.max),
|
|
77
|
-
"data-value": (_context$value = context.value) !== null && _context$value !== void 0 ? _context$value : undefined,
|
|
78
|
-
"data-max": context.max
|
|
79
|
-
}, indicatorProps, {
|
|
80
|
-
ref: forwardedRef
|
|
81
|
-
}));
|
|
82
|
-
});
|
|
83
|
-
/*#__PURE__*/ Object.assign($66e9ff9cece0fdb5$export$2b776f7e7ee60dbd, {
|
|
84
|
-
displayName: $66e9ff9cece0fdb5$var$INDICATOR_NAME
|
|
85
|
-
});
|
|
86
|
-
/* ---------------------------------------------------------------------------------------------- */ function $66e9ff9cece0fdb5$var$defaultGetValueLabel(value, max) {
|
|
106
|
+
);
|
|
107
|
+
ProgressIndicator.displayName = INDICATOR_NAME;
|
|
108
|
+
function defaultGetValueLabel(value, max) {
|
|
87
109
|
return `${Math.round(value / max * 100)}%`;
|
|
88
|
-
}
|
|
89
|
-
function
|
|
90
|
-
return value == null ?
|
|
91
|
-
}
|
|
92
|
-
function
|
|
93
|
-
return typeof value ===
|
|
94
|
-
}
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
function $66e9ff9cece0fdb5$var$getInvalidValueError(propValue, componentName) {
|
|
110
|
+
}
|
|
111
|
+
function getProgressState(value, maxValue) {
|
|
112
|
+
return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
|
|
113
|
+
}
|
|
114
|
+
function isNumber(value) {
|
|
115
|
+
return typeof value === "number";
|
|
116
|
+
}
|
|
117
|
+
function isValidMaxNumber(max) {
|
|
118
|
+
return isNumber(max) && !isNaN(max) && max > 0;
|
|
119
|
+
}
|
|
120
|
+
function isValidValueNumber(value, max) {
|
|
121
|
+
return isNumber(value) && !isNaN(value) && value <= max && value >= 0;
|
|
122
|
+
}
|
|
123
|
+
function getInvalidMaxError(propValue, componentName) {
|
|
124
|
+
return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${DEFAULT_MAX}\`.`;
|
|
125
|
+
}
|
|
126
|
+
function getInvalidValueError(propValue, componentName) {
|
|
107
127
|
return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
|
|
108
128
|
- a positive number
|
|
109
|
-
- less than the value passed to \`max\` (or ${
|
|
129
|
+
- less than the value passed to \`max\` (or ${DEFAULT_MAX} if no \`max\` prop is set)
|
|
110
130
|
- \`null\` if the progress is indeterminate.
|
|
111
131
|
|
|
112
132
|
Defaulting to \`null\`.`;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
}
|
|
134
|
+
var Root = Progress;
|
|
135
|
+
var Indicator = ProgressIndicator;
|
|
136
|
+
})();
|
|
120
137
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;A;;;;ACOA;;oGAEA,CAEA,MAAMQ,mCAAa,GAAG,UAAtB,AAAA;AACA,MAAMC,iCAAW,GAAG,GAApB,AAAA;AAGA,MAAM,CAACC,2CAAD,EAAwBV,yCAAxB,CAAA,GAA+CM,6CAAkB,CAACE,mCAAD,CAAvE,AAAA;AAIA,MAAM,CAACG,sCAAD,EAAmBC,wCAAnB,CAAA,GACJF,2CAAqB,CAAuBF,mCAAvB,CADvB,AAAA;AAWA,MAAMP,yCAAQ,GAAA,aAAGI,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AG,CAHR,CAAA;CAKD;AAED,SAASM,wCAAT,CAA4BR,KAA5B,EAAwCE,GAAxC,EAAsE;IACpE,kBAAA;IACA,OACEQ,8BAAQ,CAACV,KAAD,CAAR,IACA,CAAC4B,KAAK,CAAC5B,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,EAAwEvB,iCAAY,CAAA,GAAA,CAAzK,CAAA;CACD;AAED,SAAS6B,0CAAT,CAA8BL,SAA9B,EAAiDD,aAAjD,EAAwE;IACtE,OAAQ,CAAA,kCAAA,EAAoCC,SAAU,CAAA,iBAAA,EAAmBD,aAAc,CAAvF;;8CAEF,EAAgDvB,iCAAY,CAA5D;;;uBAGA,CALE,CAKF;CACC;AAED,MAAMN,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAS,GAAGF,yCAAlB,AAAA;;ADhKA","sources":["packages/react/progress/src/index.ts","packages/react/progress/src/Progress.tsx"],"sourcesContent":["export {\n createProgressScope,\n //\n Progress,\n ProgressIndicator,\n //\n Root,\n Indicator,\n} from './Progress';\nexport type { ProgressProps, ProgressIndicatorProps } 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":["createProgressScope","Progress","ProgressIndicator","Root","Indicator","React","createContextScope","Primitive","PROGRESS_NAME","DEFAULT_MAX","createProgressContext","ProgressProvider","useProgressContext","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","indicatorProps","context","Math","round","maxValue","isNaN"],"version":3,"file":"index.js.map"}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Progress.tsx"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AACvB,6BAAmC;AACnC,+BAA0B;AA4ClB;AAnCR,MAAM,gBAAgB;AACtB,MAAM,cAAc;AAGpB,MAAM,CAAC,uBAAuB,mBAAmB,QAAI,yCAAmB,aAAa;AAIrF,MAAM,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AAM,YAAY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,109 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {createContextScope
|
|
4
|
-
import {Primitive
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}, /*#__PURE__*/ $k03wI$createElement($k03wI$Primitive.div, $k03wI$babelruntimehelpersesmextends({
|
|
1
|
+
// packages/react/progress/src/Progress.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
4
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var PROGRESS_NAME = "Progress";
|
|
7
|
+
var DEFAULT_MAX = 100;
|
|
8
|
+
var [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);
|
|
9
|
+
var [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
|
|
10
|
+
var Progress = React.forwardRef(
|
|
11
|
+
(props, forwardedRef) => {
|
|
12
|
+
const {
|
|
13
|
+
__scopeProgress,
|
|
14
|
+
value: valueProp,
|
|
15
|
+
max: maxProp,
|
|
16
|
+
getValueLabel = defaultGetValueLabel,
|
|
17
|
+
...progressProps
|
|
18
|
+
} = props;
|
|
19
|
+
const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
|
|
20
|
+
const value = isValidValueNumber(valueProp, max) ? valueProp : null;
|
|
21
|
+
const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
|
|
22
|
+
return /* @__PURE__ */ jsx(ProgressProvider, { scope: __scopeProgress, value, max, children: /* @__PURE__ */ jsx(
|
|
23
|
+
Primitive.div,
|
|
24
|
+
{
|
|
26
25
|
"aria-valuemax": max,
|
|
27
26
|
"aria-valuemin": 0,
|
|
28
|
-
"aria-valuenow":
|
|
27
|
+
"aria-valuenow": isNumber(value) ? value : void 0,
|
|
29
28
|
"aria-valuetext": valueLabel,
|
|
30
29
|
role: "progressbar",
|
|
31
|
-
"data-state":
|
|
32
|
-
"data-value": value
|
|
33
|
-
"data-max": max
|
|
34
|
-
|
|
30
|
+
"data-state": getProgressState(value, max),
|
|
31
|
+
"data-value": value ?? void 0,
|
|
32
|
+
"data-max": max,
|
|
33
|
+
...progressProps,
|
|
35
34
|
ref: forwardedRef
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
}
|
|
36
|
+
) });
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
Progress.displayName = PROGRESS_NAME;
|
|
40
|
+
Progress.propTypes = {
|
|
41
|
+
max(props, propName, componentName) {
|
|
42
|
+
const propValue = props[propName];
|
|
43
|
+
const strVal = String(propValue);
|
|
44
|
+
if (propValue && !isValidMaxNumber(propValue)) {
|
|
45
|
+
return new Error(getInvalidMaxError(strVal, componentName));
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
},
|
|
49
|
+
value(props, propName, componentName) {
|
|
50
|
+
const valueProp = props[propName];
|
|
51
|
+
const strVal = String(valueProp);
|
|
52
|
+
const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;
|
|
53
|
+
if (valueProp != null && !isValidValueNumber(valueProp, max)) {
|
|
54
|
+
return new Error(getInvalidValueError(strVal, componentName));
|
|
54
55
|
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
55
58
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"data-state":
|
|
65
|
-
"data-value":
|
|
66
|
-
"data-max": context.max
|
|
67
|
-
|
|
59
|
+
var INDICATOR_NAME = "ProgressIndicator";
|
|
60
|
+
var ProgressIndicator = React.forwardRef(
|
|
61
|
+
(props, forwardedRef) => {
|
|
62
|
+
const { __scopeProgress, ...indicatorProps } = props;
|
|
63
|
+
const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
|
|
64
|
+
return /* @__PURE__ */ jsx(
|
|
65
|
+
Primitive.div,
|
|
66
|
+
{
|
|
67
|
+
"data-state": getProgressState(context.value, context.max),
|
|
68
|
+
"data-value": context.value ?? void 0,
|
|
69
|
+
"data-max": context.max,
|
|
70
|
+
...indicatorProps,
|
|
68
71
|
ref: forwardedRef
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
ProgressIndicator.displayName = INDICATOR_NAME;
|
|
77
|
+
function defaultGetValueLabel(value, max) {
|
|
78
|
+
return `${Math.round(value / max * 100)}%`;
|
|
76
79
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
80
|
+
function getProgressState(value, maxValue) {
|
|
81
|
+
return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
|
|
79
82
|
}
|
|
80
|
-
function
|
|
81
|
-
|
|
83
|
+
function isNumber(value) {
|
|
84
|
+
return typeof value === "number";
|
|
82
85
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
return $67824d98245208a0$var$isNumber(max) && !isNaN(max) && max > 0;
|
|
86
|
+
function isValidMaxNumber(max) {
|
|
87
|
+
return isNumber(max) && !isNaN(max) && max > 0;
|
|
86
88
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
return $67824d98245208a0$var$isNumber(value) && !isNaN(value) && value <= max && value >= 0;
|
|
90
|
-
} // Split this out for clearer readability of the error message.
|
|
91
|
-
function $67824d98245208a0$var$getInvalidMaxError(propValue, componentName) {
|
|
92
|
-
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}\`.`;
|
|
89
|
+
function isValidValueNumber(value, max) {
|
|
90
|
+
return isNumber(value) && !isNaN(value) && value <= max && value >= 0;
|
|
93
91
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
92
|
+
function getInvalidMaxError(propValue, componentName) {
|
|
93
|
+
return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${DEFAULT_MAX}\`.`;
|
|
94
|
+
}
|
|
95
|
+
function getInvalidValueError(propValue, componentName) {
|
|
96
|
+
return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
|
|
96
97
|
- a positive number
|
|
97
|
-
- less than the value passed to \`max\` (or ${
|
|
98
|
+
- less than the value passed to \`max\` (or ${DEFAULT_MAX} if no \`max\` prop is set)
|
|
98
99
|
- \`null\` if the progress is indeterminate.
|
|
99
100
|
|
|
100
101
|
Defaulting to \`null\`.`;
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
var Root = Progress;
|
|
104
|
+
var Indicator = ProgressIndicator;
|
|
105
|
+
export {
|
|
106
|
+
Indicator,
|
|
107
|
+
Progress,
|
|
108
|
+
ProgressIndicator,
|
|
109
|
+
Root,
|
|
110
|
+
createProgressScope
|
|
111
|
+
};
|
|
109
112
|
//# sourceMappingURL=index.mjs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BZ,KAA1B,EAA4D2B,QAA5D,EAA6F;IAC3F,OAAO3B,KAAK,IAAI,IAAT,GAAgB,eAAhB,GAAkCA,KAAK,KAAK2B,QAAV,GAAqB,UAArB,GAAkC,SAA3E,CAAA;CACD;AAED,SAASjB,8BAAT,CAAkBV,KAAlB,EAA+C;IAC7C,OAAO,OAAOA,KAAP,KAAiB,QAAxB,CAAA;CACD;AAED,SAASO,sCAAT,CAA0BL,GAA1B,EAAmD;IACjD,kBAAA;IACA,OACEQ,8BAAQ,CAACR,GAAD,CAAR,IACA,CAAC0B,KAAK,CAAC1B,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,CAAC4B,KAAK,CAAC5B,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,EAAwEvB,iCAAY,CAAA,GAAA,CAAzK,CAAA;CACD;AAED,SAAS6B,0CAAT,CAA8BL,SAA9B,EAAiDD,aAAjD,EAAwE;IACtE,OAAQ,CAAA,kCAAA,EAAoCC,SAAU,CAAA,iBAAA,EAAmBD,aAAc,CAAvF;;8CAEF,EAAgDvB,iCAAY,CAA5D;;;uBAGA,CALE,CAKF;CACC;AAED,MAAMN,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAS,GAAGF,yCAAlB,AAAA;;ADhKA","sources":["packages/react/progress/src/index.ts","packages/react/progress/src/Progress.tsx"],"sourcesContent":["export {\n createProgressScope,\n //\n Progress,\n ProgressIndicator,\n //\n Root,\n Indicator,\n} from './Progress';\nexport type { ProgressProps, ProgressIndicatorProps } 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":["createProgressScope","Progress","ProgressIndicator","Root","Indicator","React","createContextScope","Primitive","PROGRESS_NAME","DEFAULT_MAX","createProgressContext","ProgressProvider","useProgressContext","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","indicatorProps","context","Math","round","maxValue","isNaN"],"version":3,"file":"index.mjs.map"}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/Progress.tsx"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";AAAA,YAAY,WAAW;AACvB,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AA4ClB;AAnCR,IAAM,gBAAgB;AACtB,IAAM,cAAc;AAGpB,IAAM,CAAC,uBAAuB,mBAAmB,IAAI,mBAAmB,aAAa;AAIrF,IAAM,CAAC,kBAAkB,kBAAkB,IACzC,sBAA4C,aAAa;AAU3D,IAAM,WAAiB;AAAA,EACrB,CAAC,OAAmC,iBAAiB;AACnD,UAAM;AAAA,MACJ;AAAA,MACA,OAAO;AAAA,MACP,KAAK;AAAA,MACL,gBAAgB;AAAA,MAChB,GAAG;AAAA,IACL,IAAI;AAEJ,UAAM,MAAM,iBAAiB,OAAO,IAAI,UAAU;AAClD,UAAM,QAAQ,mBAAmB,WAAW,GAAG,IAAI,YAAY;AAC/D,UAAM,aAAa,SAAS,KAAK,IAAI,cAAc,OAAO,GAAG,IAAI;AAEjE,WACE,oBAAC,oBAAiB,OAAO,iBAAiB,OAAc,KACtD;AAAA,MAAC,UAAU;AAAA,MAAV;AAAA,QACC,iBAAe;AAAA,QACf,iBAAe;AAAA,QACf,iBAAe,SAAS,KAAK,IAAI,QAAQ;AAAA,QACzC,kBAAgB;AAAA,QAChB,MAAK;AAAA,QACL,cAAY,iBAAiB,OAAO,GAAG;AAAA,QACvC,cAAY,SAAS;AAAA,QACrB,YAAU;AAAA,QACT,GAAG;AAAA,QACJ,KAAK;AAAA;AAAA,IACP,GACF;AAAA,EAEJ;AACF;AAEA,SAAS,cAAc;AAEvB,SAAS,YAAY;AAAA,EACnB,IAAI,OAAO,UAAU,eAAe;AAClC,UAAM,YAAY,MAAM,QAAQ;AAChC,UAAM,SAAS,OAAO,SAAS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SAAS,KAAK,KACd,CAAC,MAAM,KAAK,KACZ,SAAS,OACT,SAAS;AAEb;AAGA,SAAS,mBAAmB,WAAmB,eAAuB;AACpE,SAAO,mCAAmC,SAAS,oBAAoB,aAAa,yEAAyE,WAAW;AAC1K;AAEA,SAAS,qBAAqB,WAAmB,eAAuB;AACtE,SAAO,qCAAqC,SAAS,oBAAoB,aAAa;AAAA;AAAA,gDAExC,WAAW;AAAA;AAAA;AAAA;AAI3D;AAEA,IAAM,OAAO;AACb,IAAM,YAAY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-progress",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-rc.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -28,9 +28,8 @@
|
|
|
28
28
|
"version": "yarn version"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@radix-ui/react-
|
|
33
|
-
"@radix-ui/react-primitive": "1.0.3"
|
|
31
|
+
"@radix-ui/react-context": "1.1.0-rc.1",
|
|
32
|
+
"@radix-ui/react-primitive": "1.1.0-rc.1"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"@types/react": "*",
|
|
@@ -53,5 +52,6 @@
|
|
|
53
52
|
},
|
|
54
53
|
"bugs": {
|
|
55
54
|
"url": "https://github.com/radix-ui/primitives/issues"
|
|
56
|
-
}
|
|
55
|
+
},
|
|
56
|
+
"stableVersion": "1.0.3"
|
|
57
57
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 {\n createProgressScope,\n //\n Progress,\n ProgressIndicator,\n //\n Root,\n Indicator,\n} from './Progress';\nexport type { ProgressProps, ProgressIndicatorProps } from './Progress';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|