@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.
105 lines (103 loc) • 3.19 kB
JavaScript
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { useTabsTab } from './useTabsTab.js';
import { useComponentRenderer } from '../../utils/useComponentRenderer.js';
import { useTabsRootContext } from '../root/TabsRootContext.js';
import { useTabsListContext } from '../list/TabsListContext.js';
/**
* 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 = /*#__PURE__*/React.forwardRef(function Tab(props, forwardedRef) {
const {
className,
disabled = false,
render,
value: valueProp,
id: idProp,
...other
} = props;
const {
value: selectedTabValue,
getTabPanelIdByTabValueOrIndex,
orientation
} = useTabsRootContext();
const {
activateOnFocus,
highlightedTabIndex,
onTabActivation,
setHighlightedTabIndex
} = useTabsListContext();
const {
getRootProps,
index,
selected
} = 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
} = useComponentRenderer({
propGetter: getRootProps,
render: render ?? 'button',
className,
state,
extraProps: other
});
return renderElement();
});
export { TabsTab };
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.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* @ignore
*/
disabled: PropTypes.bool,
/**
* @ignore
*/
id: PropTypes.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.oneOfType([PropTypes.element, PropTypes.func]),
/**
* The value of the Tab.
* When not specified, the value is the child position index.
*/
value: PropTypes.any
} : void 0;