@radix-ui/react-progress 0.0.0-20250116175529

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # `react-progress`
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ yarn add @radix-ui/react-progress
7
+ # or
8
+ $ npm install @radix-ui/react-progress
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ View docs [here](https://radix-ui.com/primitives/docs/components/progress).
@@ -0,0 +1,19 @@
1
+ import * as _radix_ui_react_context from '@radix-ui/react-context';
2
+ import * as React from 'react';
3
+ import { Primitive } from '@radix-ui/react-primitive';
4
+
5
+ declare const createProgressScope: _radix_ui_react_context.CreateScope;
6
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
7
+ interface ProgressProps extends PrimitiveDivProps {
8
+ value?: number | null | undefined;
9
+ max?: number;
10
+ getValueLabel?(value: number, max: number): string;
11
+ }
12
+ declare const Progress: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
13
+ interface ProgressIndicatorProps extends PrimitiveDivProps {
14
+ }
15
+ declare const ProgressIndicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
16
+ declare const Root: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
17
+ declare const Indicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
18
+
19
+ export { Indicator, Progress, ProgressIndicator, type ProgressIndicatorProps, type ProgressProps, Root, createProgressScope };
@@ -0,0 +1,19 @@
1
+ import * as _radix_ui_react_context from '@radix-ui/react-context';
2
+ import * as React from 'react';
3
+ import { Primitive } from '@radix-ui/react-primitive';
4
+
5
+ declare const createProgressScope: _radix_ui_react_context.CreateScope;
6
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
7
+ interface ProgressProps extends PrimitiveDivProps {
8
+ value?: number | null | undefined;
9
+ max?: number;
10
+ getValueLabel?(value: number, max: number): string;
11
+ }
12
+ declare const Progress: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
13
+ interface ProgressIndicatorProps extends PrimitiveDivProps {
14
+ }
15
+ declare const ProgressIndicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
16
+ declare const Root: React.ForwardRefExoticComponent<ProgressProps & React.RefAttributes<HTMLDivElement>>;
17
+ declare const Indicator: React.ForwardRefExoticComponent<ProgressIndicatorProps & React.RefAttributes<HTMLDivElement>>;
18
+
19
+ export { Indicator, Progress, ProgressIndicator, type ProgressIndicatorProps, type ProgressProps, Root, createProgressScope };
package/dist/index.js ADDED
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ "use client";
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 __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // packages/react/progress/src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ Indicator: () => Indicator,
35
+ Progress: () => Progress,
36
+ ProgressIndicator: () => ProgressIndicator,
37
+ Root: () => Root,
38
+ createProgressScope: () => createProgressScope
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
41
+
42
+ // packages/react/progress/src/Progress.tsx
43
+ var React = __toESM(require("react"));
44
+ var import_react_context = require("@radix-ui/react-context");
45
+ var import_react_primitive = require("@radix-ui/react-primitive");
46
+ var import_jsx_runtime = require("react/jsx-runtime");
47
+ var PROGRESS_NAME = "Progress";
48
+ var DEFAULT_MAX = 100;
49
+ var [createProgressContext, createProgressScope] = (0, import_react_context.createContextScope)(PROGRESS_NAME);
50
+ var [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
51
+ var Progress = React.forwardRef(
52
+ (props, forwardedRef) => {
53
+ const {
54
+ __scopeProgress,
55
+ value: valueProp = null,
56
+ max: maxProp,
57
+ getValueLabel = defaultGetValueLabel,
58
+ ...progressProps
59
+ } = props;
60
+ if ((maxProp || maxProp === 0) && !isValidMaxNumber(maxProp)) {
61
+ console.error(getInvalidMaxError(`${maxProp}`, "Progress"));
62
+ }
63
+ const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
64
+ if (valueProp !== null && !isValidValueNumber(valueProp, max)) {
65
+ console.error(getInvalidValueError(`${valueProp}`, "Progress"));
66
+ }
67
+ const value = isValidValueNumber(valueProp, max) ? valueProp : null;
68
+ const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
69
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressProvider, { scope: __scopeProgress, value, max, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
70
+ import_react_primitive.Primitive.div,
71
+ {
72
+ "aria-valuemax": max,
73
+ "aria-valuemin": 0,
74
+ "aria-valuenow": isNumber(value) ? value : void 0,
75
+ "aria-valuetext": valueLabel,
76
+ role: "progressbar",
77
+ "data-state": getProgressState(value, max),
78
+ "data-value": value ?? void 0,
79
+ "data-max": max,
80
+ ...progressProps,
81
+ ref: forwardedRef
82
+ }
83
+ ) });
84
+ }
85
+ );
86
+ Progress.displayName = PROGRESS_NAME;
87
+ var INDICATOR_NAME = "ProgressIndicator";
88
+ var ProgressIndicator = React.forwardRef(
89
+ (props, forwardedRef) => {
90
+ const { __scopeProgress, ...indicatorProps } = props;
91
+ const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
92
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
93
+ import_react_primitive.Primitive.div,
94
+ {
95
+ "data-state": getProgressState(context.value, context.max),
96
+ "data-value": context.value ?? void 0,
97
+ "data-max": context.max,
98
+ ...indicatorProps,
99
+ ref: forwardedRef
100
+ }
101
+ );
102
+ }
103
+ );
104
+ ProgressIndicator.displayName = INDICATOR_NAME;
105
+ function defaultGetValueLabel(value, max) {
106
+ return `${Math.round(value / max * 100)}%`;
107
+ }
108
+ function getProgressState(value, maxValue) {
109
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
110
+ }
111
+ function isNumber(value) {
112
+ return typeof value === "number";
113
+ }
114
+ function isValidMaxNumber(max) {
115
+ return isNumber(max) && !isNaN(max) && max > 0;
116
+ }
117
+ function isValidValueNumber(value, max) {
118
+ return isNumber(value) && !isNaN(value) && value <= max && value >= 0;
119
+ }
120
+ function 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 \`${DEFAULT_MAX}\`.`;
122
+ }
123
+ function 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 ${DEFAULT_MAX} if no \`max\` prop is set)
127
+ - \`null\` or \`undefined\` if the progress is indeterminate.
128
+
129
+ Defaulting to \`null\`.`;
130
+ }
131
+ var Root = Progress;
132
+ var Indicator = ProgressIndicator;
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/Progress.tsx"],
4
+ "sourcesContent": ["'use client';\nexport {\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 { 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 = React.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 = null,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n ...progressProps\n } = props;\n\n if ((maxProp || maxProp === 0) && !isValidMaxNumber(maxProp)) {\n console.error(getInvalidMaxError(`${maxProp}`, 'Progress'));\n }\n\n const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;\n\n if (valueProp !== null && !isValidValueNumber(valueProp, max)) {\n console.error(getInvalidValueError(`${valueProp}`, 'Progress'));\n }\n\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\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\\` or \\`undefined\\` 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,2BAAmC;AACnC,6BAA0B;AAoDlB;AA5CR,IAAM,gBAAgB;AACtB,IAAM,cAAc;AAGpB,IAAM,CAAC,uBAAuB,mBAAmB,QAAI,yCAAmB,aAAa;AAIrF,IAAM,CAAC,kBAAkB,kBAAkB,IACzC,sBAA4C,aAAa;AAU3D,IAAM,WAAiB;AAAA,EACrB,CAAC,OAAmC,iBAAiB;AACnD,UAAM;AAAA,MACJ;AAAA,MACA,OAAO,YAAY;AAAA,MACnB,KAAK;AAAA,MACL,gBAAgB;AAAA,MAChB,GAAG;AAAA,IACL,IAAI;AAEJ,SAAK,WAAW,YAAY,MAAM,CAAC,i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,MAAO,GAAG,CAAC;AAC3C;AAEA,SAAS,iBAAiB,OAAkC,UAAiC;AAC3F,SAAO,SAAS,OAAO,kBAAkB,UAAU,WAAW,aAAa;AAC7E;AAEA,SAAS,SAAS,OAA6B;AAC7C,SAAO,OAAO,UAAU;AAC1B;AAEA,SAAS,iBAAiB,KAAyB;AAEjD,SACE,SAAS,GAAG,KACZ,CAAC,MAAM,GAAG,KACV,MAAM;AAEV;AAEA,SAAS,mBAAmB,OAAY,KAA8B;AAEpE,SACE,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/dist/index.mjs ADDED
@@ -0,0 +1,101 @@
1
+ "use client";
2
+
3
+ // packages/react/progress/src/Progress.tsx
4
+ import * as React from "react";
5
+ import { createContextScope } from "@radix-ui/react-context";
6
+ import { Primitive } from "@radix-ui/react-primitive";
7
+ import { jsx } from "react/jsx-runtime";
8
+ var PROGRESS_NAME = "Progress";
9
+ var DEFAULT_MAX = 100;
10
+ var [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);
11
+ var [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
12
+ var Progress = React.forwardRef(
13
+ (props, forwardedRef) => {
14
+ const {
15
+ __scopeProgress,
16
+ value: valueProp = null,
17
+ max: maxProp,
18
+ getValueLabel = defaultGetValueLabel,
19
+ ...progressProps
20
+ } = props;
21
+ if ((maxProp || maxProp === 0) && !isValidMaxNumber(maxProp)) {
22
+ console.error(getInvalidMaxError(`${maxProp}`, "Progress"));
23
+ }
24
+ const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
25
+ if (valueProp !== null && !isValidValueNumber(valueProp, max)) {
26
+ console.error(getInvalidValueError(`${valueProp}`, "Progress"));
27
+ }
28
+ const value = isValidValueNumber(valueProp, max) ? valueProp : null;
29
+ const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
30
+ return /* @__PURE__ */ jsx(ProgressProvider, { scope: __scopeProgress, value, max, children: /* @__PURE__ */ jsx(
31
+ Primitive.div,
32
+ {
33
+ "aria-valuemax": max,
34
+ "aria-valuemin": 0,
35
+ "aria-valuenow": isNumber(value) ? value : void 0,
36
+ "aria-valuetext": valueLabel,
37
+ role: "progressbar",
38
+ "data-state": getProgressState(value, max),
39
+ "data-value": value ?? void 0,
40
+ "data-max": max,
41
+ ...progressProps,
42
+ ref: forwardedRef
43
+ }
44
+ ) });
45
+ }
46
+ );
47
+ Progress.displayName = PROGRESS_NAME;
48
+ var INDICATOR_NAME = "ProgressIndicator";
49
+ var ProgressIndicator = React.forwardRef(
50
+ (props, forwardedRef) => {
51
+ const { __scopeProgress, ...indicatorProps } = props;
52
+ const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
53
+ return /* @__PURE__ */ jsx(
54
+ Primitive.div,
55
+ {
56
+ "data-state": getProgressState(context.value, context.max),
57
+ "data-value": context.value ?? void 0,
58
+ "data-max": context.max,
59
+ ...indicatorProps,
60
+ ref: forwardedRef
61
+ }
62
+ );
63
+ }
64
+ );
65
+ ProgressIndicator.displayName = INDICATOR_NAME;
66
+ function defaultGetValueLabel(value, max) {
67
+ return `${Math.round(value / max * 100)}%`;
68
+ }
69
+ function getProgressState(value, maxValue) {
70
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
71
+ }
72
+ function isNumber(value) {
73
+ return typeof value === "number";
74
+ }
75
+ function isValidMaxNumber(max) {
76
+ return isNumber(max) && !isNaN(max) && max > 0;
77
+ }
78
+ function isValidValueNumber(value, max) {
79
+ return isNumber(value) && !isNaN(value) && value <= max && value >= 0;
80
+ }
81
+ function getInvalidMaxError(propValue, componentName) {
82
+ return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${DEFAULT_MAX}\`.`;
83
+ }
84
+ function getInvalidValueError(propValue, componentName) {
85
+ return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
86
+ - a positive number
87
+ - less than the value passed to \`max\` (or ${DEFAULT_MAX} if no \`max\` prop is set)
88
+ - \`null\` or \`undefined\` if the progress is indeterminate.
89
+
90
+ Defaulting to \`null\`.`;
91
+ }
92
+ var Root = Progress;
93
+ var Indicator = ProgressIndicator;
94
+ export {
95
+ Indicator,
96
+ Progress,
97
+ ProgressIndicator,
98
+ Root,
99
+ createProgressScope
100
+ };
101
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
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 { 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 = React.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 = null,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n ...progressProps\n } = props;\n\n if ((maxProp || maxProp === 0) && !isValidMaxNumber(maxProp)) {\n console.error(getInvalidMaxError(`${maxProp}`, 'Progress'));\n }\n\n const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;\n\n if (valueProp !== null && !isValidValueNumber(valueProp, max)) {\n console.error(getInvalidValueError(`${valueProp}`, 'Progress'));\n }\n\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\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\\` or \\`undefined\\` 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;AAoDlB;AA5CR,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,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;AAAA,QACjB,GAAG;AAAA,QACJ,KAAK;AAAA;AAAA,IACP;AAAA,EAEJ;AACF;AAEA,kBAAkB,cAAc;AAIhC,SAAS,qBAAqB,OAAe,KAAa;AACxD,SAAO,GAAG,KAAK,MAAO,QAAQ,MAAO,GAAG,CAAC;AAC3C;AAEA,SAAS,iBAAiB,OAAkC,UAAiC;AAC3F,SAAO,SAAS,OAAO,kBAAkB,UAAU,WAAW,aAAa;AAC7E;AAEA,SAAS,SAAS,OAA6B;AAC7C,SAAO,OAAO,UAAU;AAC1B;AAEA,SAAS,iBAAiB,KAAyB;AAEjD,SACE,SAAS,GAAG,KACZ,CAAC,MAAM,GAAG,KACV,MAAM;AAEV;AAEA,SAAS,mBAAmB,OAAY,KAA8B;AAEpE,SACE,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 ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@radix-ui/react-progress",
3
+ "version": "0.0.0-20250116175529",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": {
7
+ "import": {
8
+ "types": "./dist/index.d.mts",
9
+ "default": "./dist/index.mjs"
10
+ },
11
+ "require": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ }
16
+ },
17
+ "source": "./src/index.ts",
18
+ "main": "./dist/index.js",
19
+ "module": "./dist/index.mjs",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "sideEffects": false,
26
+ "scripts": {
27
+ "clean": "rm -rf dist"
28
+ },
29
+ "dependencies": {
30
+ "@radix-ui/react-context": "workspace:*",
31
+ "@radix-ui/react-primitive": "workspace:*"
32
+ },
33
+ "peerDependencies": {
34
+ "@types/react": "*",
35
+ "@types/react-dom": "*",
36
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
37
+ "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "@types/react": {
41
+ "optional": true
42
+ },
43
+ "@types/react-dom": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "homepage": "https://radix-ui.com/primitives",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/radix-ui/primitives.git"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/radix-ui/primitives/issues"
54
+ }
55
+ }