MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useProgressBar

Function useProgressBar

packages/react-aria/src/progress/useProgressBar.ts:76–117  ·  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 range = maxValue - minValue;
98 let percentage = range === 0 ? 0 : (value - minValue) / range;
99 let formatter = useNumberFormatter(formatOptions);
100
101 if (!isIndeterminate && !valueLabel) {
102 let valueToFormat = formatOptions.style === 'percent' ? percentage : value;
103 valueLabel = formatter.format(valueToFormat);
104 }
105
106 return {
107 progressBarProps: mergeProps(domProps, {
108 ...fieldProps,
109 'aria-valuenow': isIndeterminate ? undefined : value,
110 'aria-valuemin': minValue,
111 'aria-valuemax': maxValue,
112 'aria-valuetext': isIndeterminate ? undefined : (valueLabel as string),
113 role: 'progressbar'
114 }),
115 labelProps
116 };
117}

Callers 6

renderProgressBarHookFunction · 0.90
useMeterFunction · 0.90
ProgressBar.tsxFile · 0.90
ProgressCircle.tsxFile · 0.90
ProgressBar.tsxFile · 0.90
ProgressBarFunction · 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