@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
43 lines (42 loc) • 1.26 kB
JavaScript
'use client';
import * as React from 'react';
import { mergeReactProps } from '../../utils/mergeReactProps.js';
function getDefaultAriaValueText(value) {
if (value === null) {
return 'indeterminate progress';
}
return `${value}%`;
}
function useProgressRoot(parameters) {
const {
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
'aria-valuetext': ariaValuetext,
getAriaLabel,
getAriaValueText,
max = 100,
min = 0,
value
} = parameters;
let status = 'indeterminate';
if (Number.isFinite(value)) {
status = value === max ? 'complete' : 'progressing';
}
const getRootProps = React.useCallback((externalProps = {}) => mergeReactProps(externalProps, {
'aria-label': getAriaLabel ? getAriaLabel(value) : ariaLabel,
'aria-labelledby': ariaLabelledby,
'aria-valuemax': max,
'aria-valuemin': min,
'aria-valuenow': value ?? undefined,
'aria-valuetext': getAriaValueText ? getAriaValueText(value) : ariaValuetext ?? getDefaultAriaValueText(value),
role: 'progressbar'
}), [ariaLabel, ariaLabelledby, ariaValuetext, getAriaLabel, getAriaValueText, max, min, value]);
return {
getRootProps,
max,
min,
value,
status
};
}
export { useProgressRoot };