MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useProgressBar

Function useProgressBar

packages/react-aria/src/progress/useProgressBar.ts:76–116  ·  view source on GitHub ↗
(props: AriaProgressBarProps)

Source from the content-addressed store, hash-verified

74 * over time.
75 */
76export function useProgressBar(props: AriaProgressBarProps): ProgressBarAria {
77 let {
78 value = 0,
79 minValue = 0,
80 maxValue = 100,
81 valueLabel,
82 isIndeterminate,
83 formatOptions = {
84 style: 'percent'
85 }
86 } = props;
87
88 let domProps = filterDOMProps(props, {labelable: true});
89 let {labelProps, fieldProps} = useLabel({
90 ...props,
91 // Progress bar is not an HTML input element so it
92 // shouldn't be labeled by a <label> element.
93 labelElementType: 'span'
94 });
95
96 value = clamp(value, minValue, maxValue);
97 let percentage = (value - minValue) / (maxValue - minValue);
98 let formatter = useNumberFormatter(formatOptions);
99
100 if (!isIndeterminate && !valueLabel) {
101 let valueToFormat = formatOptions.style === 'percent' ? percentage : value;
102 valueLabel = formatter.format(valueToFormat);
103 }
104
105 return {
106 progressBarProps: mergeProps(domProps, {
107 ...fieldProps,
108 'aria-valuenow': isIndeterminate ? undefined : value,
109 'aria-valuemin': minValue,
110 'aria-valuemax': maxValue,
111 'aria-valuetext': isIndeterminate ? undefined : (valueLabel as string),
112 role: 'progressbar'
113 }),
114 labelProps
115 };
116}

Callers 5

renderProgressBarHookFunction · 0.90
useMeterFunction · 0.90
ProgressBar.tsxFile · 0.90
ProgressCircle.tsxFile · 0.90
ProgressBar.tsxFile · 0.90

Calls 6

filterDOMPropsFunction · 0.90
useLabelFunction · 0.90
clampFunction · 0.90
useNumberFormatterFunction · 0.90
mergePropsFunction · 0.90
formatMethod · 0.45

Tested by 1

renderProgressBarHookFunction · 0.72