UNPKG

@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.

136 lines (135 loc) 5.49 kB
"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgressRoot = void 0; var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _useComponentRenderer = require("../../utils/useComponentRenderer"); var _useProgressRoot = require("./useProgressRoot"); var _ProgressRootContext = require("./ProgressRootContext"); var _styleHooks = require("./styleHooks"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * 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 = exports.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 } = (0, _useProgressRoot.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 } = (0, _useComponentRenderer.useComponentRenderer)({ propGetter: getRootProps, render: render ?? 'div', state, className, ref: forwardedRef, extraProps: otherProps, customStyleHookMapping: _styleHooks.progressStyleHookMapping }); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ProgressRootContext.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.default.string, /** * An id or space-separated list of ids of elements that label the Indicator component. */ 'aria-labelledby': _propTypes.default.string, /** * A string value that provides a human-readable text alternative for the current value of the progress indicator. */ 'aria-valuetext': _propTypes.default.string, /** * @ignore */ children: _propTypes.default.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.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.default.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.default.func, /** * The maximum value * @default 100 */ max: _propTypes.default.number, /** * The minimum value * @default 0 */ min: _propTypes.default.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.default.oneOfType([_propTypes.default.element, _propTypes.default.func]), /** * The current value. The component is indeterminate when value is `null`. * @default null */ value: _propTypes.default.number } : void 0;