UNPKG

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