@tamagui/progress 2.7.7 → 3.0.0-beta.643.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/cjs/Progress.cjs +92 -139
- package/dist/cjs/Progress.native.cjs +136 -0
- package/dist/cjs/Progress.native.js +96 -143
- package/dist/cjs/Progress.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Progress.mjs +77 -121
- package/dist/esm/Progress.mjs.map +1 -1
- package/dist/esm/Progress.native.js +81 -126
- package/dist/esm/Progress.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/jsx/Progress.mjs +77 -121
- package/dist/jsx/Progress.mjs.map +1 -1
- package/dist/jsx/Progress.native.cjs +136 -0
- package/dist/jsx/Progress.native.js +96 -143
- package/dist/jsx/Progress.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +9 -9
- package/src/Progress.tsx +53 -78
- package/types/Progress.d.ts +82 -52
- package/types/Progress.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
package/dist/jsx/Progress.mjs
CHANGED
|
@@ -1,149 +1,105 @@
|
|
|
1
|
-
import { getVariableValue, isWeb, styled } from "@tamagui/core";
|
|
1
|
+
import { createStyledHOC, getVariableValue, isWeb, styled } from "@tamagui/core";
|
|
2
2
|
import { createContextScope } from "@tamagui/create-context";
|
|
3
3
|
import { getSize } from "@tamagui/get-token";
|
|
4
4
|
import { withStaticProperties } from "@tamagui/helpers";
|
|
5
5
|
import { YStack } from "@tamagui/stacks";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
|
|
8
9
|
const PROGRESS_NAME = "Progress";
|
|
9
10
|
const [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);
|
|
10
11
|
const [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
|
|
11
12
|
const INDICATOR_NAME = "ProgressIndicator";
|
|
12
13
|
const ProgressIndicatorFrame = styled(YStack, {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
false: {
|
|
17
|
-
height: "100%",
|
|
18
|
-
width: "100%",
|
|
19
|
-
backgroundColor: "$background"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
defaultVariants: {
|
|
24
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
25
|
-
}
|
|
14
|
+
displayName: INDICATOR_NAME,
|
|
15
|
+
height: "100%",
|
|
16
|
+
width: "100%"
|
|
26
17
|
});
|
|
27
|
-
const ProgressIndicator = ProgressIndicatorFrame
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// on native, hide until we have width measurement
|
|
51
|
-
...(!isWeb && context.width === 0 && {
|
|
52
|
-
opacity: 0
|
|
53
|
-
})
|
|
54
|
-
}),
|
|
55
|
-
...indicatorProps,
|
|
56
|
-
ref: forwardedRef,
|
|
57
|
-
transition: !isWeb && !context.width ? null : transition
|
|
58
|
-
});
|
|
18
|
+
const ProgressIndicator = createStyledHOC(ProgressIndicatorFrame, function ProgressIndicator2(props, forwardedRef) {
|
|
19
|
+
const { __scopeProgress, transition, ...indicatorProps } = props;
|
|
20
|
+
const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
|
|
21
|
+
const progressRatio = (context.value ?? 0) / context.max;
|
|
22
|
+
let x;
|
|
23
|
+
if (isWeb) {
|
|
24
|
+
x = `${-100 + progressRatio * 50}%`;
|
|
25
|
+
} else {
|
|
26
|
+
const baseWidth = context.width || 0;
|
|
27
|
+
x = Math.ceil(-baseWidth * (2 - progressRatio));
|
|
28
|
+
}
|
|
29
|
+
return /* @__PURE__ */ jsx(ProgressIndicatorFrame, {
|
|
30
|
+
"data-state": getProgressState(context.value, context.max),
|
|
31
|
+
"data-value": context.value ?? void 0,
|
|
32
|
+
"data-max": context.max,
|
|
33
|
+
x,
|
|
34
|
+
width: "200%",
|
|
35
|
+
animateOnly: ["transform"],
|
|
36
|
+
...!isWeb && context.width === 0 && { opacity: 0 },
|
|
37
|
+
...indicatorProps,
|
|
38
|
+
ref: forwardedRef,
|
|
39
|
+
transition: !isWeb && !context.width ? null : transition
|
|
40
|
+
});
|
|
59
41
|
});
|
|
60
42
|
function defaultGetValueLabel(value, max) {
|
|
61
|
-
|
|
43
|
+
return `${Math.round(value / max * 100)}%`;
|
|
62
44
|
}
|
|
63
45
|
function getProgressState(value, maxValue) {
|
|
64
|
-
|
|
46
|
+
return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
|
|
65
47
|
}
|
|
66
48
|
function isNumber(value) {
|
|
67
|
-
|
|
49
|
+
return typeof value === "number";
|
|
68
50
|
}
|
|
69
51
|
function isValidMaxNumber(max) {
|
|
70
|
-
|
|
52
|
+
return isNumber(max) && !Number.isNaN(max) && max > 0;
|
|
71
53
|
}
|
|
72
54
|
function isValidValueNumber(value, max) {
|
|
73
|
-
|
|
55
|
+
return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;
|
|
74
56
|
}
|
|
75
57
|
const DEFAULT_MAX = 100;
|
|
76
58
|
const ProgressFrame = styled(YStack, {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"...size": val => {
|
|
88
|
-
const size = Math.round(getVariableValue(getSize(val)) * 0.25);
|
|
89
|
-
return {
|
|
90
|
-
height: size,
|
|
91
|
-
minWidth: getVariableValue(size) * 20,
|
|
92
|
-
width: "100%"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
defaultVariants: {
|
|
98
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
const Progress = withStaticProperties(ProgressFrame.styleable(function Progress2(props, forwardedRef) {
|
|
102
|
-
const {
|
|
103
|
-
// @ts-expect-error
|
|
104
|
-
__scopeProgress,
|
|
105
|
-
value: valueProp,
|
|
106
|
-
max: maxProp,
|
|
107
|
-
getValueLabel = defaultGetValueLabel,
|
|
108
|
-
size = "$true",
|
|
109
|
-
...progressProps
|
|
110
|
-
} = props;
|
|
111
|
-
const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
|
|
112
|
-
const value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null;
|
|
113
|
-
const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
|
|
114
|
-
const [width, setWidth] = useState(0);
|
|
115
|
-
return /* @__PURE__ */jsx(ProgressProvider, {
|
|
116
|
-
scope: __scopeProgress,
|
|
117
|
-
value,
|
|
118
|
-
max,
|
|
119
|
-
width,
|
|
120
|
-
children: /* @__PURE__ */jsx(ProgressFrame, {
|
|
121
|
-
"aria-valuemax": max,
|
|
122
|
-
"aria-valuemin": 0,
|
|
123
|
-
"aria-valuenow": isNumber(value) ? value : void 0,
|
|
124
|
-
"aria-valuetext": valueLabel,
|
|
125
|
-
role: "progressbar",
|
|
126
|
-
"data-state": getProgressState(value, max),
|
|
127
|
-
"data-value": value ?? void 0,
|
|
128
|
-
"data-max": max,
|
|
129
|
-
...(progressProps.unstyled !== true && {
|
|
130
|
-
size
|
|
131
|
-
}),
|
|
132
|
-
...progressProps,
|
|
133
|
-
...(!isWeb && {
|
|
134
|
-
onLayout: e => {
|
|
135
|
-
const newWidth = Math.round(e.nativeEvent.layout.width);
|
|
136
|
-
if (newWidth !== width) {
|
|
137
|
-
setWidth(newWidth);
|
|
138
|
-
}
|
|
139
|
-
progressProps.onLayout?.(e);
|
|
140
|
-
}
|
|
141
|
-
}),
|
|
142
|
-
ref: forwardedRef
|
|
143
|
-
})
|
|
144
|
-
});
|
|
145
|
-
}), {
|
|
146
|
-
Indicator: ProgressIndicator
|
|
59
|
+
displayName: "Progress",
|
|
60
|
+
overflow: "hidden",
|
|
61
|
+
variants: { size: { Size: (val) => {
|
|
62
|
+
const size = Math.round(getVariableValue(getSize(val)) * .25);
|
|
63
|
+
return {
|
|
64
|
+
height: size,
|
|
65
|
+
minWidth: getVariableValue(size) * 20,
|
|
66
|
+
width: "100%"
|
|
67
|
+
};
|
|
68
|
+
} } }
|
|
147
69
|
});
|
|
70
|
+
const Progress = withStaticProperties(createStyledHOC(ProgressFrame, function Progress2(props, forwardedRef) {
|
|
71
|
+
const { __scopeProgress, value: valueProp, max: maxProp, getValueLabel = defaultGetValueLabel, size = true, ...progressProps } = props;
|
|
72
|
+
const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
|
|
73
|
+
const value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null;
|
|
74
|
+
const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
|
|
75
|
+
const [width, setWidth] = useState(0);
|
|
76
|
+
return /* @__PURE__ */ jsx(ProgressProvider, {
|
|
77
|
+
scope: __scopeProgress,
|
|
78
|
+
value,
|
|
79
|
+
max,
|
|
80
|
+
width,
|
|
81
|
+
children: /* @__PURE__ */ jsx(ProgressFrame, {
|
|
82
|
+
"aria-valuemax": max,
|
|
83
|
+
"aria-valuemin": 0,
|
|
84
|
+
"aria-valuenow": isNumber(value) ? value : void 0,
|
|
85
|
+
"aria-valuetext": valueLabel,
|
|
86
|
+
role: "progressbar",
|
|
87
|
+
"data-state": getProgressState(value, max),
|
|
88
|
+
"data-value": value ?? void 0,
|
|
89
|
+
"data-max": max,
|
|
90
|
+
size,
|
|
91
|
+
...progressProps,
|
|
92
|
+
...!isWeb && { onLayout: (e) => {
|
|
93
|
+
const newWidth = Math.round(e.nativeEvent.layout.width);
|
|
94
|
+
if (newWidth !== width) {
|
|
95
|
+
setWidth(newWidth);
|
|
96
|
+
}
|
|
97
|
+
progressProps.onLayout?.(e);
|
|
98
|
+
} },
|
|
99
|
+
ref: forwardedRef
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
}), { Indicator: ProgressIndicator });
|
|
103
|
+
|
|
148
104
|
export { Progress, ProgressFrame, ProgressIndicator, ProgressIndicatorFrame, createProgressScope };
|
|
149
105
|
//# sourceMappingURL=Progress.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"Progress.js","names":[],"sources":["jsx/Progress.js"],"sourcesContent":["import { createStyledHOC, getVariableValue, isWeb, styled } from \"@tamagui/core\";\nimport { createContextScope } from \"@tamagui/create-context\";\nimport { getSize } from \"@tamagui/get-token\";\nimport { withStaticProperties } from \"@tamagui/helpers\";\nimport { YStack } from \"@tamagui/stacks\";\nimport { useState } from \"react\";\nimport { jsx } from \"react/jsx-runtime\";\nconst PROGRESS_NAME = \"Progress\";\nconst [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);\nconst [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);\nconst INDICATOR_NAME = \"ProgressIndicator\";\nconst ProgressIndicatorFrame = styled(YStack, {\n displayName: INDICATOR_NAME,\n height: \"100%\",\n width: \"100%\"\n});\nconst ProgressIndicator = createStyledHOC(\n ProgressIndicatorFrame,\n function ProgressIndicator2(props, forwardedRef) {\n const { __scopeProgress, transition, ...indicatorProps } = props;\n const context = useProgressContext(INDICATOR_NAME, __scopeProgress);\n const progressRatio = (context.value ?? 0) / context.max;\n let x;\n if (isWeb) {\n x = `${-100 + progressRatio * 50}%`;\n } else {\n const baseWidth = context.width || 0;\n x = Math.ceil(-baseWidth * (2 - progressRatio));\n }\n return /* @__PURE__ */ jsx(\n ProgressIndicatorFrame,\n {\n \"data-state\": getProgressState(context.value, context.max),\n \"data-value\": context.value ?? void 0,\n \"data-max\": context.max,\n x,\n width: \"200%\",\n animateOnly: [\"transform\"],\n ...!isWeb && context.width === 0 && { opacity: 0 },\n ...indicatorProps,\n ref: forwardedRef,\n transition: !isWeb && !context.width ? null : transition\n }\n );\n }\n);\nfunction defaultGetValueLabel(value, max) {\n return `${Math.round(value / max * 100)}%`;\n}\nfunction getProgressState(value, maxValue) {\n return value == null ? \"indeterminate\" : value === maxValue ? \"complete\" : \"loading\";\n}\nfunction isNumber(value) {\n return typeof value === \"number\";\n}\nfunction isValidMaxNumber(max) {\n return isNumber(max) && !Number.isNaN(max) && max > 0;\n}\nfunction isValidValueNumber(value, max) {\n return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;\n}\nconst DEFAULT_MAX = 100;\nconst ProgressFrame = styled(YStack, {\n displayName: \"Progress\",\n overflow: \"hidden\",\n variants: {\n size: {\n Size: (val) => {\n const size = Math.round(getVariableValue(getSize(val)) * 0.25);\n return {\n height: size,\n minWidth: getVariableValue(size) * 20,\n width: \"100%\"\n };\n }\n }\n }\n});\nconst Progress = withStaticProperties(\n createStyledHOC(ProgressFrame, function Progress2(props, forwardedRef) {\n const {\n // @ts-expect-error\n __scopeProgress,\n value: valueProp,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n size = true,\n ...progressProps\n } = props;\n const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;\n const value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null;\n const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;\n const [width, setWidth] = useState(0);\n return /* @__PURE__ */ jsx(ProgressProvider, { scope: __scopeProgress, value, max, width, children: /* @__PURE__ */ jsx(\n ProgressFrame,\n {\n \"aria-valuemax\": max,\n \"aria-valuemin\": 0,\n \"aria-valuenow\": isNumber(value) ? value : void 0,\n \"aria-valuetext\": valueLabel,\n role: \"progressbar\",\n \"data-state\": getProgressState(value, max),\n \"data-value\": value ?? void 0,\n \"data-max\": max,\n size,\n ...progressProps,\n ...!isWeb && {\n onLayout: (e) => {\n const newWidth = Math.round(e.nativeEvent.layout.width);\n if (newWidth !== width) {\n setWidth(newWidth);\n }\n progressProps.onLayout?.(e);\n }\n },\n ref: forwardedRef\n }\n ) });\n }),\n {\n Indicator: ProgressIndicator\n }\n);\nexport {\n Progress,\n ProgressFrame,\n ProgressIndicator,\n ProgressIndicatorFrame,\n createProgressScope\n};\n//# sourceMappingURL=Progress.js.map\n"],"mappings":"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"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var Progress_exports = {};
|
|
25
|
+
__export(Progress_exports, {
|
|
26
|
+
Progress: () => Progress,
|
|
27
|
+
ProgressFrame: () => ProgressFrame,
|
|
28
|
+
ProgressIndicator: () => ProgressIndicator,
|
|
29
|
+
ProgressIndicatorFrame: () => ProgressIndicatorFrame,
|
|
30
|
+
createProgressScope: () => createProgressScope
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Progress_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_core = require("@tamagui/core");
|
|
35
|
+
var import_create_context = require("@tamagui/create-context");
|
|
36
|
+
var import_get_token = require("@tamagui/get-token");
|
|
37
|
+
var import_helpers = require("@tamagui/helpers");
|
|
38
|
+
var import_stacks = require("@tamagui/stacks");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var PROGRESS_NAME = "Progress";
|
|
41
|
+
var [createProgressContext, createProgressScope] = (0, import_create_context.createContextScope)(PROGRESS_NAME);
|
|
42
|
+
var [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
|
|
43
|
+
var INDICATOR_NAME = "ProgressIndicator";
|
|
44
|
+
var ProgressIndicatorFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
45
|
+
displayName: INDICATOR_NAME,
|
|
46
|
+
height: "100%",
|
|
47
|
+
width: "100%"
|
|
48
|
+
});
|
|
49
|
+
var ProgressIndicator = (0, import_core.createStyledHOC)(ProgressIndicatorFrame, function ProgressIndicator2(props, forwardedRef) {
|
|
50
|
+
var { __scopeProgress, transition, ...indicatorProps } = props;
|
|
51
|
+
var context = useProgressContext(INDICATOR_NAME, __scopeProgress);
|
|
52
|
+
var _context_value;
|
|
53
|
+
var progressRatio = ((_context_value = context.value) !== null && _context_value !== void 0 ? _context_value : 0) / context.max;
|
|
54
|
+
var x;
|
|
55
|
+
if (import_core.isWeb) {
|
|
56
|
+
x = `${-100 + progressRatio * 50}%`;
|
|
57
|
+
} else {
|
|
58
|
+
var baseWidth = context.width || 0;
|
|
59
|
+
x = Math.ceil(-baseWidth * (2 - progressRatio));
|
|
60
|
+
}
|
|
61
|
+
var _context_value1;
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressIndicatorFrame, {
|
|
63
|
+
"data-state": getProgressState(context.value, context.max),
|
|
64
|
+
"data-value": (_context_value1 = context.value) !== null && _context_value1 !== void 0 ? _context_value1 : void 0,
|
|
65
|
+
"data-max": context.max,
|
|
66
|
+
x,
|
|
67
|
+
width: "200%",
|
|
68
|
+
animateOnly: ["transform"],
|
|
69
|
+
...!import_core.isWeb && context.width === 0 && { opacity: 0 },
|
|
70
|
+
...indicatorProps,
|
|
71
|
+
ref: forwardedRef,
|
|
72
|
+
transition: !import_core.isWeb && !context.width ? null : transition
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
function defaultGetValueLabel(value, max) {
|
|
76
|
+
return `${Math.round(value / max * 100)}%`;
|
|
77
|
+
}
|
|
78
|
+
function getProgressState(value, maxValue) {
|
|
79
|
+
return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
|
|
80
|
+
}
|
|
81
|
+
function isNumber(value) {
|
|
82
|
+
return typeof value === "number";
|
|
83
|
+
}
|
|
84
|
+
function isValidMaxNumber(max) {
|
|
85
|
+
return isNumber(max) && !Number.isNaN(max) && max > 0;
|
|
86
|
+
}
|
|
87
|
+
function isValidValueNumber(value, max) {
|
|
88
|
+
return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;
|
|
89
|
+
}
|
|
90
|
+
var DEFAULT_MAX = 100;
|
|
91
|
+
var ProgressFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
92
|
+
displayName: "Progress",
|
|
93
|
+
overflow: "hidden",
|
|
94
|
+
variants: { size: { Size: function(val) {
|
|
95
|
+
var size = Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * .25);
|
|
96
|
+
return {
|
|
97
|
+
height: size,
|
|
98
|
+
minWidth: (0, import_core.getVariableValue)(size) * 20,
|
|
99
|
+
width: "100%"
|
|
100
|
+
};
|
|
101
|
+
} } }
|
|
102
|
+
});
|
|
103
|
+
var Progress = (0, import_helpers.withStaticProperties)((0, import_core.createStyledHOC)(ProgressFrame, function Progress2(props, forwardedRef) {
|
|
104
|
+
var { __scopeProgress, value: valueProp, max: maxProp, getValueLabel = defaultGetValueLabel, size = true, ...progressProps } = props;
|
|
105
|
+
var max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
|
|
106
|
+
var value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null;
|
|
107
|
+
var valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
|
|
108
|
+
var [width, setWidth] = (0, import_react.useState)(0);
|
|
109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressProvider, {
|
|
110
|
+
scope: __scopeProgress,
|
|
111
|
+
value,
|
|
112
|
+
max,
|
|
113
|
+
width,
|
|
114
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressFrame, {
|
|
115
|
+
"aria-valuemax": max,
|
|
116
|
+
"aria-valuemin": 0,
|
|
117
|
+
"aria-valuenow": isNumber(value) ? value : void 0,
|
|
118
|
+
"aria-valuetext": valueLabel,
|
|
119
|
+
role: "progressbar",
|
|
120
|
+
"data-state": getProgressState(value, max),
|
|
121
|
+
"data-value": value !== null && value !== void 0 ? value : void 0,
|
|
122
|
+
"data-max": max,
|
|
123
|
+
size,
|
|
124
|
+
...progressProps,
|
|
125
|
+
...!import_core.isWeb && { onLayout: function(e) {
|
|
126
|
+
var _progressProps_onLayout;
|
|
127
|
+
var newWidth = Math.round(e.nativeEvent.layout.width);
|
|
128
|
+
if (newWidth !== width) {
|
|
129
|
+
setWidth(newWidth);
|
|
130
|
+
}
|
|
131
|
+
(_progressProps_onLayout = progressProps.onLayout) === null || _progressProps_onLayout === void 0 ? void 0 : _progressProps_onLayout.call(progressProps, e);
|
|
132
|
+
} },
|
|
133
|
+
ref: forwardedRef
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
}), { Indicator: ProgressIndicator });
|