@tamagui/progress 2.7.7 → 3.0.0-0.canary.1791056644527

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