@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.
111 lines (110 loc) • 4.37 kB
JavaScript
;
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TabsTab = void 0;
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _useTabsTab = require("./useTabsTab");
var _useComponentRenderer = require("../../utils/useComponentRenderer");
var _TabsRootContext = require("../root/TabsRootContext");
var _TabsListContext = require("../list/TabsListContext");
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; }
/**
* An individual interactive tab button that toggles the corresponding panel.
* Renders a `<button>` element.
*
* Documentation: [Base UI Tabs](https://base-ui.com/react/components/tabs)
*/
const TabsTab = exports.TabsTab = /*#__PURE__*/React.forwardRef(function Tab(props, forwardedRef) {
const {
className,
disabled = false,
render,
value: valueProp,
id: idProp,
...other
} = props;
const {
value: selectedTabValue,
getTabPanelIdByTabValueOrIndex,
orientation
} = (0, _TabsRootContext.useTabsRootContext)();
const {
activateOnFocus,
highlightedTabIndex,
onTabActivation,
setHighlightedTabIndex
} = (0, _TabsListContext.useTabsListContext)();
const {
getRootProps,
index,
selected
} = (0, _useTabsTab.useTabsTab)({
activateOnFocus,
disabled,
getTabPanelIdByTabValueOrIndex,
highlightedTabIndex,
id: idProp,
onTabActivation,
rootRef: forwardedRef,
setHighlightedTabIndex,
selectedTabValue,
value: valueProp
});
const highlighted = index > -1 && index === highlightedTabIndex;
const state = React.useMemo(() => ({
disabled,
highlighted,
selected,
orientation
}), [disabled, highlighted, selected, orientation]);
const {
renderElement
} = (0, _useComponentRenderer.useComponentRenderer)({
propGetter: getRootProps,
render: render ?? 'button',
className,
state,
extraProps: other
});
return renderElement();
});
process.env.NODE_ENV !== "production" ? TabsTab.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
*/
disabled: _propTypes.default.bool,
/**
* @ignore
*/
id: _propTypes.default.string,
/**
* 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 Tab.
* When not specified, the value is the child position index.
*/
value: _propTypes.default.any
} : void 0;