UNPKG

4.22 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", "defaultValue", "orientation", "direction", "onChange", "selectionFollowsFocus", "slotProps", "slots"];
6import * as React from 'react';
7import PropTypes from 'prop-types';
8import { useSlotProps } from '../utils';
9import { unstable_composeClasses as composeClasses } from '../composeClasses';
10import { getTabsUtilityClass } from './tabsClasses';
11import { useTabs } from '../useTabs';
12import { TabsProvider } from '../useTabs/TabsProvider';
13import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
14import { jsx as _jsx } from "react/jsx-runtime";
15const useUtilityClasses = ownerState => {
16 const {
17 orientation
18 } = ownerState;
19 const slots = {
20 root: ['root', orientation]
21 };
22 return composeClasses(slots, useClassNamesOverride(getTabsUtilityClass));
23};
24
25/**
26 *
27 * Demos:
28 *
29 * - [Tabs](https://mui.com/base-ui/react-tabs/)
30 *
31 * API:
32 *
33 * - [Tabs API](https://mui.com/base-ui/react-tabs/components-api/#tabs)
34 */
35const Tabs = /*#__PURE__*/React.forwardRef(function Tabs(props, forwardedRef) {
36 var _slots$root;
37 const {
38 children,
39 orientation = 'horizontal',
40 direction = 'ltr',
41 slotProps = {},
42 slots = {}
43 } = props,
44 other = _objectWithoutPropertiesLoose(props, _excluded);
45 const ownerState = _extends({}, props, {
46 orientation,
47 direction
48 });
49 const {
50 contextValue
51 } = useTabs(ownerState);
52 const classes = useUtilityClasses(ownerState);
53 const TabsRoot = (_slots$root = slots.root) != null ? _slots$root : 'div';
54 const tabsRootProps = useSlotProps({
55 elementType: TabsRoot,
56 externalSlotProps: slotProps.root,
57 externalForwardedProps: other,
58 additionalProps: {
59 ref: forwardedRef
60 },
61 ownerState,
62 className: classes.root
63 });
64 return /*#__PURE__*/_jsx(TabsRoot, _extends({}, tabsRootProps, {
65 children: /*#__PURE__*/_jsx(TabsProvider, {
66 value: contextValue,
67 children: children
68 })
69 }));
70});
71process.env.NODE_ENV !== "production" ? Tabs.propTypes /* remove-proptypes */ = {
72 // ┌────────────────────────────── Warning ──────────────────────────────┐
73 // │ These PropTypes are generated from the TypeScript type definitions. │
74 // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
75 // └─────────────────────────────────────────────────────────────────────┘
76 /**
77 * The content of the component.
78 */
79 children: PropTypes.node,
80 /**
81 * @ignore
82 */
83 className: PropTypes.string,
84 /**
85 * The default value. Use when the component is not controlled.
86 */
87 defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
88 /**
89 * The direction of the text.
90 * @default 'ltr'
91 */
92 direction: PropTypes.oneOf(['ltr', 'rtl']),
93 /**
94 * Callback invoked when new value is being set.
95 */
96 onChange: PropTypes.func,
97 /**
98 * The component orientation (layout flow direction).
99 * @default 'horizontal'
100 */
101 orientation: PropTypes.oneOf(['horizontal', 'vertical']),
102 /**
103 * If `true` the selected tab changes on focus. Otherwise it only
104 * changes on activation.
105 */
106 selectionFollowsFocus: PropTypes.bool,
107 /**
108 * The props used for each slot inside the Tabs.
109 * @default {}
110 */
111 slotProps: PropTypes.shape({
112 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
113 }),
114 /**
115 * The components used for each slot inside the Tabs.
116 * Either a string to use a HTML element or a component.
117 * @default {}
118 */
119 slots: PropTypes.shape({
120 root: PropTypes.elementType
121 }),
122 /**
123 * The value of the currently selected `Tab`.
124 * If you don't want any selected `Tab`, you can set this prop to `null`.
125 */
126 value: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
127} : void 0;
128export { Tabs };
\No newline at end of file