UNPKG

3.2 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 var _slots$root;
33 const {
34 children,
35 slotProps = {},
36 slots = {}
37 } = props,
38 other = _objectWithoutPropertiesLoose(props, _excluded);
39 const {
40 hidden,
41 getRootProps
42 } = useTabPanel(props);
43 const ownerState = _extends({}, props, {
44 hidden
45 });
46 const classes = useUtilityClasses(ownerState);
47 const TabPanelRoot = (_slots$root = slots.root) != null ? _slots$root : 'div';
48 const tabPanelRootProps = useSlotProps({
49 elementType: TabPanelRoot,
50 getSlotProps: getRootProps,
51 externalSlotProps: slotProps.root,
52 externalForwardedProps: other,
53 additionalProps: {
54 role: 'tabpanel',
55 ref: forwardedRef
56 },
57 ownerState,
58 className: classes.root
59 });
60 return /*#__PURE__*/_jsx(TabPanelRoot, _extends({}, tabPanelRootProps, {
61 children: !hidden && children
62 }));
63});
64process.env.NODE_ENV !== "production" ? TabPanel.propTypes /* remove-proptypes */ = {
65 // ----------------------------- Warning --------------------------------
66 // | These PropTypes are generated from the TypeScript type definitions |
67 // | To update them edit TypeScript types and run "yarn proptypes" |
68 // ----------------------------------------------------------------------
69 /**
70 * The content of the component.
71 */
72 children: PropTypes.node,
73 /**
74 * The props used for each slot inside the TabPanel.
75 * @default {}
76 */
77 slotProps: PropTypes.shape({
78 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
79 }),
80 /**
81 * The components used for each slot inside the TabPanel.
82 * Either a string to use a HTML element or a component.
83 * @default {}
84 */
85 slots: PropTypes.shape({
86 root: PropTypes.elementType
87 }),
88 /**
89 * The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected.
90 * If not provided, it will fall back to the index of the panel.
91 * It is recommended to explicitly provide it, as it's required for the tab panel to be rendered on the server.
92 */
93 value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
94} : void 0;
95export default TabPanel;
\No newline at end of file