@tamagui/progress 1.47.7 → 1.47.9
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.js +61 -83
- package/dist/cjs/Progress.js.map +2 -2
- package/dist/esm/Progress.js +61 -83
- package/dist/esm/Progress.js.map +2 -2
- package/dist/jsx/Progress.js +56 -78
- package/dist/jsx/Progress.js.map +2 -2
- package/package.json +7 -7
- package/src/Progress.tsx +73 -95
- package/types/Progress.d.ts +400 -9
- package/types/Progress.d.ts.map +1 -1
package/src/Progress.tsx
CHANGED
|
@@ -21,9 +21,6 @@ const [ProgressProvider, useProgressContext] =
|
|
|
21
21
|
|
|
22
22
|
const INDICATOR_NAME = 'ProgressIndicator'
|
|
23
23
|
|
|
24
|
-
type ProgressIndicatorElement = TamaguiElement
|
|
25
|
-
interface ProgressIndicatorProps extends YStackProps {}
|
|
26
|
-
|
|
27
24
|
export const ProgressIndicatorFrame = styled(ThemeableStack, {
|
|
28
25
|
name: INDICATOR_NAME,
|
|
29
26
|
|
|
@@ -42,29 +39,33 @@ export const ProgressIndicatorFrame = styled(ThemeableStack, {
|
|
|
42
39
|
},
|
|
43
40
|
})
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
42
|
+
type ProgressIndicatorProps = GetProps<typeof ProgressIndicatorFrame>
|
|
43
|
+
|
|
44
|
+
const ProgressIndicator = ProgressIndicatorFrame.styleable(function ProgressIndicator(
|
|
45
|
+
props: ScopedProps<ProgressIndicatorProps>,
|
|
46
|
+
forwardedRef
|
|
47
|
+
) {
|
|
48
|
+
const { __scopeProgress, ...indicatorProps } = props
|
|
49
|
+
const context = useProgressContext(INDICATOR_NAME, __scopeProgress)
|
|
50
|
+
const pct = context.max - (context.value ?? 0)
|
|
51
|
+
// default somewhat far off
|
|
52
|
+
const x = -(context.width === 0 ? 300 : context.width) * (pct / 100)
|
|
53
|
+
return (
|
|
54
|
+
<ProgressIndicatorFrame
|
|
55
|
+
data-state={getProgressState(context.value, context.max)}
|
|
56
|
+
data-value={context.value ?? undefined}
|
|
57
|
+
data-max={context.max}
|
|
58
|
+
x={x}
|
|
59
|
+
width={context.width}
|
|
60
|
+
{...(!props.unstyled && {
|
|
61
|
+
animateOnly: ['transform'],
|
|
62
|
+
opacity: context.width === 0 ? 0 : 1,
|
|
63
|
+
})}
|
|
64
|
+
{...indicatorProps}
|
|
65
|
+
ref={forwardedRef}
|
|
66
|
+
/>
|
|
64
67
|
)
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
ProgressIndicator.displayName = INDICATOR_NAME
|
|
68
|
+
})
|
|
68
69
|
|
|
69
70
|
/* ---------------------------------------------------------------------------------------------- */
|
|
70
71
|
|
|
@@ -115,12 +116,8 @@ type ScopedProps<P> = P & { __scopeProgress?: Scope }
|
|
|
115
116
|
|
|
116
117
|
type ProgressState = 'indeterminate' | 'complete' | 'loading'
|
|
117
118
|
|
|
118
|
-
type TamaguiElement = HTMLElement | View
|
|
119
|
-
|
|
120
|
-
type ProgressElement = TamaguiElement
|
|
121
|
-
|
|
122
119
|
export const ProgressFrame = styled(ThemeableStack, {
|
|
123
|
-
name:
|
|
120
|
+
name: 'Progress',
|
|
124
121
|
|
|
125
122
|
variants: {
|
|
126
123
|
unstyled: {
|
|
@@ -142,6 +139,10 @@ export const ProgressFrame = styled(ThemeableStack, {
|
|
|
142
139
|
},
|
|
143
140
|
},
|
|
144
141
|
} as const,
|
|
142
|
+
|
|
143
|
+
defaultVariants: {
|
|
144
|
+
unstyled: false,
|
|
145
|
+
},
|
|
145
146
|
})
|
|
146
147
|
|
|
147
148
|
type ProgressProps = GetProps<typeof ProgressFrame> & {
|
|
@@ -151,76 +152,53 @@ type ProgressProps = GetProps<typeof ProgressFrame> & {
|
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
const Progress = withStaticProperties(
|
|
154
|
-
ProgressFrame.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
155
|
+
ProgressFrame.styleable<ProgressProps>(function Progress(
|
|
156
|
+
props: ScopedProps<ProgressProps>,
|
|
157
|
+
forwardedRef
|
|
158
|
+
) {
|
|
159
|
+
const {
|
|
160
|
+
__scopeProgress,
|
|
161
|
+
value: valueProp,
|
|
162
|
+
max: maxProp,
|
|
163
|
+
getValueLabel = defaultGetValueLabel,
|
|
164
|
+
size = '$true',
|
|
165
|
+
...progressProps
|
|
166
|
+
} = props
|
|
167
|
+
|
|
168
|
+
const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX
|
|
169
|
+
const value = isValidValueNumber(valueProp, max) ? valueProp : null
|
|
170
|
+
const valueLabel = isNumber(value) ? getValueLabel(value, max) : undefined
|
|
171
|
+
const [width, setWidth] = React.useState(0)
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<ProgressProvider scope={__scopeProgress} value={value} max={max} width={width}>
|
|
175
|
+
<ProgressFrame
|
|
176
|
+
aria-valuemax={max}
|
|
177
|
+
aria-valuemin={0}
|
|
178
|
+
aria-valuenow={isNumber(value) ? value : undefined}
|
|
179
|
+
aria-valuetext={valueLabel}
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
role="progressbar"
|
|
182
|
+
data-state={getProgressState(value, max)}
|
|
183
|
+
data-value={value ?? undefined}
|
|
184
|
+
data-max={max}
|
|
185
|
+
{...(progressProps.unstyled !== true && {
|
|
186
|
+
size,
|
|
187
|
+
})}
|
|
188
|
+
{...progressProps}
|
|
189
|
+
onLayout={(e) => {
|
|
190
|
+
setWidth(e.nativeEvent.layout.width)
|
|
191
|
+
progressProps.onLayout?.(e)
|
|
192
|
+
}}
|
|
193
|
+
ref={forwardedRef}
|
|
194
|
+
/>
|
|
195
|
+
</ProgressProvider>
|
|
196
196
|
)
|
|
197
|
-
),
|
|
197
|
+
}),
|
|
198
198
|
{
|
|
199
199
|
Indicator: ProgressIndicator,
|
|
200
200
|
}
|
|
201
201
|
)
|
|
202
202
|
|
|
203
|
-
Progress.displayName = PROGRESS_NAME
|
|
204
|
-
|
|
205
|
-
Progress.propTypes = {
|
|
206
|
-
max(props, propName, componentName) {
|
|
207
|
-
const propValue = props[propName]
|
|
208
|
-
const strVal = String(propValue)
|
|
209
|
-
if (propValue && !isValidMaxNumber(propValue)) {
|
|
210
|
-
return new Error(getInvalidMaxError(strVal, componentName))
|
|
211
|
-
}
|
|
212
|
-
return null
|
|
213
|
-
},
|
|
214
|
-
value(props, propName, componentName) {
|
|
215
|
-
const valueProp = props[propName]
|
|
216
|
-
const strVal = String(valueProp)
|
|
217
|
-
const max = isValidMaxNumber(props.max) ? props.max : DEFAULT_MAX
|
|
218
|
-
if (valueProp != null && !isValidValueNumber(valueProp, max)) {
|
|
219
|
-
return new Error(getInvalidValueError(strVal, componentName))
|
|
220
|
-
}
|
|
221
|
-
return null
|
|
222
|
-
},
|
|
223
|
-
}
|
|
224
|
-
|
|
225
203
|
export { createProgressScope, Progress, ProgressIndicator }
|
|
226
204
|
export type { ProgressProps, ProgressIndicatorProps }
|