@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.
127 lines (126 loc) • 5.37 kB
JavaScript
;
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TabsRoot = void 0;
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _useComponentRenderer = require("../../utils/useComponentRenderer");
var _CompositeList = require("../../composite/list/CompositeList");
var _DirectionContext = require("../../direction-provider/DirectionContext");
var _useTabsRoot = require("./useTabsRoot");
var _TabsRootContext = require("./TabsRootContext");
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 the tabs and the corresponding panels.
* Renders a `<div>` element.
*
* Documentation: [Base UI Tabs](https://base-ui.com/react/components/tabs)
*/
const TabsRoot = exports.TabsRoot = /*#__PURE__*/React.forwardRef(function TabsRoot(props, forwardedRef) {
const {
className,
defaultValue = 0,
onValueChange: onValueChangeProp,
orientation = 'horizontal',
render,
value: valueProp,
...other
} = props;
const direction = (0, _DirectionContext.useDirection)();
const {
getTabElementBySelectedValue,
getTabIdByPanelValueOrIndex,
getTabPanelIdByTabValueOrIndex,
onValueChange,
setTabMap,
setTabPanelMap,
tabActivationDirection,
tabPanelRefs,
value
} = (0, _useTabsRoot.useTabsRoot)({
value: valueProp,
defaultValue,
onValueChange: onValueChangeProp
});
const tabsContextValue = React.useMemo(() => ({
direction,
getTabElementBySelectedValue,
getTabIdByPanelValueOrIndex,
getTabPanelIdByTabValueOrIndex,
onValueChange,
orientation,
setTabMap,
tabActivationDirection,
value
}), [direction, getTabElementBySelectedValue, getTabIdByPanelValueOrIndex, getTabPanelIdByTabValueOrIndex, onValueChange, orientation, setTabMap, tabActivationDirection, value]);
const state = {
orientation,
tabActivationDirection
};
const {
renderElement
} = (0, _useComponentRenderer.useComponentRenderer)({
render: render ?? 'div',
className,
state,
extraProps: other,
ref: forwardedRef,
customStyleHookMapping: _styleHooks.tabsStyleHookMapping
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabsRootContext.TabsRootContext.Provider, {
value: tabsContextValue,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CompositeList.CompositeList, {
elementsRef: tabPanelRefs,
onMapChange: setTabPanelMap,
children: renderElement()
})
});
});
process.env.NODE_ENV !== "production" ? TabsRoot.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]),
/**
* The default value. Use when the component is not controlled.
* When the value is `null`, no Tab will be selected.
* @default 0
*/
defaultValue: _propTypes.default.any,
/**
* Callback invoked when new value is being set.
*/
onValueChange: _propTypes.default.func,
/**
* The component orientation (layout flow direction).
* @default 'horizontal'
*/
orientation: _propTypes.default.oneOf(['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]),
/**
* The value of the currently selected `Tab`. Use when the component is controlled.
* When the value is `null`, no Tab will be selected.
*/
value: _propTypes.default.any
} : void 0;