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.

99 lines (98 loc) 4.37 kB
"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.TabsPanel = void 0; var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _useTabsPanel = require("./useTabsPanel"); var _styleHooks = require("../root/styleHooks"); var _TabsRootContext = require("../root/TabsRootContext"); var _useComponentRenderer = require("../../utils/useComponentRenderer"); 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; } /** * A panel displayed when the corresponding tab is active. * Renders a `<div>` element. * * Documentation: [Base UI Tabs](https://base-ui.com/react/components/tabs) */ const TabsPanel = exports.TabsPanel = /*#__PURE__*/React.forwardRef(function TabPanel(props, forwardedRef) { const { children, className, value: valueProp, render, keepMounted = false, ...other } = props; const { value: selectedValue, getTabIdByPanelValueOrIndex, orientation, tabActivationDirection } = (0, _TabsRootContext.useTabsRootContext)(); const { hidden, getRootProps } = (0, _useTabsPanel.useTabsPanel)({ getTabIdByPanelValueOrIndex, rootRef: forwardedRef, selectedValue, value: valueProp }); const state = React.useMemo(() => ({ hidden, orientation, tabActivationDirection }), [hidden, orientation, tabActivationDirection]); const { renderElement } = (0, _useComponentRenderer.useComponentRenderer)({ propGetter: getRootProps, render: render ?? 'div', className, state, extraProps: { ...other, children: hidden && !keepMounted ? undefined : children }, customStyleHookMapping: _styleHooks.tabsStyleHookMapping }); return renderElement(); }); process.env.NODE_ENV !== "production" ? TabsPanel.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]), /** * Whether to keep the HTML element in the DOM while the panel is hidden. * @default false */ keepMounted: _propTypes.default.bool, /** * 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 value of the TabPanel. It will be shown when the Tab with the corresponding value is selected. * If not provided, it will fall back to the index of the panel. * It is recommended to explicitly provide it, as it's required for the tab panel to be rendered on the server. */ value: _propTypes.default.any } : void 0;