@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.
125 lines (124 loc) • 5.27 kB
JavaScript
;
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TabsList = void 0;
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _useComponentRenderer = require("../../utils/useComponentRenderer");
var _CompositeRoot = require("../../composite/root/CompositeRoot");
var _styleHooks = require("../root/styleHooks");
var _TabsRootContext = require("../root/TabsRootContext");
var _useTabsList = require("./useTabsList");
var _TabsListContext = require("./TabsListContext");
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 individual tab buttons.
* Renders a `<div>` element.
*
* Documentation: [Base UI Tabs](https://base-ui.com/react/components/tabs)
*/const TabsList = exports.TabsList = /*#__PURE__*/React.forwardRef(function TabsList(props, forwardedRef) {
const {
activateOnFocus = true,
className,
loop = true,
render,
...other
} = props;
const {
direction,
getTabElementBySelectedValue,
onValueChange,
orientation,
value,
setTabMap,
tabActivationDirection
} = (0, _TabsRootContext.useTabsRootContext)();
const [highlightedTabIndex, setHighlightedTabIndex] = React.useState(0);
const tabsListRef = React.useRef(null);
const {
getRootProps,
onTabActivation
} = (0, _useTabsList.useTabsList)({
getTabElementBySelectedValue,
onValueChange,
orientation,
rootRef: forwardedRef,
setTabMap,
tabsListRef,
value
});
const state = React.useMemo(() => ({
orientation,
tabActivationDirection
}), [orientation, tabActivationDirection]);
const {
renderElement
} = (0, _useComponentRenderer.useComponentRenderer)({
propGetter: getRootProps,
render: render ?? 'div',
className,
state,
extraProps: other,
customStyleHookMapping: _styleHooks.tabsStyleHookMapping
});
const tabsListContextValue = React.useMemo(() => ({
activateOnFocus,
highlightedTabIndex,
onTabActivation,
setHighlightedTabIndex,
tabsListRef,
value
}), [activateOnFocus, highlightedTabIndex, onTabActivation, setHighlightedTabIndex, tabsListRef, value]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabsListContext.TabsListContext.Provider, {
value: tabsListContextValue,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CompositeRoot.CompositeRoot, {
highlightedIndex: highlightedTabIndex,
enableHomeAndEndKeys: true,
loop: loop,
direction: direction,
orientation: orientation,
onHighlightedIndexChange: setHighlightedTabIndex,
onMapChange: setTabMap,
render: renderElement()
})
});
});
process.env.NODE_ENV !== "production" ? TabsList.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* Whether to automatically change the active tab on arrow key focus.
* Otherwise, tabs will be activated using Enter or Spacebar key press.
* @default true
*/
activateOnFocus: _propTypes.default.bool,
/**
* @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 loop keyboard focus back to the first item
* when the end of the list is reached while using the arrow keys.
* @default true
*/
loop: _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])
} : void 0;