@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.
@@ -1,32 +1,31 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
10
11
  };
11
12
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
19
20
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
22
  var Progress_exports = {};
24
23
  __export(Progress_exports, {
25
- Progress: () => Progress,
26
- ProgressFrame: () => ProgressFrame,
27
- ProgressIndicator: () => ProgressIndicator,
28
- ProgressIndicatorFrame: () => ProgressIndicatorFrame,
29
- createProgressScope: () => createProgressScope
24
+ Progress: () => Progress,
25
+ ProgressFrame: () => ProgressFrame,
26
+ ProgressIndicator: () => ProgressIndicator,
27
+ ProgressIndicatorFrame: () => ProgressIndicatorFrame,
28
+ createProgressScope: () => createProgressScope
30
29
  });
31
30
  module.exports = __toCommonJS(Progress_exports);
32
31
  var import_core = require("@tamagui/core");
@@ -41,138 +40,92 @@ const [createProgressContext, createProgressScope] = (0, import_create_context.c
41
40
  const [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
42
41
  const INDICATOR_NAME = "ProgressIndicator";
43
42
  const ProgressIndicatorFrame = (0, import_core.styled)(import_stacks.YStack, {
44
- name: INDICATOR_NAME,
45
- variants: {
46
- unstyled: {
47
- false: {
48
- height: "100%",
49
- width: "100%",
50
- backgroundColor: "$background"
51
- }
52
- }
53
- },
54
- defaultVariants: {
55
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
56
- }
43
+ displayName: INDICATOR_NAME,
44
+ height: "100%",
45
+ width: "100%"
57
46
  });
58
- const ProgressIndicator = ProgressIndicatorFrame.styleable(function ProgressIndicator2(props, forwardedRef) {
59
- const {
60
- __scopeProgress,
61
- transition,
62
- ...indicatorProps
63
- } = props;
64
- const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
65
- const progressRatio = (context.value ?? 0) / context.max;
66
- let x;
67
- if (import_core.isWeb) {
68
- x = `${-100 + progressRatio * 50}%`;
69
- } else {
70
- const baseWidth = context.width || 0;
71
- x = Math.ceil(-baseWidth * (2 - progressRatio));
72
- }
73
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressIndicatorFrame, {
74
- "data-state": getProgressState(context.value, context.max),
75
- "data-value": context.value ?? void 0,
76
- "data-max": context.max,
77
- x,
78
- width: "200%",
79
- ...(!props.unstyled && {
80
- animateOnly: ["transform"],
81
- // on native, hide until we have width measurement
82
- ...(!import_core.isWeb && context.width === 0 && {
83
- opacity: 0
84
- })
85
- }),
86
- ...indicatorProps,
87
- ref: forwardedRef,
88
- transition: !import_core.isWeb && !context.width ? null : transition
89
- });
47
+ const ProgressIndicator = (0, import_core.createStyledHOC)(ProgressIndicatorFrame, function ProgressIndicator2(props, forwardedRef) {
48
+ const { __scopeProgress, transition, ...indicatorProps } = props;
49
+ const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
50
+ const progressRatio = (context.value ?? 0) / context.max;
51
+ let x;
52
+ if (import_core.isWeb) {
53
+ x = `${-100 + progressRatio * 50}%`;
54
+ } else {
55
+ const baseWidth = context.width || 0;
56
+ x = Math.ceil(-baseWidth * (2 - progressRatio));
57
+ }
58
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressIndicatorFrame, {
59
+ "data-state": getProgressState(context.value, context.max),
60
+ "data-value": context.value ?? void 0,
61
+ "data-max": context.max,
62
+ x,
63
+ width: "200%",
64
+ animateOnly: ["transform"],
65
+ ...!import_core.isWeb && context.width === 0 && { opacity: 0 },
66
+ ...indicatorProps,
67
+ ref: forwardedRef,
68
+ transition: !import_core.isWeb && !context.width ? null : transition
69
+ });
90
70
  });
91
71
  function defaultGetValueLabel(value, max) {
92
- return `${Math.round(value / max * 100)}%`;
72
+ return `${Math.round(value / max * 100)}%`;
93
73
  }
94
74
  function getProgressState(value, maxValue) {
95
- return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
75
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
96
76
  }
97
77
  function isNumber(value) {
98
- return typeof value === "number";
78
+ return typeof value === "number";
99
79
  }
100
80
  function isValidMaxNumber(max) {
101
- return isNumber(max) && !Number.isNaN(max) && max > 0;
81
+ return isNumber(max) && !Number.isNaN(max) && max > 0;
102
82
  }
103
83
  function isValidValueNumber(value, max) {
104
- return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;
84
+ return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;
105
85
  }
106
86
  const DEFAULT_MAX = 100;
107
87
  const ProgressFrame = (0, import_core.styled)(import_stacks.YStack, {
108
- name: "Progress",
109
- variants: {
110
- unstyled: {
111
- false: {
112
- borderRadius: 1e5,
113
- overflow: "hidden",
114
- backgroundColor: "$background"
115
- }
116
- },
117
- size: {
118
- "...size": val => {
119
- const size = Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * 0.25);
120
- return {
121
- height: size,
122
- minWidth: (0, import_core.getVariableValue)(size) * 20,
123
- width: "100%"
124
- };
125
- }
126
- }
127
- },
128
- defaultVariants: {
129
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
130
- }
88
+ displayName: "Progress",
89
+ overflow: "hidden",
90
+ variants: { size: { Size: (val) => {
91
+ const size = Math.round((0, import_core.getVariableValue)((0, import_get_token.getSize)(val)) * .25);
92
+ return {
93
+ height: size,
94
+ minWidth: (0, import_core.getVariableValue)(size) * 20,
95
+ width: "100%"
96
+ };
97
+ } } }
131
98
  });
132
- const Progress = (0, import_helpers.withStaticProperties)(ProgressFrame.styleable(function Progress2(props, forwardedRef) {
133
- const {
134
- // @ts-expect-error
135
- __scopeProgress,
136
- value: valueProp,
137
- max: maxProp,
138
- getValueLabel = defaultGetValueLabel,
139
- size = "$true",
140
- ...progressProps
141
- } = props;
142
- const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
143
- const value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null;
144
- const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
145
- const [width, setWidth] = (0, import_react.useState)(0);
146
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressProvider, {
147
- scope: __scopeProgress,
148
- value,
149
- max,
150
- width,
151
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressFrame, {
152
- "aria-valuemax": max,
153
- "aria-valuemin": 0,
154
- "aria-valuenow": isNumber(value) ? value : void 0,
155
- "aria-valuetext": valueLabel,
156
- role: "progressbar",
157
- "data-state": getProgressState(value, max),
158
- "data-value": value ?? void 0,
159
- "data-max": max,
160
- ...(progressProps.unstyled !== true && {
161
- size
162
- }),
163
- ...progressProps,
164
- ...(!import_core.isWeb && {
165
- onLayout: e => {
166
- const newWidth = Math.round(e.nativeEvent.layout.width);
167
- if (newWidth !== width) {
168
- setWidth(newWidth);
169
- }
170
- progressProps.onLayout?.(e);
171
- }
172
- }),
173
- ref: forwardedRef
174
- })
175
- });
176
- }), {
177
- Indicator: ProgressIndicator
178
- });
99
+ const Progress = (0, import_helpers.withStaticProperties)((0, import_core.createStyledHOC)(ProgressFrame, function Progress2(props, forwardedRef) {
100
+ const { __scopeProgress, value: valueProp, max: maxProp, getValueLabel = defaultGetValueLabel, size = true, ...progressProps } = props;
101
+ const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
102
+ const value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null;
103
+ const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
104
+ const [width, setWidth] = (0, import_react.useState)(0);
105
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressProvider, {
106
+ scope: __scopeProgress,
107
+ value,
108
+ max,
109
+ width,
110
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgressFrame, {
111
+ "aria-valuemax": max,
112
+ "aria-valuemin": 0,
113
+ "aria-valuenow": isNumber(value) ? value : void 0,
114
+ "aria-valuetext": valueLabel,
115
+ role: "progressbar",
116
+ "data-state": getProgressState(value, max),
117
+ "data-value": value ?? void 0,
118
+ "data-max": max,
119
+ size,
120
+ ...progressProps,
121
+ ...!import_core.isWeb && { onLayout: (e) => {
122
+ const newWidth = Math.round(e.nativeEvent.layout.width);
123
+ if (newWidth !== width) {
124
+ setWidth(newWidth);
125
+ }
126
+ progressProps.onLayout?.(e);
127
+ } },
128
+ ref: forwardedRef
129
+ })
130
+ });
131
+ }), { Indicator: ProgressIndicator });
@@ -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 });