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.

152 lines (151 loc) 5.2 kB
"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.CompositeRoot = CompositeRoot; var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _CompositeList = require("../list/CompositeList"); var _useCompositeRoot = require("./useCompositeRoot"); var _CompositeRootContext = require("./CompositeRootContext"); var _proptypes = require("../../utils/proptypes"); var _useComponentRenderer = require("../../utils/useComponentRenderer"); 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; } /** * @ignore - internal component. */ function CompositeRoot(props) { const { render, className, highlightedIndex: highlightedIndexProp, onHighlightedIndexChange: onHighlightedIndexChangeProp, orientation, dense, itemSizes, loop, cols, direction, enableHomeAndEndKeys, onMapChange, stopEventPropagation, rootRef, ...otherProps } = props; const { getRootProps, highlightedIndex, onHighlightedIndexChange, elementsRef } = (0, _useCompositeRoot.useCompositeRoot)({ itemSizes, cols, loop, dense, orientation, highlightedIndex: highlightedIndexProp, onHighlightedIndexChange: onHighlightedIndexChangeProp, rootRef, stopEventPropagation, enableHomeAndEndKeys, direction }); const { renderElement } = (0, _useComponentRenderer.useComponentRenderer)({ propGetter: getRootProps, render: render ?? 'div', state: {}, className, extraProps: otherProps }); const contextValue = React.useMemo(() => ({ highlightedIndex, onHighlightedIndexChange }), [highlightedIndex, onHighlightedIndexChange]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CompositeRootContext.CompositeRootContext.Provider, { value: contextValue, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CompositeList.CompositeList, { elementsRef: elementsRef, onMapChange: onMapChange, children: renderElement() }) }); } process.env.NODE_ENV !== "production" ? CompositeRoot.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @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]), /** * @ignore */ cols: _propTypes.default.number, /** * @ignore */ dense: _propTypes.default.bool, /** * @ignore */ direction: _propTypes.default.oneOf(['ltr', 'rtl']), /** * @ignore */ enableHomeAndEndKeys: _propTypes.default.bool, /** * @ignore */ highlightedIndex: _propTypes.default.number, /** * @ignore */ itemSizes: _propTypes.default.arrayOf(_propTypes.default.shape({ height: _propTypes.default.number.isRequired, width: _propTypes.default.number.isRequired })), /** * @ignore */ loop: _propTypes.default.bool, /** * @ignore */ onHighlightedIndexChange: _propTypes.default.func, /** * @ignore */ onMapChange: _propTypes.default.func, /** * @ignore */ orientation: _propTypes.default.oneOf(['both', 'horizontal', 'vertical']), /** * 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]), /** * @ignore */ rootRef: _proptypes.refType, /** * @ignore */ stopEventPropagation: _propTypes.default.bool } : void 0;