@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.
129 lines (128 loc) • 4.26 kB
JavaScript
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { useComponentRenderer } from '../../utils/useComponentRenderer.js';
import { useProgressRoot } from './useProgressRoot.js';
import { ProgressRootContext } from './ProgressRootContext.js';
import { progressStyleHookMapping } from './styleHooks.js';
import { jsx as _jsx } from "react/jsx-runtime";
/**
* Groups all parts of the progress bar and provides the task completion status to screen readers.
* Renders a `<div>` element.
*
* Documentation: [Base UI Progress](https://base-ui.com/react/components/progress)
*/
const ProgressRoot = /*#__PURE__*/React.forwardRef(function ProgressRoot(props, forwardedRef) {
const {
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
'aria-valuetext': ariaValuetext,
getAriaLabel,
getAriaValueText,
max = 100,
min = 0,
value,
render,
className,
...otherProps
} = props;
const {
getRootProps,
...progress
} = useProgressRoot({
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
'aria-valuetext': ariaValuetext,
getAriaLabel,
getAriaValueText,
max,
min,
value
});
const state = React.useMemo(() => ({
max,
min,
status: progress.status
}), [max, min, progress.status]);
const contextValue = React.useMemo(() => ({
...progress,
state
}), [progress, state]);
const {
renderElement
} = useComponentRenderer({
propGetter: getRootProps,
render: render ?? 'div',
state,
className,
ref: forwardedRef,
extraProps: otherProps,
customStyleHookMapping: progressStyleHookMapping
});
return /*#__PURE__*/_jsx(ProgressRootContext.Provider, {
value: contextValue,
children: renderElement()
});
});
process.env.NODE_ENV !== "production" ? ProgressRoot.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* The label for the Indicator component.
*/
'aria-label': PropTypes.string,
/**
* An id or space-separated list of ids of elements that label the Indicator component.
*/
'aria-labelledby': PropTypes.string,
/**
* A string value that provides a human-readable text alternative for the current value of the progress indicator.
*/
'aria-valuetext': PropTypes.string,
/**
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* Accepts a function which returns a string value that provides an accessible name for the Indicator component
* @param {number | null} value The component's value
* @returns {string}
*/
getAriaLabel: PropTypes.func,
/**
* Accepts a function which returns a string value that provides a human-readable text alternative for the current value of the progress indicator.
* @param {number | null} value The component's value to format
* @returns {string}
*/
getAriaValueText: PropTypes.func,
/**
* The maximum value
* @default 100
*/
max: PropTypes.number,
/**
* The minimum value
* @default 0
*/
min: PropTypes.number,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* The current value. The component is indeterminate when value is `null`.
* @default null
*/
value: PropTypes.number
} : void 0;
export { ProgressRoot };