@tamagui/progress 1.2.9 → 1.2.10

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.
@@ -0,0 +1,156 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { getVariableValue, styled, withStaticProperties } from "@tamagui/core";
3
+ import { createContextScope } from "@tamagui/create-context";
4
+ import { getSize } from "@tamagui/get-size";
5
+ import { ThemeableStack } from "@tamagui/stacks";
6
+ import * as React from "react";
7
+ const PROGRESS_NAME = "Progress";
8
+ const [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);
9
+ const [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
10
+ const INDICATOR_NAME = "ProgressIndicator";
11
+ const ProgressIndicatorFrame = styled(ThemeableStack, {
12
+ name: INDICATOR_NAME,
13
+ height: "100%",
14
+ width: "100%",
15
+ backgrounded: true
16
+ });
17
+ const ProgressIndicator = ProgressIndicatorFrame.extractable(
18
+ React.forwardRef(
19
+ (props, forwardedRef) => {
20
+ const { __scopeProgress, ...indicatorProps } = props;
21
+ const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
22
+ const pct = context.max - (context.value ?? 0);
23
+ const x = -context.width * (pct / 100);
24
+ return /* @__PURE__ */ jsx(
25
+ ProgressIndicatorFrame,
26
+ {
27
+ "data-state": getProgressState(context.value, context.max),
28
+ "data-value": context.value ?? void 0,
29
+ "data-max": context.max,
30
+ x,
31
+ width: context.width,
32
+ ...indicatorProps,
33
+ ref: forwardedRef
34
+ }
35
+ );
36
+ }
37
+ )
38
+ );
39
+ ProgressIndicator.displayName = INDICATOR_NAME;
40
+ function defaultGetValueLabel(value, max) {
41
+ return `${Math.round(value / max * 100)}%`;
42
+ }
43
+ function getProgressState(value, maxValue) {
44
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
45
+ }
46
+ function isNumber(value) {
47
+ return typeof value === "number";
48
+ }
49
+ function isValidMaxNumber(max) {
50
+ return isNumber(max) && !isNaN(max) && max > 0;
51
+ }
52
+ function isValidValueNumber(value, max) {
53
+ return isNumber(value) && !isNaN(value) && value <= max && value >= 0;
54
+ }
55
+ function getInvalidMaxError(propValue, componentName) {
56
+ return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${DEFAULT_MAX}\`.`;
57
+ }
58
+ function getInvalidValueError(propValue, componentName) {
59
+ return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
60
+ - a positive number
61
+ - less than the value passed to \`max\` (or ${DEFAULT_MAX} if no \`max\` prop is set)
62
+ - \`null\` if the progress is indeterminate.
63
+
64
+ Defaulting to \`null\`.`;
65
+ }
66
+ const DEFAULT_MAX = 100;
67
+ const ProgressFrame = styled(ThemeableStack, {
68
+ name: PROGRESS_NAME,
69
+ borderRadius: 1e5,
70
+ overflow: "hidden",
71
+ backgrounded: true,
72
+ variants: {
73
+ size: {
74
+ "...size": (val) => {
75
+ const size = Math.round(getVariableValue(getSize(val)) * 0.25);
76
+ return {
77
+ height: size,
78
+ minWidth: getVariableValue(size) * 20,
79
+ width: "100%"
80
+ };
81
+ }
82
+ }
83
+ }
84
+ });
85
+ const Progress = withStaticProperties(
86
+ ProgressFrame.extractable(
87
+ React.forwardRef(
88
+ (props, forwardedRef) => {
89
+ const {
90
+ __scopeProgress,
91
+ value: valueProp,
92
+ max: maxProp,
93
+ getValueLabel = defaultGetValueLabel,
94
+ size = "$true",
95
+ ...progressProps
96
+ } = props;
97
+ const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
98
+ const value = isValidValueNumber(valueProp, max) ? valueProp : null;
99
+ const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
100
+ const [width, setWidth] = React.useState(0);
101
+ return /* @__PURE__ */ jsx(ProgressProvider, { scope: __scopeProgress, value, max, width, children: /* @__PURE__ */ jsx(
102
+ ProgressFrame,
103
+ {
104
+ size,
105
+ "aria-valuemax": max,
106
+ "aria-valuemin": 0,
107
+ "aria-valuenow": isNumber(value) ? value : void 0,
108
+ "aria-valuetext": valueLabel,
109
+ role: "progressbar",
110
+ "data-state": getProgressState(value, max),
111
+ "data-value": value ?? void 0,
112
+ "data-max": max,
113
+ ...progressProps,
114
+ onLayout: (e) => {
115
+ var _a;
116
+ setWidth(e.nativeEvent.layout.width);
117
+ (_a = progressProps.onLayout) == null ? void 0 : _a.call(progressProps, e);
118
+ },
119
+ ref: forwardedRef
120
+ }
121
+ ) });
122
+ }
123
+ )
124
+ ),
125
+ {
126
+ Indicator: ProgressIndicator
127
+ }
128
+ );
129
+ Progress.displayName = PROGRESS_NAME;
130
+ Progress.propTypes = {
131
+ max(props, propName, componentName) {
132
+ const propValue = props[propName];
133
+ const strVal = String(propValue);
134
+ if (propValue && !isValidMaxNumber(propValue)) {
135
+ return new Error(getInvalidMaxError(strVal, componentName));
136
+ }
137
+ return null;
138
+ },
139
+ value(props, propName, componentName) {
140
+ const valueProp = props[propName];
141
+ const strVal = String(valueProp);
142
+ const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;
143
+ if (valueProp != null && !isValidValueNumber(valueProp, max)) {
144
+ return new Error(getInvalidValueError(strVal, componentName));
145
+ }
146
+ return null;
147
+ }
148
+ };
149
+ export {
150
+ Progress,
151
+ ProgressFrame,
152
+ ProgressIndicator,
153
+ ProgressIndicatorFrame,
154
+ createProgressScope
155
+ };
156
+ //# sourceMappingURL=Progress.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/Progress.tsx"],
4
+ "sourcesContent": ["// forked from Radix UI\n// https://github.com/radix-ui/primitives/blob/main/packages/react/progress/src/Progress.tsx\n\nimport { GetProps, getVariableValue, styled, withStaticProperties } from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { getSize } from '@tamagui/get-size'\nimport { ThemeableStack, YStackProps } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst PROGRESS_NAME = 'Progress'\n\nconst [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME)\ntype ProgressContextValue = { value: number | null; max: number; width: number }\nconst [ProgressProvider, useProgressContext] =\n createProgressContext<ProgressContextValue>(PROGRESS_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * ProgressIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'ProgressIndicator'\n\ntype ProgressIndicatorElement = TamaguiElement\ninterface ProgressIndicatorProps extends YStackProps {}\n\nexport const ProgressIndicatorFrame = styled(ThemeableStack, {\n name: INDICATOR_NAME,\n height: '100%',\n width: '100%',\n backgrounded: true,\n})\n\nconst ProgressIndicator = ProgressIndicatorFrame.extractable(\n React.forwardRef<ProgressIndicatorElement, ProgressIndicatorProps>(\n (props: ScopedProps<ProgressIndicatorProps>, forwardedRef) => {\n const { __scopeProgress, ...indicatorProps } = props\n const context = useProgressContext(INDICATOR_NAME, __scopeProgress)\n const pct = context.max - (context.value ?? 0)\n const x = -context.width * (pct / 100)\n return (\n <ProgressIndicatorFrame\n data-state={getProgressState(context.value, context.max)}\n data-value={context.value ?? undefined}\n data-max={context.max}\n x={x}\n width={context.width}\n {...indicatorProps}\n ref={forwardedRef}\n />\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(\n value: number | undefined | null,\n maxValue: number\n): 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 return isNumber(max) && !isNaN(max) && max > 0\n}\n\nfunction isValidValueNumber(value: any, max: number): value is number {\n return isNumber(value) && !isNaN(value) && value <= max && value >= 0\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\n/* -------------------------------------------------------------------------------------------------\n * Progress\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_MAX = 100\n\ntype ScopedProps<P> = P & { __scopeProgress?: Scope }\n\ntype ProgressState = 'indeterminate' | 'complete' | 'loading'\n\ntype TamaguiElement = HTMLElement | View\n\ntype ProgressElement = TamaguiElement\n\nexport const ProgressFrame = styled(ThemeableStack, {\n name: PROGRESS_NAME,\n borderRadius: 100_000,\n overflow: 'hidden',\n backgrounded: true,\n\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 } as const,\n})\n\ntype ProgressProps = GetProps<typeof ProgressFrame> & {\n value?: number | null | undefined\n max?: number\n getValueLabel?(value: number, max: number): string\n}\n\nconst Progress = withStaticProperties(\n ProgressFrame.extractable(\n React.forwardRef<ProgressElement, ProgressProps>(\n (props: ScopedProps<ProgressProps>, forwardedRef) => {\n const {\n __scopeProgress,\n value: valueProp,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n size = '$true',\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 const [width, setWidth] = React.useState(0)\n\n return (\n <ProgressProvider scope={__scopeProgress} value={value} max={max} width={width}>\n <ProgressFrame\n size={size}\n aria-valuemax={max}\n aria-valuemin={0}\n aria-valuenow={isNumber(value) ? value : undefined}\n aria-valuetext={valueLabel}\n // @ts-ignore\n role=\"progressbar\"\n data-state={getProgressState(value, max)}\n data-value={value ?? undefined}\n data-max={max}\n {...progressProps}\n onLayout={(e) => {\n setWidth(e.nativeEvent.layout.width)\n progressProps.onLayout?.(e)\n }}\n ref={forwardedRef}\n />\n </ProgressProvider>\n )\n }\n )\n ),\n {\n Indicator: ProgressIndicator,\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\nexport { createProgressScope, Progress, ProgressIndicator }\nexport type { ProgressProps, ProgressIndicatorProps }\n"],
5
+ "mappings": "AAyCQ;AAtCR,SAAmB,kBAAkB,QAAQ,4BAA4B;AACzE,SAAgB,0BAA0B;AAC1C,SAAS,eAAe;AACxB,SAAS,sBAAmC;AAC5C,YAAY,WAAW;AAGvB,MAAM,gBAAgB;AAEtB,MAAM,CAAC,uBAAuB,mBAAmB,IAAI,mBAAmB,aAAa;AAErF,MAAM,CAAC,kBAAkB,kBAAkB,IACzC,sBAA4C,aAAa;AAM3D,MAAM,iBAAiB;AAKhB,MAAM,yBAAyB,OAAO,gBAAgB;AAAA,EAC3D,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,cAAc;AAChB,CAAC;AAED,MAAM,oBAAoB,uBAAuB;AAAA,EAC/C,MAAM;AAAA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AA,EACb;AACF;AAEA,SAAS,cAAc;AAEvB,SAAS,YAAY;AAAA,EACnB,IAAI,OAAO,UAAU,eAAe;AAClC,UAAM,YAAY,MAAM,QAAQ;AAChC,UAAM,SAAS,OAAO,SAAS;AAC/B,QAAI,aAAa,CAAC,iBAAiB,SAAS,GAAG;AAC7C,aAAO,IAAI,MAAM,mBAAmB,QAAQ,aAAa,CAAC;AAAA,IAC5D;AACA,WAAO;AAAA,EACT;AAAA,EACA,MAAM,OAAO,UAAU,eAAe;AACpC,UAAM,YAAY,MAAM,QAAQ;AAChC,UAAM,SAAS,OAAO,SAAS;AAC/B,UAAM,MAAM,iBAAiB,MAAM,GAAG,IAAI,MAAM,MAAM;AACtD,QAAI,aAAa,QAAQ,CAAC,mBAAmB,WAAW,GAAG,GAAG;AAC5D,aAAO,IAAI,MAAM,qBAAqB,QAAQ,aAAa,CAAC;AAAA,IAC9D;AACA,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./Progress";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './Progress'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
@@ -0,0 +1,148 @@
1
+ import { getVariableValue, styled, withStaticProperties } from "@tamagui/core";
2
+ import { createContextScope } from "@tamagui/create-context";
3
+ import { getSize } from "@tamagui/get-size";
4
+ import { ThemeableStack } from "@tamagui/stacks";
5
+ import * as React from "react";
6
+ const PROGRESS_NAME = "Progress";
7
+ const [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME);
8
+ const [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME);
9
+ const INDICATOR_NAME = "ProgressIndicator";
10
+ const ProgressIndicatorFrame = styled(ThemeableStack, {
11
+ name: INDICATOR_NAME,
12
+ height: "100%",
13
+ width: "100%",
14
+ backgrounded: true
15
+ });
16
+ const ProgressIndicator = ProgressIndicatorFrame.extractable(
17
+ React.forwardRef(
18
+ (props, forwardedRef) => {
19
+ const { __scopeProgress, ...indicatorProps } = props;
20
+ const context = useProgressContext(INDICATOR_NAME, __scopeProgress);
21
+ const pct = context.max - (context.value ?? 0);
22
+ const x = -context.width * (pct / 100);
23
+ return <ProgressIndicatorFrame
24
+ data-state={getProgressState(context.value, context.max)}
25
+ data-value={context.value ?? void 0}
26
+ data-max={context.max}
27
+ x={x}
28
+ width={context.width}
29
+ {...indicatorProps}
30
+ ref={forwardedRef}
31
+ />;
32
+ }
33
+ )
34
+ );
35
+ ProgressIndicator.displayName = INDICATOR_NAME;
36
+ function defaultGetValueLabel(value, max) {
37
+ return `${Math.round(value / max * 100)}%`;
38
+ }
39
+ function getProgressState(value, maxValue) {
40
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
41
+ }
42
+ function isNumber(value) {
43
+ return typeof value === "number";
44
+ }
45
+ function isValidMaxNumber(max) {
46
+ return isNumber(max) && !isNaN(max) && max > 0;
47
+ }
48
+ function isValidValueNumber(value, max) {
49
+ return isNumber(value) && !isNaN(value) && value <= max && value >= 0;
50
+ }
51
+ function getInvalidMaxError(propValue, componentName) {
52
+ return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${DEFAULT_MAX}\`.`;
53
+ }
54
+ function getInvalidValueError(propValue, componentName) {
55
+ return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
56
+ - a positive number
57
+ - less than the value passed to \`max\` (or ${DEFAULT_MAX} if no \`max\` prop is set)
58
+ - \`null\` if the progress is indeterminate.
59
+
60
+ Defaulting to \`null\`.`;
61
+ }
62
+ const DEFAULT_MAX = 100;
63
+ const ProgressFrame = styled(ThemeableStack, {
64
+ name: PROGRESS_NAME,
65
+ borderRadius: 1e5,
66
+ overflow: "hidden",
67
+ backgrounded: true,
68
+ variants: {
69
+ size: {
70
+ "...size": (val) => {
71
+ const size = Math.round(getVariableValue(getSize(val)) * 0.25);
72
+ return {
73
+ height: size,
74
+ minWidth: getVariableValue(size) * 20,
75
+ width: "100%"
76
+ };
77
+ }
78
+ }
79
+ }
80
+ });
81
+ const Progress = withStaticProperties(
82
+ ProgressFrame.extractable(
83
+ React.forwardRef(
84
+ (props, forwardedRef) => {
85
+ const {
86
+ __scopeProgress,
87
+ value: valueProp,
88
+ max: maxProp,
89
+ getValueLabel = defaultGetValueLabel,
90
+ size = "$true",
91
+ ...progressProps
92
+ } = props;
93
+ const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
94
+ const value = isValidValueNumber(valueProp, max) ? valueProp : null;
95
+ const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
96
+ const [width, setWidth] = React.useState(0);
97
+ return <ProgressProvider scope={__scopeProgress} value={value} max={max} width={width}><ProgressFrame
98
+ size={size}
99
+ aria-valuemax={max}
100
+ aria-valuemin={0}
101
+ aria-valuenow={isNumber(value) ? value : void 0}
102
+ aria-valuetext={valueLabel}
103
+ role="progressbar"
104
+ data-state={getProgressState(value, max)}
105
+ data-value={value ?? void 0}
106
+ data-max={max}
107
+ {...progressProps}
108
+ onLayout={(e) => {
109
+ setWidth(e.nativeEvent.layout.width);
110
+ progressProps.onLayout?.(e);
111
+ }}
112
+ ref={forwardedRef}
113
+ /></ProgressProvider>;
114
+ }
115
+ )
116
+ ),
117
+ {
118
+ Indicator: ProgressIndicator
119
+ }
120
+ );
121
+ Progress.displayName = PROGRESS_NAME;
122
+ Progress.propTypes = {
123
+ max(props, propName, componentName) {
124
+ const propValue = props[propName];
125
+ const strVal = String(propValue);
126
+ if (propValue && !isValidMaxNumber(propValue)) {
127
+ return new Error(getInvalidMaxError(strVal, componentName));
128
+ }
129
+ return null;
130
+ },
131
+ value(props, propName, componentName) {
132
+ const valueProp = props[propName];
133
+ const strVal = String(valueProp);
134
+ const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX;
135
+ if (valueProp != null && !isValidValueNumber(valueProp, max)) {
136
+ return new Error(getInvalidValueError(strVal, componentName));
137
+ }
138
+ return null;
139
+ }
140
+ };
141
+ export {
142
+ Progress,
143
+ ProgressFrame,
144
+ ProgressIndicator,
145
+ ProgressIndicatorFrame,
146
+ createProgressScope
147
+ };
148
+ //# sourceMappingURL=Progress.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/Progress.tsx"],
4
+ "sourcesContent": ["// forked from Radix UI\n// https://github.com/radix-ui/primitives/blob/main/packages/react/progress/src/Progress.tsx\n\nimport { GetProps, getVariableValue, styled, withStaticProperties } from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { getSize } from '@tamagui/get-size'\nimport { ThemeableStack, YStackProps } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst PROGRESS_NAME = 'Progress'\n\nconst [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME)\ntype ProgressContextValue = { value: number | null; max: number; width: number }\nconst [ProgressProvider, useProgressContext] =\n createProgressContext<ProgressContextValue>(PROGRESS_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * ProgressIndicator\n * -----------------------------------------------------------------------------------------------*/\n\nconst INDICATOR_NAME = 'ProgressIndicator'\n\ntype ProgressIndicatorElement = TamaguiElement\ninterface ProgressIndicatorProps extends YStackProps {}\n\nexport const ProgressIndicatorFrame = styled(ThemeableStack, {\n name: INDICATOR_NAME,\n height: '100%',\n width: '100%',\n backgrounded: true,\n})\n\nconst ProgressIndicator = ProgressIndicatorFrame.extractable(\n React.forwardRef<ProgressIndicatorElement, ProgressIndicatorProps>(\n (props: ScopedProps<ProgressIndicatorProps>, forwardedRef) => {\n const { __scopeProgress, ...indicatorProps } = props\n const context = useProgressContext(INDICATOR_NAME, __scopeProgress)\n const pct = context.max - (context.value ?? 0)\n const x = -context.width * (pct / 100)\n return (\n <ProgressIndicatorFrame\n data-state={getProgressState(context.value, context.max)}\n data-value={context.value ?? undefined}\n data-max={context.max}\n x={x}\n width={context.width}\n {...indicatorProps}\n ref={forwardedRef}\n />\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(\n value: number | undefined | null,\n maxValue: number\n): 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 return isNumber(max) && !isNaN(max) && max > 0\n}\n\nfunction isValidValueNumber(value: any, max: number): value is number {\n return isNumber(value) && !isNaN(value) && value <= max && value >= 0\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\n/* -------------------------------------------------------------------------------------------------\n * Progress\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_MAX = 100\n\ntype ScopedProps<P> = P & { __scopeProgress?: Scope }\n\ntype ProgressState = 'indeterminate' | 'complete' | 'loading'\n\ntype TamaguiElement = HTMLElement | View\n\ntype ProgressElement = TamaguiElement\n\nexport const ProgressFrame = styled(ThemeableStack, {\n name: PROGRESS_NAME,\n borderRadius: 100_000,\n overflow: 'hidden',\n backgrounded: true,\n\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 } as const,\n})\n\ntype ProgressProps = GetProps<typeof ProgressFrame> & {\n value?: number | null | undefined\n max?: number\n getValueLabel?(value: number, max: number): string\n}\n\nconst Progress = withStaticProperties(\n ProgressFrame.extractable(\n React.forwardRef<ProgressElement, ProgressProps>(\n (props: ScopedProps<ProgressProps>, forwardedRef) => {\n const {\n __scopeProgress,\n value: valueProp,\n max: maxProp,\n getValueLabel = defaultGetValueLabel,\n size = '$true',\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 const [width, setWidth] = React.useState(0)\n\n return (\n <ProgressProvider scope={__scopeProgress} value={value} max={max} width={width}>\n <ProgressFrame\n size={size}\n aria-valuemax={max}\n aria-valuemin={0}\n aria-valuenow={isNumber(value) ? value : undefined}\n aria-valuetext={valueLabel}\n // @ts-ignore\n role=\"progressbar\"\n data-state={getProgressState(value, max)}\n data-value={value ?? undefined}\n data-max={max}\n {...progressProps}\n onLayout={(e) => {\n setWidth(e.nativeEvent.layout.width)\n progressProps.onLayout?.(e)\n }}\n ref={forwardedRef}\n />\n </ProgressProvider>\n )\n }\n )\n ),\n {\n Indicator: ProgressIndicator,\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\nexport { createProgressScope, Progress, ProgressIndicator }\nexport type { ProgressProps, ProgressIndicatorProps }\n"],
5
+ "mappings": "AAGA,SAAmB,kBAAkB,QAAQ,4BAA4B;AACzE,SAAgB,0BAA0B;AAC1C,SAAS,eAAe;AACxB,SAAS,sBAAmC;AAC5C,YAAY,WAAW;AAGvB,MAAM,gBAAgB;AAEtB,MAAM,CAAC,uBAAuB,mBAAmB,IAAI,mBAAmB,aAAa;AAErF,MAAM,CAAC,kBAAkB,kBAAkB,IACzC,sBAA4C,aAAa;AAM3D,MAAM,iBAAiB;AAKhB,MAAM,yBAAyB,OAAO,gBAAgB;AAAA,EAC3D,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,cAAc;AAChB,CAAC;AAED,MAAM,oBAAoB,uBAAuB;AAAA,EAC/C,MAAM;AAAA,IACJ,CAAC,OAA4C,iBAAiB;AAC5D,YAAM,EAAE,iBAAiB,GAAG,eAAe,IAAI;AAC/C,YAAM,UAAU,mBAAmB,gBAAgB,eAAe;AAClE,YAAM,MAAM,QAAQ,OAAO,QAAQ,SAAS;AAC5C,YAAM,IAAI,CAAC,QAAQ,SAAS,MAAM;AAClC,aACE,CAAC;AAAA,QACC,YAAY,iBAAiB,QAAQ,OAAO,QAAQ,GAAG;AAAA,QACvD,YAAY,QAAQ,SAAS;AAAA,QAC7B,UAAU,QAAQ;AAAA,QAClB,GAAG;AAAA,QACH,OAAO,QAAQ;AAAA,YACX;AAAA,QACJ,KAAK;AAAA,MACP;AAAA,IAEJ;AAAA,EACF;AACF;AAEA,kBAAkB,cAAc;AAIhC,SAAS,qBAAqB,OAAe,KAAa;AACxD,SAAO,GAAG,KAAK,MAAO,QAAQ,MAAO,GAAG;AAC1C;AAEA,SAAS,iBACP,OACA,UACe;AACf,SAAO,SAAS,OAAO,kBAAkB,UAAU,WAAW,aAAa;AAC7E;AAEA,SAAS,SAAS,OAA6B;AAC7C,SAAO,OAAO,UAAU;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": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './Progress'\n"],
5
+ "mappings": "AAAA,cAAc;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/progress",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -23,11 +23,11 @@
23
23
  "clean:build": "tamagui-build clean:build"
24
24
  },
25
25
  "dependencies": {
26
- "@tamagui/compose-refs": "^1.2.9",
27
- "@tamagui/core": "^1.2.9",
28
- "@tamagui/create-context": "^1.2.9",
29
- "@tamagui/get-size": "^1.2.9",
30
- "@tamagui/stacks": "^1.2.9"
26
+ "@tamagui/compose-refs": "^1.2.10",
27
+ "@tamagui/core": "^1.2.10",
28
+ "@tamagui/create-context": "^1.2.10",
29
+ "@tamagui/get-size": "^1.2.10",
30
+ "@tamagui/stacks": "^1.2.10"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": "*",
@@ -35,7 +35,7 @@
35
35
  "react-native": "*"
36
36
  },
37
37
  "devDependencies": {
38
- "@tamagui/build": "^1.2.9",
38
+ "@tamagui/build": "^1.2.10",
39
39
  "react": "^18.2.0",
40
40
  "react-dom": "^18.2.0",
41
41
  "react-native": "*"