@mui/base
Version:
MUI Base is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
100 lines (99 loc) • 3.28 kB
JavaScript
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { useSlotProps } from "../utils/index.js";
import { unstable_composeClasses as composeClasses } from "../composeClasses/index.js";
import { getTabPanelUtilityClass } from "./tabPanelClasses.js";
import { useTabPanel } from "../useTabPanel/useTabPanel.js";
import { useClassNamesOverride } from "../utils/ClassNameConfigurator.js";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
hidden
} = ownerState;
const slots = {
root: ['root', hidden && 'hidden']
};
return composeClasses(slots, useClassNamesOverride(getTabPanelUtilityClass));
};
/**
*
* Demos:
*
* - [Tabs](https://mui.com/base-ui/react-tabs/)
*
* API:
*
* - [TabPanel API](https://mui.com/base-ui/react-tabs/components-api/#tab-panel)
*/
const TabPanel = /*#__PURE__*/React.forwardRef(function TabPanel(props, forwardedRef) {
const {
children,
value,
slotProps = {},
slots = {},
...other
} = props;
const {
hidden,
getRootProps
} = useTabPanel(props);
const ownerState = {
...props,
hidden
};
const classes = useUtilityClasses(ownerState);
const TabPanelRoot = slots.root ?? 'div';
const tabPanelRootProps = useSlotProps({
elementType: TabPanelRoot,
getSlotProps: getRootProps,
externalSlotProps: slotProps.root,
externalForwardedProps: other,
additionalProps: {
role: 'tabpanel',
ref: forwardedRef
},
ownerState,
className: classes.root
});
return /*#__PURE__*/_jsx(TabPanelRoot, {
...tabPanelRootProps,
children: !hidden && children
});
});
process.env.NODE_ENV !== "production" ? TabPanel.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The props used for each slot inside the TabPanel.
* @default {}
*/
slotProps: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside the TabPanel.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
root: PropTypes.elementType
}),
/**
* 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.oneOfType([PropTypes.number, PropTypes.string])
} : void 0;
export { TabPanel };