UNPKG

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