@tamagui/progress 1.47.8 → 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/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
- const ProgressIndicator = ProgressIndicatorFrame.extractable(
46
- React.forwardRef<ProgressIndicatorElement, ProgressIndicatorProps>(
47
- (props: ScopedProps<ProgressIndicatorProps>, forwardedRef) => {
48
- const { __scopeProgress, ...indicatorProps } = props
49
- const context = useProgressContext(INDICATOR_NAME, __scopeProgress)
50
- const pct = context.max - (context.value ?? 0)
51
- const x = -context.width * (pct / 100)
52
- return (
53
- <ProgressIndicatorFrame
54
- data-state={getProgressState(context.value, context.max)}
55
- data-value={context.value ?? undefined}
56
- data-max={context.max}
57
- x={x}
58
- width={context.width}
59
- {...indicatorProps}
60
- ref={forwardedRef}
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: PROGRESS_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.extractable(
155
- React.forwardRef<ProgressElement, ProgressProps>(
156
- (props: ScopedProps<ProgressProps>, forwardedRef) => {
157
- const {
158
- __scopeProgress,
159
- value: valueProp,
160
- max: maxProp,
161
- getValueLabel = defaultGetValueLabel,
162
- size = '$true',
163
- ...progressProps
164
- } = props
165
-
166
- const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX
167
- const value = isValidValueNumber(valueProp, max) ? valueProp : null
168
- const valueLabel = isNumber(value) ? getValueLabel(value, max) : undefined
169
- const [width, setWidth] = React.useState(0)
170
-
171
- return (
172
- <ProgressProvider scope={__scopeProgress} value={value} max={max} width={width}>
173
- <ProgressFrame
174
- aria-valuemax={max}
175
- aria-valuemin={0}
176
- aria-valuenow={isNumber(value) ? value : undefined}
177
- aria-valuetext={valueLabel}
178
- // @ts-ignore
179
- role="progressbar"
180
- data-state={getProgressState(value, max)}
181
- data-value={value ?? undefined}
182
- data-max={max}
183
- {...(progressProps.unstyled !== true && {
184
- size,
185
- })}
186
- {...progressProps}
187
- onLayout={(e) => {
188
- setWidth(e.nativeEvent.layout.width)
189
- progressProps.onLayout?.(e)
190
- }}
191
- ref={forwardedRef}
192
- />
193
- </ProgressProvider>
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 }