UNPKG

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