UNPKG

3.15 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3const _excluded = ["children", "value", "slotProps", "slots"];
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import { useSlotProps } from '../utils';
7import composeClasses from '../composeClasses';
8import { getTabPanelUtilityClass } from './tabPanelClasses';
9import useTabPanel from '../useTabPanel/useTabPanel';
10import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
11import { jsx as _jsx } from "react/jsx-runtime";
12const useUtilityClasses = ownerState => {
13 const {
14 hidden
15 } = ownerState;
16 const slots = {
17 root: ['root', hidden && 'hidden']
18 };
19 return composeClasses(slots, useClassNamesOverride(getTabPanelUtilityClass));
20};
21/**
22 *
23 * Demos:
24 *
25 * - [Tabs](https://mui.com/base/react-tabs/)
26 *
27 * API:
28 *
29 * - [TabPanel API](https://mui.com/base/react-tabs/components-api/#tab-panel)
30 */
31const TabPanel = /*#__PURE__*/React.forwardRef(function TabPanel(props, forwardedRef) {
32 const {
33 children,
34 slotProps = {},
35 slots = {}
36 } = props,
37 other = _objectWithoutPropertiesLoose(props, _excluded);
38 const {
39 hidden,
40 getRootProps
41 } = useTabPanel(props);
42 const ownerState = _extends({}, props, {
43 hidden
44 });
45 const classes = useUtilityClasses(ownerState);
46 const TabPanelRoot = slots.root ?? 'div';
47 const tabPanelRootProps = useSlotProps({
48 elementType: TabPanelRoot,
49 getSlotProps: getRootProps,
50 externalSlotProps: slotProps.root,
51 externalForwardedProps: other,
52 additionalProps: {
53 role: 'tabpanel',
54 ref: forwardedRef
55 },
56 ownerState,
57 className: classes.root
58 });
59 return /*#__PURE__*/_jsx(TabPanelRoot, _extends({}, tabPanelRootProps, {
60 children: !hidden && children
61 }));
62});
63process.env.NODE_ENV !== "production" ? TabPanel.propTypes /* remove-proptypes */ = {
64 // ----------------------------- Warning --------------------------------
65 // | These PropTypes are generated from the TypeScript type definitions |
66 // | To update them edit TypeScript types and run "yarn proptypes" |
67 // ----------------------------------------------------------------------
68 /**
69 * The content of the component.
70 */
71 children: PropTypes.node,
72 /**
73 * The props used for each slot inside the TabPanel.
74 * @default {}
75 */
76 slotProps: PropTypes.shape({
77 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
78 }),
79 /**
80 * The components used for each slot inside the TabPanel.
81 * Either a string to use a HTML element or a component.
82 * @default {}
83 */
84 slots: PropTypes.shape({
85 root: PropTypes.elementType
86 }),
87 /**
88 * The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected.
89 * If not provided, it will fall back to the index of the panel.
90 * It is recommended to explicitly provide it, as it's required for the tab panel to be rendered on the server.
91 */
92 value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
93} : void 0;
94export default TabPanel;
\No newline at end of file