You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.4 KiB
JavaScript
100 lines
3.4 KiB
JavaScript
'use client';
|
|
|
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
const _excluded = ["children", "value", "slotProps", "slots"];
|
|
import * as React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useSlotProps } from '../utils';
|
|
import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
|
import { getTabPanelUtilityClass } from './tabPanelClasses';
|
|
import { useTabPanel } from '../useTabPanel/useTabPanel';
|
|
import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
|
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,
|
|
slotProps = {},
|
|
slots = {}
|
|
} = props,
|
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
const {
|
|
hidden,
|
|
getRootProps
|
|
} = useTabPanel(props);
|
|
const ownerState = _extends({}, 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, _extends({}, 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 }; |